summaryrefslogtreecommitdiff
path: root/Thronefall_1_57/Decompile/Ara/ElasticArray.cs
blob: 038435cf6658d89050cab1b4736128afb566bd5b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
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;
		}
	}
}