Beispiel #1
0
        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);
            }
        }
Beispiel #2
0
        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;
            }
        }
Beispiel #3
0
        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;
        }