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 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;
        }