public void Insert(ListIterator <T> pos, RandomAccessIterator <T> begin, RandomAccessIterator <T> end) { Capacity = Count + IteratorUtil.Distance(begin, end); int index = pos.Position; InsertRange(index, IteratorUtil.CreateEnumerator(begin, end)); }
/// <summary> /// Erases a range of elements. Returns an iterator to the next element after the deleted range. /// </summary> /// <param name="begin"></param> /// <param name="end"></param> /// <returns></returns> ListIterator <T> Erase(ListIterator <T> begin, ListIterator <T> end) { int index = begin.Position; int count = IteratorUtil.Distance(begin, end); base.RemoveRange(index, count); return(new ListIterator <T>(this, index)); }
/// <summary> /// Erases a range of elements. Returns an iterator to the next element after the deleted range. /// </summary> /// <param name="begin"></param> /// <param name="end"></param> /// <returns></returns> public ListIterator <T> Erase(ListIterator <T> begin, ListIterator <T> end) { int index = begin.Position; int count = IteratorUtil.Distance(begin, end); Shift(index + count, -count); m_Count -= count; return(new ListIterator <T>(this, index)); }
[Test] public void Unique_RandomAccessIterator_Predicate() { RandomAccessIterator <int> begin = IteratorUtil.Begin(src); RandomAccessIterator <int> end = IteratorUtil.End(src); RandomAccessIterator <int> result = Algorithm.Unique(begin, end, delegate(int lhs, int rhs) { return(lhs == rhs); }); VerifyOutput(); Assert.IsNotNull(result); Assert.AreEqual(5, IteratorUtil.Distance(begin, result)); }
[Test] public void SearchN_Iterator() { int[] array = Constants.TEST_BIG_INT_ARRAY; ForwardIterator <int> result = Algorithm.SearchN(IteratorUtil.Begin(array), IteratorUtil.End(array), 3, 1); Assert.IsNotNull(result); Assert.IsInstanceOfType(typeof(ListIterator <int>), result); Assert.AreEqual(5, IteratorUtil.Distance(IteratorUtil.Begin(array), result)); Assert.AreEqual(array[5], result.Read()); }
[Test] public void Unique_ForwardIterator() { ForwardIterator <int> begin = IteratorUtil.Begin(src); ForwardIterator <int> end = IteratorUtil.End(src); ForwardIterator <int> result = Algorithm.Unique(begin, end); VerifyOutput(); Assert.IsNotNull(result); Assert.AreEqual(5, IteratorUtil.Distance(begin, result)); }
[Test] public void Unique_RandomAccessIterator_Comparer() { RandomAccessIterator <int> begin = IteratorUtil.Begin(src); RandomAccessIterator <int> end = IteratorUtil.End(src); RandomAccessIterator <int> result = Algorithm.Unique(begin, end, EqualityComparer <int> .Default); VerifyOutput(); Assert.IsNotNull(result); Assert.AreEqual(5, IteratorUtil.Distance(begin, result)); }
[Test] public void FindFirstOf_Iterator() { ForwardIterator <int> result = Algorithm.FindFirstOf(IteratorUtil.Begin(array), IteratorUtil.End(array), IteratorUtil.Begin(search), IteratorUtil.End(search)); Assert.IsNotNull(result); Assert.IsInstanceOfType(typeof(ListIterator <int>), result); Assert.AreEqual(5, IteratorUtil.Distance(IteratorUtil.Begin(array), result)); Assert.AreEqual(33, result.Read()); }
[Test] public void FindEnd_Predicate() { ForwardIterator <int> result = Algorithm.FindEnd(IteratorUtil.Begin(array), IteratorUtil.End(array), IteratorUtil.Begin(search), IteratorUtil.End(search), Functional.EqualTo <int>); Assert.IsNotNull(result); Assert.IsInstanceOfType(typeof(ListIterator <int>), result); Assert.AreEqual(array.Length - 9, IteratorUtil.Distance(IteratorUtil.Begin(array), result)); Assert.AreEqual(5, result.Read()); }
[Test] public void FindEnd_Comparer() { ForwardIterator <int> result = Algorithm.FindEnd(IteratorUtil.Begin(array), IteratorUtil.End(array), IteratorUtil.Begin(search), IteratorUtil.End(search), EqualityComparer <int> .Default); Assert.IsNotNull(result); Assert.IsInstanceOfType(typeof(ListIterator <int>), result); Assert.AreEqual(array.Length - 9, IteratorUtil.Distance(IteratorUtil.Begin(array), result)); Assert.AreEqual(5, result.Read()); }
[Test] public void UniqueCopy_ForwardIterator() { ForwardIterator <int> destIter = IteratorUtil.Begin(dest); destIter.MoveNext(); ForwardIterator <int> result = Algorithm.UniqueCopy(IteratorUtil.Begin(src), IteratorUtil.End(src), destIter); VerifyOutput(); Assert.IsNotNull(result); Assert.AreEqual(6, IteratorUtil.Distance(IteratorUtil.Begin(dest), result)); Assert.AreEqual(Int32.MinValue, result.Read()); }
[Test] public void Remove_Comparer_ForwardIterator() { ForwardIterator <int> begin = IteratorUtil.Begin(src); ForwardIterator <int> end = IteratorUtil.End(src); ForwardIterator <int> result = Algorithm.Remove(begin, end, 29, EqualityComparer <int> .Default); Assert.IsNotNull(result); Assert.AreEqual(0, (begin as ListIterator <int>).Position); Assert.AreEqual(src.Length, IteratorUtil.Distance(begin, end)); Assert.AreEqual(src.Length - 4, IteratorUtil.Distance(begin, result)); }
[Test] public void UniqueCopy_Predicate_ForwardIterator() { ForwardIterator <string> destIter = IteratorUtil.Begin(dest); destIter.MoveNext(); ForwardIterator <string> result = Algorithm.UniqueCopy(IteratorUtil.Begin(src), IteratorUtil.End(src), destIter, delegate(string lhs, string rhs) { return(lhs == rhs); }); VerifyOutput(); Assert.IsNotNull(result); Assert.AreEqual(6, IteratorUtil.Distance(IteratorUtil.Begin(dest), result)); Assert.AreEqual(MARKER, result.Read()); }
[Test] public void UniqueCopy_Comparer_ForwardIterator() { ForwardIterator <string> destIter = IteratorUtil.Begin(dest); destIter.MoveNext(); ForwardIterator <string> result = Algorithm.UniqueCopy(IteratorUtil.Begin(src), IteratorUtil.End(src), destIter, EqualityComparer <string> .Default); VerifyOutput(); Assert.IsNotNull(result); Assert.AreEqual(6, IteratorUtil.Distance(IteratorUtil.Begin(dest), result)); Assert.AreEqual(MARKER, result.Read()); }
public void TestConstructors() { Vector<int> v = new Vector<int>(); Assert.AreEqual(0, v.Count); Assert.AreEqual(0, v.Capacity); Assert.IsTrue(v.Begin().Equals(v.End())); Assert.AreEqual(0, IteratorUtil.Distance(v.Begin(), v.End())); int[] src = new int[]{1,2,3,4,5}; v = new Vector<int>(src); Assert.AreEqual(src.Length, v.Count); Assert.IsFalse(v.Begin().Equals(v.End())); Assert.AreEqual(src.Length, IteratorUtil.Distance(v.Begin(), v.End())); for(int i=0; i<src.Length; ++i) { Assert.AreEqual(src[i], v[i]); } v = new Vector<int>(IteratorUtil.Begin(src), IteratorUtil.End(src)); Assert.AreEqual(src.Length, v.Count); Assert.IsFalse(v.Begin().Equals(v.End())); Assert.AreEqual(src.Length, IteratorUtil.Distance(v.Begin(), v.End())); for(int i=0; i<src.Length; ++i) { Assert.AreEqual(src[i], v[i]); } v = new Vector<int>(v); Assert.AreEqual(src.Length, v.Count); Assert.IsFalse(v.Begin().Equals(v.End())); Assert.AreEqual(src.Length, IteratorUtil.Distance(v.Begin(), v.End())); for(int i=0; i<src.Length; ++i) { Assert.AreEqual(src[i], v[i]); } v = new Vector<int>(10); Assert.AreEqual(10, v.Count); Assert.IsFalse(v.Begin().Equals(v.End())); Assert.AreEqual(10, IteratorUtil.Distance(v.Begin(), v.End())); Algorithm.ForEach(v.Begin(), v.End(), delegate(int x) { Assert.AreEqual(0, x); }); v = new Vector<int>(10, 42); Assert.AreEqual(10, v.Count); Assert.IsFalse(v.Begin().Equals(v.End())); Assert.AreEqual(10, IteratorUtil.Distance(v.Begin(), v.End())); Algorithm.ForEach(v.Begin(), v.End(), delegate(int x) { Assert.AreEqual(42, x); }); }
[Test] public void RemoveCopy_List_ForwardIterator_Comparer() { ForwardIterator <int> destIter = IteratorUtil.Begin(dest); destIter.MoveNext(); ForwardIterator <int> result = Algorithm.RemoveCopy(src, destIter, 29, EqualityComparer <int> .Default); VerifyOutput(); Assert.IsNotNull(result); Assert.AreEqual(src.Length - 3, IteratorUtil.Distance(IteratorUtil.Begin(dest), result)); Assert.AreEqual(Int32.MinValue, result.Read()); }
[Test] public void RemoveCopyIf_ForwardIterator() { ForwardIterator <int> destIter = IteratorUtil.Begin(dest); destIter.MoveNext(); ForwardIterator <int> result = Algorithm.RemoveCopyIf(IteratorUtil.Begin(src), IteratorUtil.End(src), destIter, Is29); VerifyOutput(); Assert.IsNotNull(result); Assert.AreEqual(src.Length - 3, IteratorUtil.Distance(IteratorUtil.Begin(dest), result)); Assert.AreEqual(Int32.MinValue, result.Read()); }
[Test] public void UniqueCopy_List_Predicate_ForwardIterator() { ForwardIterator <int> destIter = IteratorUtil.Begin(dest); destIter.MoveNext(); ForwardIterator <int> result = Algorithm.UniqueCopy(src, destIter, delegate(int lhs, int rhs) { return(lhs == rhs); }); VerifyOutput(); Assert.IsNotNull(result); Assert.AreEqual(6, IteratorUtil.Distance(IteratorUtil.Begin(dest), result)); Assert.AreEqual(Int32.MinValue, (result as ListIterator <int>).Read()); }
[Test] public void UniqueCopy_List_Comparer_ForwardIterator() { ForwardIterator <int> destIter = IteratorUtil.Begin(dest); destIter.MoveNext(); ForwardIterator <int> result = Algorithm.UniqueCopy(src, destIter, EqualityComparer <int> .Default); VerifyOutput(); Assert.IsNotNull(result); Assert.AreEqual(6, IteratorUtil.Distance(IteratorUtil.Begin(dest), result)); Assert.AreEqual(Int32.MinValue, (result as ListIterator <int>).Read()); }
[Test] public void Search_Iterator() { int[] array = Constants.TEST_INT_ARRAY; int[] search = new int[3]; Algorithm.CopyN(array, 5, 3, search, 0); ForwardIterator <int> result = Algorithm.Search(IteratorUtil.Begin(array), IteratorUtil.End(array), IteratorUtil.Begin(search), IteratorUtil.End(search)); Assert.IsNotNull(result); Assert.IsInstanceOfType(typeof(ListIterator <int>), result); Assert.AreEqual(5, IteratorUtil.Distance(IteratorUtil.Begin(array), result)); Assert.AreEqual(array[5], result.Read()); }
public static bool Equal <T>(RandomAccessIterator <T> begin, RandomAccessIterator <T> end, RandomAccessIterator <T> cmpBegin, RandomAccessIterator <T> cmpEnd, IComparer <T> comparer) { if (IteratorUtil.Distance(begin, end) != IteratorUtil.Distance(cmpBegin, cmpEnd)) { return(false); } for (; !begin.Equals(end) && !cmpBegin.Equals(cmpEnd); begin.MoveNext(), cmpBegin.MoveNext()) { T t1 = begin.Read(); T t2 = cmpBegin.Read(); if (comparer.Compare(t1, t2) != 0) { return(false); } } return(true); }
[Test] public void AdjacentFind_ForwardIterator() { int[] array = Constants.TEST_INT_ARRAY; ForwardIterator <int> begin = IteratorUtil.Begin(array); ForwardIterator <int> end = IteratorUtil.End(array); ForwardIterator <int> iter = Algorithm.AdjacentFind(begin, end); Assert.AreEqual(6, IteratorUtil.Distance(begin, iter)); Assert.AreEqual(array[6], iter.Read()); iter = Algorithm.AdjacentFind(IteratorUtil.Begin(array), IteratorUtil.End(array), EqualityComparer <int> .Default); Assert.AreEqual(6, IteratorUtil.Distance(begin, iter)); Assert.AreEqual(array[6], iter.Read()); iter = Algorithm.AdjacentFind(IteratorUtil.Begin(array), IteratorUtil.End(array), AreEqual); Assert.AreEqual(6, IteratorUtil.Distance(begin, iter)); Assert.AreEqual(array[6], iter.Read()); }
/// <summary> /// Inserts a range into the collection before a position pointed to by an iterator /// </summary> /// <param name="pos"></param> /// <param name="begin"></param> /// <param name="end"></param> public void Insert(ListIterator <T> pos, ForwardIterator <T> begin, ForwardIterator <T> end) { int distance = IteratorUtil.Distance(begin, end); Insert(pos, begin, end, 0); }
public void Insert(ListIterator <T> pos, RandomAccessIterator <T> begin, RandomAccessIterator <T> end) { int distance = IteratorUtil.Distance(begin, end); Insert(pos, begin, end, distance); }
public void AddRange(RandomAccessIterator <T> begin, RandomAccessIterator <T> end) { CheckReAlloc(m_Count + IteratorUtil.Distance(begin, end)); Algorithm.ForEach(begin, end, Add); }
public void Assign(RandomAccessIterator <T> begin, RandomAccessIterator <T> end) { Clear(); Capacity = IteratorUtil.Distance(begin, end); Algorithm.ForEach(begin, end, Add); }