示例#1
0
 /// <summary>
 /// Search for Item in this collection with an option
 /// to position the B-Tree current pointer to the 1st
 /// instance of the record having matching key with 'Item'.
 /// This is useful when searching a tree with items having
 /// duplicate Keys.
 /// </summary>
 /// <param name="item"></param>
 /// <param name="goToFirstInstance"></param>
 /// <returns></returns>
 public bool Search(object item, bool goToFirstInstance)
 {
     if (RootNode == null)
     {
         throw new InvalidOperationException("Can't Search item, ObjectStore is close.");
     }
     if (HintSequentialRead)
     {
         HintSequentialRead = false;
     }
     if (RootNode != null && Count > 0)
     {
         BeginTreeMaintenance();
         try
         {
             if (CurrentEntry == null ||
                 ComparerWrapper.Compare(CurrentEntry, item) != 0 ||
                 goToFirstInstance)
             {
                 bool r = RootNode.Search(this, item, goToFirstInstance);
                 return(r);
             }
         }
         finally
         {
             EndTreeMaintenance();
         }
         return(true);
     }
     return(false);
 }
示例#2
0
 /// <summary>
 /// Search btree for a certain record (Item). If current record is equal
 /// to Item then true will be returned without doing any search operation.
 /// This minimizes unnecessary BTree traversal. If Item is found, it becomes the current item.
 /// </summary>
 /// <param name="Item">record to search for</param>
 /// <param name="GoToFirstInstance">if true, will make first instance of duplicated keys the current record</param>
 /// <returns>Returns true if found else, false</returns>
 public bool Search(object Item, bool GoToFirstInstance)
 {
     if (Count > 0)
     {
         if (CurrentEntry == null || ComparerWrapper.Compare(CurrentEntry, Item) != 0 ||
             GoToFirstInstance)
         {
             bool r = Root.Search(this, Item, GoToFirstInstance);
             TreeNode.ResetArray(TempSlots, null);
             TempParent = null;
             return(r);
         }
         return(true);                   // current entry is equal to ObjectToSearch!!
     }
     // tree is empty
     return(false);
 }
示例#3
0
 /// <summary>
 /// Remove "Item" from the tree. Doesn't throw exception if "Item" is not found
 /// </summary>
 /// <param name="Item">Record to remove</param>
 public void Remove(object Item)         // return true if found, else false
 {
     if (Count > 0)
     {
         if (CurrentEntry == null)
         {
             if (Root.Search(this, Item, false))
             {
                 Remove();
             }
         }
         else if (ComparerWrapper.Compare(CurrentEntry, Item) == 0)
         {
             Remove();
         }
         else
         {
             if (Root.Search(this, Item, false))
             {
                 Remove();
             }
         }
     }
 }