Exemplo n.º 1
0
        internal CircularVersionList Upsize()
        {
            CircularVersionList newList = new CircularVersionList(this.internalArray.Length << 1);
            long localMetaIndex         = Interlocked.Read(ref this.metaIndex);
            int  size      = (int)(localMetaIndex >> 32);
            int  tailIndex = (int)(localMetaIndex & 0xFFFFFFFFL);

            if (size == 0)
            {
                return(newList);
            }

            int headIndex =
                (tailIndex - size + 1 + this.internalArray.Length) %
                this.internalArray.Length;

            if (tailIndex >= headIndex)
            {
                Array.Copy(this.internalArray, headIndex, newList.internalArray, 0, size);
            }
            else
            {
                Array.Copy(
                    this.internalArray,
                    headIndex,
                    newList.internalArray,
                    0,
                    this.internalArray.Length - headIndex);

                Array.Copy(
                    this.internalArray,
                    0,
                    newList.internalArray,
                    this.internalArray.Length - headIndex,
                    tailIndex + 1);
            }

            newList.metaIndex = (long)size << 32 | (long)(size - 1);

            return(newList);
        }
Exemplo n.º 2
0
 public VersionList(int capacity = 8)
 {
     this.tailKey     = -1;
     this.versionList = new CircularVersionList(capacity < 0 ? VersionList.MaxCapacity : capacity);
 }