Survivalcraft API 1.8.2.3 v1.8.2.3
Survivalcraft 2.4
载入中...
搜索中...
未找到
CollectionUtils.cs
浏览该文件的文档.
1namespace Game {
2 public static class CollectionUtils {
3 public static T ElementAt<T, E>(E enumerator, int index) where E : IEnumerator<T> {
4 int num = 0;
5 do {
6 if (!enumerator.MoveNext()) {
7 throw new IndexOutOfRangeException("ElementAt() index out of range.");
8 }
9 num++;
10 }
11 while (num <= index);
12 return enumerator.Current;
13 }
14
15 public static void RandomShuffle<T>(this IList<T> list, Func<int, int> random) {
16 for (int num = list.Count - 1; num > 0; num--) {
17 int index = random(num + 1);
18 T value = list[index];
19 list[index] = list[num];
20 list[num] = value;
21 }
22 }
23
24 public static int FirstIndex<T>(this IEnumerable<T> collection, T value) {
25 int num = 0;
26 foreach (T item in collection) {
27 if (Equals(item, value)) {
28 return num;
29 }
30 num++;
31 }
32 return -1;
33 }
34
35 public static int FirstIndex<T>(this IEnumerable<T> collection, Func<T, bool> predicate) {
36 int num = 0;
37 foreach (T item in collection) {
38 if (predicate(item)) {
39 return num;
40 }
41 num++;
42 }
43 return -1;
44 }
45
46 public static T SelectNth<T>(this IList<T> list, int n, IComparer<T> comparer) {
47 if (list == null
48 || list.Count <= n) {
49 throw new ArgumentException();
50 }
51 int num = 0;
52 int num2 = list.Count - 1;
53 while (num < num2) {
54 int num3 = num;
55 int num4 = num2;
56 T y = list[(num3 + num4) / 2];
57 while (num3 < num4) {
58 if (comparer.Compare(list[num3], y) >= 0) {
59 T value = list[num4];
60 list[num4] = list[num3];
61 list[num3] = value;
62 num4--;
63 }
64 else {
65 num3++;
66 }
67 }
68 if (comparer.Compare(list[num3], y) > 0) {
69 num3--;
70 }
71 if (n <= num3) {
72 num2 = num3;
73 }
74 else {
75 num = num3 + 1;
76 }
77 }
78 return list[n];
79 }
80 }
81}
static void RandomShuffle< T >(this IList< T > list, Func< int, int > random)
static T ElementAt< T, E >(E enumerator, int index)
static int FirstIndex< T >(this IEnumerable< T > collection, T value)
static T SelectNth< T >(this IList< T > list, int n, IComparer< T > comparer)