summaryrefslogtreecommitdiff
path: root/Thronefall_1_57/Decompile/Ara/ElasticArray.cs
diff options
context:
space:
mode:
authorchai <215380520@qq.com>2024-05-19 16:05:58 +0800
committerchai <215380520@qq.com>2024-05-19 16:05:58 +0800
commit8e13e7e2874adc8982e16d1d2ed2e28d7480b45f (patch)
tree63ef85c460288891f5a593d69afeca16cba050b3 /Thronefall_1_57/Decompile/Ara/ElasticArray.cs
parentc5f145786f4c6d2fe4bea831dfc16e52228920a5 (diff)
+1.57
Diffstat (limited to 'Thronefall_1_57/Decompile/Ara/ElasticArray.cs')
-rw-r--r--Thronefall_1_57/Decompile/Ara/ElasticArray.cs160
1 files changed, 160 insertions, 0 deletions
diff --git a/Thronefall_1_57/Decompile/Ara/ElasticArray.cs b/Thronefall_1_57/Decompile/Ara/ElasticArray.cs
new file mode 100644
index 0000000..038435c
--- /dev/null
+++ b/Thronefall_1_57/Decompile/Ara/ElasticArray.cs
@@ -0,0 +1,160 @@
+using System;
+using System.Collections;
+using System.Collections.Generic;
+
+namespace Ara;
+
+public class ElasticArray<T> : IList<T>, ICollection<T>, IEnumerable<T>, IEnumerable
+{
+ private T[] data = new T[16];
+
+ private int count;
+
+ public int Count => count;
+
+ public bool IsReadOnly => false;
+
+ public T this[int index]
+ {
+ get
+ {
+ return data[index];
+ }
+ set
+ {
+ data[index] = value;
+ }
+ }
+
+ public T[] Data => data;
+
+ public IEnumerator<T> GetEnumerator()
+ {
+ int i = 0;
+ while (i < count)
+ {
+ yield return data[i];
+ int num = i + 1;
+ i = num;
+ }
+ }
+
+ IEnumerator IEnumerable.GetEnumerator()
+ {
+ return GetEnumerator();
+ }
+
+ public void Add(T item)
+ {
+ EnsureCapacity(count + 1);
+ data[count++] = item;
+ }
+
+ public void Clear()
+ {
+ count = 0;
+ }
+
+ public bool Contains(T item)
+ {
+ for (int i = 0; i < count; i++)
+ {
+ if (data[i].Equals(item))
+ {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public void CopyTo(T[] array, int arrayIndex)
+ {
+ if (array == null)
+ {
+ throw new ArgumentNullException();
+ }
+ if (array.Length - arrayIndex < count)
+ {
+ throw new ArgumentException();
+ }
+ Array.Copy(data, 0, array, arrayIndex, count);
+ }
+
+ public bool Remove(T item)
+ {
+ bool flag = false;
+ for (int i = 0; i < count; i++)
+ {
+ if (!flag && data[i].Equals(item))
+ {
+ flag = true;
+ }
+ if (flag && i < count - 1)
+ {
+ data[i] = data[i + 1];
+ }
+ }
+ if (flag)
+ {
+ count--;
+ }
+ return flag;
+ }
+
+ public int IndexOf(T item)
+ {
+ return Array.IndexOf(data, item);
+ }
+
+ public void Insert(int index, T item)
+ {
+ if (index < 0 || index > count)
+ {
+ throw new ArgumentOutOfRangeException();
+ }
+ EnsureCapacity(++count);
+ for (int i = count - 1; i > index; i++)
+ {
+ data[i] = data[i - 1];
+ }
+ data[index] = item;
+ }
+
+ public void RemoveAt(int index)
+ {
+ for (int i = index; i < count; i++)
+ {
+ if (i < count - 1)
+ {
+ data[i] = data[i + 1];
+ }
+ }
+ count--;
+ }
+
+ public void SetCount(int count)
+ {
+ EnsureCapacity(count);
+ this.count = count;
+ }
+
+ public void EnsureCapacity(int capacity)
+ {
+ if (capacity >= data.Length)
+ {
+ Array.Resize(ref data, capacity * 2);
+ }
+ }
+
+ public void Reverse()
+ {
+ int num = 0;
+ int num2 = count - 1;
+ while (num < num2)
+ {
+ T val = data[num];
+ data[num++] = data[num2];
+ data[num2--] = val;
+ }
+ }
+}