示例#1
0
        /// <summary>
        /// Constructs a NamedDataBuffer with the initial capacity
        /// </summary>
        /// <param name="initialCapacity">the starting size of the buffer</param>
        /// <param name="hashSize">the size of the hashtable in the buffer</param>
        public NamedDataBuffer(int initialCapacity, int hashSize = 47)
        {
            _buffer     = new DoubleDataBuffer <TValue, Entry>(initialCapacity);
            _hashStarts = new DataBuffer <int>(hashSize, -1);
            _hashEnds   = new int[hashSize];
            _hashSize   = hashSize;
            _capacity   = initialCapacity;

            _buffer.Set(BufferTransactionType.WriteRead, 0, default, new Entry()
        /// <summary>
        /// Perform a deep copy of a DoubleDataBuffer
        /// </summary>
        /// <param name="copy">buffer to copy</param>
        /// <param name="length">the length of the new buffer</param>
        public DoubleDataBuffer(DoubleDataBuffer <TPrimary, TSecondary> copy, int length = -1)
        {
            length = length == -1 ? copy.GetLength() : length;

            if (length > copy._value1s.Length)
            {
                for (int i = 0; i < 3; i++)
                {
                    _value1s[i] = new TPrimary[length];
                    copy._value1s[i].CopyTo(_value1s[i], 0);

                    _value2s[i] = new TSecondary[length];
                    copy._value2s[i].CopyTo(_value2s[i], 0);
                }

                for (int i = 0; i < 2; i++)
                {
                    _dirtyMarks[i] = new bool[length];
                    copy._dirtyMarks[i].CopyTo(_dirtyMarks[i], 0);

                    _dirtyEntries[i] = new Queue <int>(copy._dirtyEntries[i]);
                }
            }
            else
            {
                for (int i = 0; i < 3; i++)
                {
                    _value1s[i] = new TPrimary[length];
                    Buffer.BlockCopy(copy._value1s[i], 0, _value1s[i], 0, length);

                    _value2s[i] = new TSecondary[length];
                    Buffer.BlockCopy(copy._value2s[i], 0, _value2s[i], 0, length);
                }

                for (int i = 0; i < 2; i++)
                {
                    _dirtyMarks[i] = new bool[length];
                    Buffer.BlockCopy(copy._dirtyMarks[i], 0, _dirtyMarks[i], 0, length);

                    foreach (var entry in copy._dirtyEntries[i].Where(entry => entry < length))
                    {
                        _dirtyEntries[i].Enqueue(entry);
                    }
                }
            }
        }