private JaggedArrayAccessor(Array array, JaggedArrayInfo arrayInfo, bool asRanges, bool zeroBased, int[] transpose, bool readOnly) : base(array != null ? indices => GetValue(array, arrayInfo, asRanges, zeroBased, transpose, indices) : (FuncParams <int, T>)null, array != null && !array.IsReadOnly ? (value, indices) => SetValue(array, arrayInfo, value, asRanges, zeroBased, transpose, indices) : (ActionParams <int, T>)null) { if (array == null) { throw new ArgumentNullException("array"); } if (!typeof(T).IsAssignableFrom(array.GetJaggedArrayElementType())) { throw new ArgumentException("Invalid array element type"); } // if (transpose != null) { bool[] occurs = new bool[transpose.Length]; for (int i = 0; i < transpose.Length; i++) { if (transpose[i] < 0 && transpose[i] >= transpose.Length) { throw new ArgumentRegularArrayElementException("transpose", "Transpose index is out of range", i); } else if (occurs[transpose[i]]) { throw new ArgumentRegularArrayElementException("transpose", "Duplicate transpose index", i); } else { occurs[transpose[i]] = true; } } } }
private JaggedArrayRankedAccessor(Array array, JaggedArrayInfo arrayInfo, bool asRanges, bool zeroBased, bool readOnly) : base(array != null ? indices => GetValue(array, arrayInfo, asRanges, zeroBased, indices) : (FuncParams <int[], T>)null, array != null && !array.IsReadOnly ? (value, indices) => SetValue(array, arrayInfo, value, asRanges, zeroBased, indices) : (ActionParams <int[], T>)null) { if (array == null) { throw new ArgumentNullException("array"); } if (!typeof(T).IsAssignableFrom(array.GetJaggedArrayElementType())) { throw new ArgumentException("Invalid array element type"); } }
static void Main(string[] args) { int[][] intarray = new int[][] { new int[] { 1, 2, 3, 4 }, new int[] { 4, 3, 2, 1 }, new int[] { 3, 2, 6, 1 } }; JaggedArrayInfo info = new JaggedArrayInfo(intarray); Console.WriteLine(info.Lowers); //вывести кол-во строк по убыванию Console.WriteLine(info.Uppers); //вывести кол-во строк по возрастанию Console.WriteLine(info.Ravnie); //вывести кол-во строк равных Console.WriteLine(info.Lost); //вывести кол-во строк не отсортированных Console.Read(); }
public static void GetDimIndices(this ArrayIndex arrayIndex, int[][] dimIndices) { if (arrayIndex == null) { throw new NullReferenceException("arrayIndex"); } JaggedArrayInfo arrayInfo = arrayIndex.ArrayInfo as JaggedArrayInfo; if (arrayInfo == null) { throw new InvalidOperationException("Indexearray is nojagged"); } // if (dimIndices == null) { throw new ArgumentNullException("dimIndices"); } else if (dimIndices.Length != arrayInfo.Depths) { throw new ArgumentException(ArrayResources.Default.Strings[ArrayMessage.InvalidArrayLength], "dimIndices"); } else { for (int i = 0; i < arrayInfo.Depths; i++) { if (dimIndices[i] == null) { throw new ArgumentRegularArrayElementException("dimIndices", "Value is null", i); } else if (dimIndices[i].Length != arrayInfo.GetRank(i)) { throw new ArgumentRegularArrayElementException("dimIndices", ArrayResources.Default.Strings[ArrayMessage.InvalidArrayLength], i); } } } // for (int i = 0, j = 0; i < arrayInfo.Depths; j += arrayInfo.GetRank(i), i++) { for (int k = 0; k < arrayInfo.GetRank(i); k++) { dimIndices[i][k] = arrayIndex.GetDimIndex(j + k); } } }
private static void SetValue(Array array, JaggedArrayInfo arrayInfo, T value, bool asRanges, bool zeroBased, int[][] indices) { arrayInfo.SetValue <T>(array, value, asRanges, zeroBased, indices); }
private static T GetValue(Array array, JaggedArrayInfo arrayInfo, bool asRanges, bool zeroBased, int[][] indices) { return(arrayInfo.GetValue <T>(array, asRanges, zeroBased, indices)); }
private static void SetValue(Array array, JaggedArrayInfo arrayInfo, T value, bool asRanges, bool zeroBased, int[] transpose, int[] indices) { arrayInfo.SetValue <T>(array, value, asRanges, zeroBased, transpose != null ? Transpose(indices, transpose) : indices); }
private static T GetValue(Array array, JaggedArrayInfo arrayInfo, bool asRanges, bool zeroBased, int[] transpose, int[] indices) { return(arrayInfo.GetValue <T>(array, asRanges, zeroBased, transpose != null ? Transpose(indices, transpose) : indices)); }