public SortedSet(IEnumerable <T> collection) { _comparer = Comparer <T> .Default; _wrapped = new AVLTree <T, T>(); foreach (var item in Check.NotNullArgument(collection, "collection")) { _wrapped.AddNonDuplicate(item, item); } }
public SortedSet(IEnumerable <T> collection, IComparer <T> comparer) { Comparer = comparer ?? Comparer <T> .Default; _wrapped = new AVLTree <T, VoidStruct>(); foreach (var item in collection ?? throw new ArgumentNullException(nameof(collection))) { _wrapped.AddNonDuplicate(item, default); } }
private static void AddAndIterateNonDuplicate(int[] data) { var avl = new AVLTree <int, int>(); var copy = new List <int>(); foreach (var item in data) { bool duplicate = copy.Contains(item); Assert.AreNotEqual(avl.AddNonDuplicate(item, item), duplicate); if (!duplicate) { copy.Add(item); } } Assert.AreEqual(avl.Count, copy.Count); Array.Sort(data); var index = 0; foreach (var item in avl) { Assert.AreEqual(item.Key, copy[index]); index++; } }
internal virtual bool AddExtracted(T item) { return(_wrapped.AddNonDuplicate(item, default)); }
protected virtual bool AddExtracted(T item) { return(_wrapped.AddNonDuplicate(item, item)); }
private static void AddAndIterateNonDuplicate(int[] data) { var avl = new AVLTree<int, int>(); var copy = new List<int>(); foreach (var item in data) { bool duplicate = copy.Contains(item); Assert.AreNotEqual(avl.AddNonDuplicate(item, item), duplicate); if (!duplicate) { copy.Add(item); } } Assert.AreEqual(avl.Count, copy.Count); Array.Sort(data); var index = 0; foreach (var item in avl) { Assert.AreEqual(item.Key, copy[index]); index++; } }