Exemple #1
0
 /// <summary>
 /// Removes the specified leaf node from the sparse index
 /// </summary>
 /// <param name="key">The leaf node to remove</param>
 /// <param name="level"></param>
 public void Remove(TKey key, byte level)
 {
     if (level <= RootNodeLevel)
     {
         SortedTreeNodeBase <TKey, SnapUInt32> node = GetNode(level);
         if (!node.TryRemove(key))
         {
             throw new KeyNotFoundException();
         }
         if (level == RootNodeLevel)
         {
             if (node.RightSiblingNodeIndex == uint.MaxValue &&
                 node.LeftSiblingNodeIndex == uint.MaxValue &&
                 node.RecordCount == 1)
             {
                 RootNodeLevel--;
                 node.TryGetFirstRecord(m_tmpKey, m_tmpValue);
                 RootNodeIndexAddress = m_tmpValue.Value;
                 node.Clear();
             }
         }
     }
     else
     {
         throw new Exception("Cannot update value of root");
     }
 }
        /// <summary>
        /// Gets the lower and upper bounds of this tree.
        /// </summary>
        /// <param name="lowerBounds">The first key in the tree</param>
        /// <param name="upperBounds">The final key in the tree</param>
        /// <remarks>
        /// If the tree contains no data. <see cref="lowerBounds"/> is set to it's maximum value
        /// and <see cref="upperBounds"/> is set to it's minimum value.
        /// </remarks>
        public void GetKeyRange(TKey lowerBounds, TKey upperBounds)
        {
            LeafStorage.SeekToFirstNode();
            bool firstFound = LeafStorage.TryGetFirstRecord(lowerBounds, m_tempValue);

            LeafStorage.SeekToLastNode();
            bool lastFound = LeafStorage.TryGetLastRecord(upperBounds, m_tempValue);

            if (firstFound && lastFound)
            {
                return;
            }
            lowerBounds.SetMax();
            upperBounds.SetMin();
        }
Exemple #3
0
        /// <summary>
        /// Gets the node index of the first leaf node in the tree.
        /// </summary>
        /// <param name="level">the level of the node requesting the lookup</param>
        /// <returns>the index of the first leaf node</returns>
        public uint GetFirstIndex(byte level)
        {
            if (RootNodeLevel == level)
            {
                return(RootNodeIndexAddress);
            }

            uint nodeIndexAddress = RootNodeIndexAddress;
            byte nodeLevel        = RootNodeLevel;

            while (nodeLevel > level)
            {
                SortedTreeNodeBase <TKey, SnapUInt32> currentNode = GetNode(nodeLevel);
                currentNode.SetNodeIndex(nodeIndexAddress);
                if (!currentNode.TryGetFirstRecord(m_tmpValue))
                {
                    throw new Exception("Node is empty");
                }
                nodeIndexAddress = m_tmpValue.Value;
                nodeLevel--;
            }
            return(nodeIndexAddress);
        }