Exemple #1
0
        /// <summary>
        /// Inserts the provided key into the current node.
        /// </summary>
        /// <param name="oldKey"></param>
        /// <param name="newKey"></param>
        private void InternalUpdateKey(TKey oldKey, TKey newKey)
        {
            //ToDo: Make this implementation generic
            byte *ptr   = GetReadPointer();
            int   index = KeyMethods.BinarySearch(ptr + HeaderSize, oldKey, RecordCount, KeyValueSize); // BinarySearch(key);

            if (index < 0)
            {
                throw new KeyNotFoundException("Missing key on update.");
            }

            ptr = GetWritePointer() + HeaderSize + index * KeyValueSize;

            if (index > 0)
            {
                if (!KeyMethods.IsGreaterThan(ptr - KeyValueSize, newKey))
                {
                    throw new Exception("Cannot update the key because the sorting gets messed up");
                }
            }
            if (index < RecordCount - 1)
            {
                if (!KeyMethods.IsGreaterThan(newKey, ptr + KeyValueSize))
                {
                    throw new Exception("Cannot update the key because the sorting gets messed up");
                }
            }

            newKey.Write(ptr);
        }
        /// <summary>
        /// Using <see cref="SortedTreeScannerBase{TKey,TValue}.Pointer"/> advance to the search location of the provided <see cref="key"/>
        /// </summary>
        /// <param name="key">the key to advance to</param>
        protected override unsafe void FindKey(TKey key)
        {
            int offset = KeyMethods.BinarySearch(Pointer, key, RecordCount, m_keyValueSize);

            if (offset < 0)
            {
                offset = ~offset;
            }
            IndexOfNextKeyValue = offset;
        }
Exemple #3
0
        private void InternalUpdateValue(TKey key, TValue value)
        {
            //ToDo: Make this implementation generic
            byte *ptr   = GetReadPointer();
            int   index = KeyMethods.BinarySearch(ptr + HeaderSize, key, RecordCount, KeyValueSize); // BinarySearch(key);

            if (index < 0)
            {
                throw new KeyNotFoundException();
            }

            ptr = GetWritePointer() + HeaderSize + index * KeyValueSize + KeySize;
            value.Write(ptr);
        }
 protected override int GetIndexOf(TKey key)
 {
     return(KeyMethods.BinarySearch(GetReadPointerAfterHeader(), key, RecordCount, KeyValueSize));
 }