Ejemplo n.º 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");
     }
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Tries to remove the following key from the tree.
 /// </summary>
 /// <param name="key">the key to remove</param>
 /// <returns>true if successful, false otherwise.</returns>
 public bool TryRemove(TKey key)
 {
     if (LeafStorage.TryRemove(key))
     {
         if (IsDirty && AutoFlush)
         {
             m_header.SaveHeader(Stream);
         }
         return(true);
     }
     return(false);
 }