public override void Add(T element) { var index = Interlocked.Increment(ref this.index) - 1; var adjustedIndex = index; var arrayIndex = CCList <T> .GetArrayIndex(index + 1); if (arrayIndex > 0) { adjustedIndex -= CCList <T> .counts[arrayIndex - 1]; } if (this.array[arrayIndex] == null) { var arrayLength = CCList <T> .sizes[arrayIndex]; Interlocked.CompareExchange(ref this.array[arrayIndex], PoolArray <T> .Claim(arrayLength), null); } this.array[arrayIndex][adjustedIndex] = element; var count = this.count; var fuzzyCount = Interlocked.Increment(ref this.fuzzyCount); if (fuzzyCount == index + 1) { Interlocked.CompareExchange(ref this.count, fuzzyCount, count); } }
public override T this[int index] { get { if (index < 0 || index >= this.count) { throw new ArgumentOutOfRangeException("index"); } var arrayIndex = CCList <T> .GetArrayIndex(index + 1); if (arrayIndex > 0) { index -= ((1 << arrayIndex) - 1); } return(this.array[arrayIndex][index]); } set { var arrayIndex = CCList <T> .GetArrayIndex(index + 1); if (arrayIndex > 0) { index -= ((1 << arrayIndex) - 1); } this.array[arrayIndex][index] = value; } }
public void InitialCopyOf(CCList <T> other) { if (other == null) { this.OnRecycle(); return; } for (int i = 0; i < other.array.Length; ++i) { if (other.array[i] != null) { if (this.array[i] != null) { PoolArray <T> .Release(ref this.array[i]); } this.array[i] = PoolArray <T> .Claim(other.array[i].Length); } else { PoolArray <T> .Release(ref this.array[i]); } ArrayUtils.Clear(this.array[i]); } this.index = other.index; this.count = other.count; this.fuzzyCount = other.fuzzyCount; }
public void RemoveAt(int index) { if (index < 0 || index >= this.count) { throw new ArgumentOutOfRangeException("index"); } var arrayIndex = CCList <T> .GetArrayIndex(index + 1); if (arrayIndex > 0) { index -= ((1 << arrayIndex) - 1); } --this.index; --this.count; --this.fuzzyCount; var arr = this.array[arrayIndex]; System.Array.Copy(arr, index + 1, arr, index, arr.Length - 1 - index); arr[arr.Length - 1] = default; }