Example #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);
 }
        public void Sort(IComparer comparer)
        {
            var comparerWrapper = new ComparerWrapper((comparer != null) ? comparer : ObjectComparer.Singleton);

            m_items.Sort(comparerWrapper);

            this.OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
        }
        public CompositeEqualityComparer AddComparer <T>([NotNull] Func <T, T, bool> equalsDel, [NotNull] Func <T, int> getHashDel, bool exactlySameType = false)
        {
            var comparerWrapper = new ComparerWrapper <T>(equalsDel, getHashDel, exactlySameType);

            lock (_locker)
            {
                Array.Resize(ref _comparers, _comparers.Length + 1);
                _comparers[_comparers.Length - 1] = comparerWrapper;
            }
            return(this);
        }
        public CompositeEqualityComparer AddComparer <T>([NotNull] IEqualityComparer <T> comparer, bool exactlySameType = false)
        {
            var comparerWrapper = new ComparerWrapper <T>(comparer, exactlySameType);

            lock (_locker)
            {
                Array.Resize(ref _comparers, _comparers.Length + 1);
                _comparers[_comparers.Length - 1] = comparerWrapper;
            }
            return(this);
        }
Example #5
0
            public static ComparerWrapper <T> Create(IComparer <T> comparer)
            {
                // Let nulls be handled by the CollectionAssert class.
                if (comparer == null)
                {
                    return(null);
                }

                var wrapper = new ComparerWrapper <T>();

                wrapper._comparer = comparer;
                return(wrapper);
            }
Example #6
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);
 }
Example #7
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();
             }
         }
     }
 }
Example #8
0
 /// <summary>
 /// Wrapper for the <see cref="CollectionAssert.AreNotEqual(ICollection,ICollection,IComparer,String,Object[])"/> method.
 /// </summary>
 public static void AreNotEqual <T>(IEnumerable <T> notExpected, IEnumerable <T> actual, IComparer <T> comparer, String message, Object[] parameters)
 {
     CollectionAssert.AreNotEqual(notExpected?.ToList(), actual?.ToList(), ComparerWrapper <T> .Create(comparer), message, parameters);
 }
Example #9
0
 /// <summary>
 /// Wrapper for the <see cref="CollectionAssert.AreNotEqual(ICollection,ICollection,IComparer)"/> method.
 /// </summary>
 public static void AreNotEqual <T>(IEnumerable <T> notExpected, IEnumerable <T> actual, IComparer <T> comparer)
 {
     CollectionAssert.AreNotEqual(notExpected?.ToList(), actual?.ToList(), ComparerWrapper <T> .Create(comparer));
 }
Example #10
0
 /// <summary>
 /// Wrapper for the <see cref="CollectionAssert.AreEqual(ICollection,ICollection,IComparer,String)"/> method.
 /// </summary>
 public static void AreEqual <T>(IEnumerable <T> expected, IEnumerable <T> actual, IComparer <T> comparer, String message)
 {
     CollectionAssert.AreEqual(expected?.ToList(), actual?.ToList(), ComparerWrapper <T> .Create(comparer), message);
 }