dotnetanywhere-wb /corlib/System.Collections.Generic/List.cs

Language C# Lines 274
MD5 Hash 923f2938fab538099b6c776a538d061b Estimated Cost $5,642 (why?)
Repository https://bitbucket.org/cosi2/dotnetanywhere-wb.git View Raw File
  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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
using System;

#if LOCALTEST
using System.Collections;
using System.Collections.Generic;
namespace System_.Collections.Generic {
#else
namespace System.Collections.Generic {
#endif
	public class List<T> : IList<T>, ICollection<T>, IEnumerable<T>, IList, ICollection, IEnumerable {

		public struct Enumerator : IEnumerator<T>, IDisposable {

			private List<T> list;
			private int index;

			internal Enumerator(List<T> list) {
				this.list = list;
				this.index = -1;
			}

			public T Current {
				get {
					return this.list[this.index];
				}
			}

			public void Dispose() {
			}

			object IEnumerator.Current {
				get {
					return this.list[this.index];
				}
			}

			public bool MoveNext() {
				this.index++;
				return (this.index < this.list.Count);
			}

			public void Reset() {
				this.index = -1;
			}

		}

		private const int defaultCapacity = 4;

		private T[] items;
		private int size;

		public List() : this(defaultCapacity) { }

		public List(int capacity) {
			if (capacity < 0) {
				throw new ArgumentOutOfRangeException("capacity");
			}
			this.items = new T[capacity];
			this.size = 0;
		}

		public List(IEnumerable<T> collection) {
			ICollection<T> iCol = collection as ICollection<T>;
			if (iCol != null) {
				this.size = iCol.Count;
				this.items = new T[this.size];
				iCol.CopyTo(this.items, 0);
			} else {
				this.items = new T[defaultCapacity];
				this.size = 0;
				foreach (T item in collection) {
					this.Add(item);
				}
			}
		}

		private void EnsureSpace(int space) {
			if (this.size + space > this.items.Length) {
				Array.Resize<T>(ref this.items, Math.Max(this.items.Length << 1, 4));
			}
		}

		private void Shift(int index, int count) {
			if (count > 0) {
				this.EnsureSpace(count);
				for (int i = this.size - 1; i >= index; i--) {
					this.items[i + count] = this.items[i];
				}
			} else {
				for (int i = index; i < this.size + count; i++) {
					this.items[i] = this.items[i - count];
				}
			}
			this.size += count;
		}

		public void Add(T item) {
			this.EnsureSpace(1);
			this.items[this.size++] = item;
		}

		public int Count {
			get {
				return this.size;
			}
		}

		public int Capacity {
			get {
				return this.items.Length;
			}
			set {
				throw new NotImplementedException();
			}
		}

		public T this[int index] {
			get {
				if (index >= this.size || index < 0) {
					throw new ArgumentOutOfRangeException("index");
				}
				return this.items[index];
			}
			set {
				if (index >= this.size || index < 0) {
					throw new ArgumentOutOfRangeException("index");
				}
				this.items[index] = value;
			}
		}

		public Enumerator GetEnumerator() {
			return new Enumerator(this);
		}

		public int IndexOf(T item, int start, int count) {
			return Array.IndexOf<T>(this.items, item, start, count);
		}

		public int IndexOf(T item, int start) {
			return this.IndexOf(item, start, this.size - start);
		}

		public void InsertRange(int index, IEnumerable<T> collection) {
			if (collection == null) {
				throw new ArgumentNullException("collection");
			}
			if (index < 0 || index > this.size) {
				throw new ArgumentOutOfRangeException("index");
			}
			List<T> toInsert = new List<T>(collection);
			this.Shift(index, toInsert.Count);
			for (int i = 0; i < toInsert.Count; i++) {
				this.items[index + i] = toInsert[i];
			}
		}

		public T[] ToArray() {
			T[] array = new T[this.size];
			Array.Copy(this.items, array, this.size);
			return array;
		}

		#region Interface Members

		public int IndexOf(T item) {
			return this.IndexOf(item, 0, size);
		}

		public void Insert(int index, T item) {
			if (index < 0 || index > this.size) {
				throw new ArgumentOutOfRangeException("index");
			}
			this.Shift(index, 1);
			this.items[index] = item;
		}

		public void RemoveAt(int index) {
			this.Shift(index, -1);
		}

		public bool IsReadOnly {
			get {
				return false;
			}
		}

		public void Clear() {
			Array.Clear(this.items, 0, this.items.Length);
			this.size = 0;
		}

		public bool Contains(T item) {
			return Array.IndexOf(this.items, item) >= 0;
		}

		public void CopyTo(T[] array, int arrayIndex) {
			Array.Copy(this.items, 0, (Array)array, arrayIndex, this.size);
		}

		public bool Remove(T item) {
			int idx = Array.IndexOf(this.items, item);
			if (idx >= 0) {
				this.RemoveAt(idx);
				return true;
			}
			return false;
		}

		IEnumerator<T> IEnumerable<T>.GetEnumerator() {
			return new Enumerator(this);
		}

		IEnumerator IEnumerable.GetEnumerator() {
			return new Enumerator(this);
		}

		public bool IsFixedSize {
			get {
				return false;
			}
		}

		object IList.this[int index] {
			get {
				return this[index];
			}
			set {
				this[index] = (T)value;
			}
		}

		public int Add(object value) {
			this.Add((T)value);
			return this.items.Length - 1;
		}

		public bool Contains(object value) {
			return this.Contains((T)value);
		}

		public int IndexOf(object value) {
			return this.IndexOf((T)value);
		}

		public void Insert(int index, object value) {
			this.Insert(index, (T)value);
		}

		public void Remove(object value) {
			this.Remove((T)value);
		}

		public bool IsSynchronized {
			get {
				return false;
			}
		}

		public object SyncRoot {
			get {
				return this;
			}
		}

		public void CopyTo(Array array, int index) {
			Array.Copy(this.items, 0, array, index, this.size);
		}

		#endregion
	}
}
Back to Top