Created
March 25, 2024 06:46
-
-
Save baba-s/a8027ca05a831cbdee43c45e8247c4ea to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections.Generic; | |
namespace Kogane | |
{ | |
public static class IReadOnlyListExtensionMethods | |
{ | |
public static T[] ShiftRight<T> | |
( | |
this IReadOnlyList<T> self, | |
int shiftCount | |
) | |
{ | |
var count = self.Count; | |
var result = new T[ count ]; | |
for ( var i = 0; i < count; i++ ) | |
{ | |
result[ i ] = self[ ( i - shiftCount + count ) % count ]; | |
} | |
return result; | |
} | |
public static T[] ShiftLeft<T> | |
( | |
this IReadOnlyList<T> self, | |
int shiftCount | |
) | |
{ | |
var count = self.Count; | |
var result = new T[ count ]; | |
for ( var i = 0; i < count; i++ ) | |
{ | |
result[ i ] = self[ ( i + shiftCount ) % count ]; | |
} | |
return result; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment