public CircularLinkedListNode <T> FindPair(T value1, T value2) { uint startVersion = version; CircularLinkedListNode <T> node = this.First; if (node != null) { do { if (node.Next != null) { bool firstEqual = Equals(value1, node.Value); bool secondEqual = Equals(value2, node.Next.Value); if (firstEqual && secondEqual) { return(node); } } if (version != startVersion) { throw new InvalidOperationException("list modified"); } node = node.Next; }while (node != null && node != this.Last.Next); } return(null); }
public CircularLinkedListNode <T> FindNodePair(Func <CircularLinkedListNode <T>, CircularLinkedListNode <T>, bool> predicate) { uint startVersion = version; CircularLinkedListNode <T> node = this.First; if (node != null) { do { if (node.Next != null) { if (predicate(node, node.Next)) { return(node); } } if (version != startVersion) { throw new InvalidOperationException("list modified"); } node = node.Next; }while (node != null && node != this.Last.Next); } return(null); }
/// <summary> /// Removes nodes from the arguments list and inserts them at the end of the target list. /// </summary> /// <param name="srcFirst">The first node in the source list.</param> /// <param name="srcLast">The last node in the source list.</param> public void SpliceLast(CircularLinkedListNode <T> srcFirst, CircularLinkedListNode <T> srcLast) { if (srcFirst == null) { throw new ArgumentNullException("srcFirst"); } if (srcLast == null) { throw new ArgumentNullException("srcLast"); } if (srcFirst.List != srcLast.List) { throw new InvalidOperationException("source nodes not in same list"); } CircularLinkedList <T> srcList = srcFirst.List; CircularLinkedListNode <T> terminator = srcLast.Next; CircularLinkedListNode <T> node = srcFirst; do { CircularLinkedListNode <T> nextNode = node.Next; srcList.Remove(node); this.AddLast(node); node = nextNode; }while (node != terminator); }
public void CopyTo(T[] array, int index) { if (array == null) { throw new ArgumentNullException("array"); } if ((uint)index < (uint)array.GetLowerBound(0)) { throw new ArgumentOutOfRangeException("index"); } if (array.Rank != 1) { throw new ArgumentException("Array is multidimensional", "array"); } if (array.Length - index + array.GetLowerBound(0) < count) { throw new ArgumentException("number of items exceeds capacity"); } CircularLinkedListNode <T> node = first; if (first == null) { return; } do { array[index] = node.Value; index++; node = node.forward; }while (node != first); }
void IDeserializationCallback.OnDeserialization(object sender) { if (si == null) { return; } if (list.si != null) { ((IDeserializationCallback)list).OnDeserialization(this); } si = null; if (version == list.version && index != -1) { CircularLinkedListNode <T> node = list.First; for (int i = 0; i < index; i++) { node = node.forward; } current = node; } }
public bool MoveNext() { if (list == null) { throw new ObjectDisposedException(null); } if (version != list.version) { throw new InvalidOperationException("list modified"); } if (current == null) { current = list.first; } else { current = current.forward; if (current == list.first) { current = null; } } if (current == null) { index = -1; return(false); } ++index; return(true); }
public void AddBeforeAndAfterTest() { CircularLinkedListNode <int> node = threeList.Find(3); threeList.AddAfter(node, new CircularLinkedListNode <int>(5)); CircularLinkedListNode <int> sixNode = threeList.AddAfter(node, 6); CircularLinkedListNode <int> sevenNode = threeList.AddBefore(node, 7); threeList.AddBefore(node, new CircularLinkedListNode <int>(8)); Assert.AreEqual(6, sixNode.Value); Assert.AreEqual(7, sevenNode.Value); // 2 7 8 3 6 5 4 int[] values = new int[] { 2, 7, 8, 3, 6, 5, 4 }; int i = 0; foreach (int current in threeList) { Assert.AreEqual(values[i], current); i++; } CircularLinkedListNode <int> node2 = threeList.First; do { Assert.AreSame(threeList, node2.List); node2 = node2.Next; }while (node2 != threeList.First); }
public void BecomeCircularTest() { threeList.IsCircular = true; CircularLinkedListNode <int> node = threeList.First; Assert.AreEqual(2, node.Value); CircularLinkedListNode <int> previous = node.Previous; Assert.AreEqual(4, previous.Value); node = node.Next; Assert.IsNotNull(node); Assert.AreEqual(3, node.Value); node = node.Next; Assert.IsNotNull(node); Assert.AreEqual(4, node.Value); Assert.AreSame(previous, node); node = node.Next; Assert.IsNotNull(node); Assert.AreEqual(2, node.Value); Assert.AreSame(node, threeList.First); }
public void RemoveTest() { Assert.IsTrue(threeList.Remove(3)); Assert.AreEqual(2, threeList.Count); int[] values = { 2, 4 }; int i = 0; foreach (int current in threeList) { Assert.AreEqual(values[i], current); i++; } Assert.IsFalse(threeList.Remove(5)); CircularLinkedListNode <string> node = stringList.Find("baz"); stringList.Remove(node); Assert.IsNull(node.List); Assert.IsNull(node.Previous); Assert.IsNull(node.Next); string[] values2 = { "foo", "bar" }; i = 0; foreach (string current in stringList) { Assert.AreEqual(values2[i], current); i++; } }
internal void Detach() { back.forward = forward; forward.back = back; forward = back = null; container = null; }
public void AddAfter(CircularLinkedListNode <T> node, CircularLinkedListNode <T> newNode) { VerifyReferencedNode(node); VerifyBlankNode(newNode); newNode.InsertBetween(node, node.forward, this); count++; version++; }
internal void InsertBetween(CircularLinkedListNode <T> previousNode, CircularLinkedListNode <T> nextNode, CircularLinkedList <T> list) { previousNode.forward = this; nextNode.back = this; this.forward = nextNode; this.back = previousNode; this.container = list; }
internal Enumerator(SerializationInfo info, StreamingContext context) { si = info; list = (CircularLinkedList <T>)si.GetValue(ListKey, typeof(CircularLinkedList <T>)); index = si.GetInt32(IndexKey); version = si.GetUInt32(VersionKey); current = null; }
public CircularLinkedListNode <T> AddAfter(CircularLinkedListNode <T> node, T value) { VerifyReferencedNode(node); CircularLinkedListNode <T> newNode = new CircularLinkedListNode <T>(this, value, node, node.forward); count++; version++; return(newNode); }
internal CircularLinkedListNode(CircularLinkedList <T> list, T value, CircularLinkedListNode <T> previousNode, CircularLinkedListNode <T> nextNode) { container = list; item = value; this.back = previousNode; this.forward = nextNode; previousNode.forward = this; nextNode.back = this; }
public void FindPredicateNodePairNegativeTest() { CircularLinkedListNode <int> pairNode = threeList.FindNodePair(delegate(CircularLinkedListNode <int> a, CircularLinkedListNode <int> b) { return(a.Value == 3 && b.Value == 2); }); Assert.AreEqual(null, pairNode); }
public void FindPredicateNegativeTest() { CircularLinkedListNode <int> found = threeList.Find(delegate(int a) { return(a == 5); }); Assert.AreEqual(null, found); }
public void FindPredicatePairNegativeTest() { CircularLinkedListNode <int> pairNode = threeList.FindPair(delegate(int a, int b) { return(a == 3 && b == 2); }); Assert.AreEqual(null, pairNode); }
public void FindPredicatePairPositiveTest() { CircularLinkedListNode <int> pairNode = threeList.FindPair(delegate(int a, int b) { return(a == 3 && b == 4); }); Assert.AreEqual(threeList.Last, pairNode.Next); }
public void FindPredicatePositiveTest() { CircularLinkedListNode <int> found = threeList.Find(delegate(int a) { return(a == 4); }); Assert.AreEqual(threeList.Last, found); }
public void FindPredicateNodePairPositiveTest() { CircularLinkedListNode <int> pairNode = threeList.FindNodePair(delegate(CircularLinkedListNode <int> a, CircularLinkedListNode <int> b) { return(a.Value == 3 && b.Value == 4); }); Assert.AreEqual(threeList.Last, pairNode.Next); }
public void Dispose() { if (list == null) { throw new ObjectDisposedException(null); } current = null; list = null; }
internal Enumerator(CircularLinkedList <T> parent) { #if !NET_2_1 si = null; #endif this.list = parent; current = null; index = -1; version = parent.version; }
public bool Remove(T value) { CircularLinkedListNode <T> node = Find(value); if (node == null) { return(false); } Remove(node); return(true); }
static void VerifyBlankNode(CircularLinkedListNode <T> newNode) { if (newNode == null) { throw new ArgumentNullException("newNode"); } if (newNode.List != null) { throw new InvalidOperationException(); } }
void VerifyReferencedNode(CircularLinkedListNode <T> node) { if (node == null) { throw new ArgumentNullException("node"); } if (node.List != this) { throw new InvalidOperationException(); } }
public void AddBefore(CircularLinkedListNode <T> node, CircularLinkedListNode <T> newNode) { VerifyReferencedNode(node); VerifyBlankNode(newNode); newNode.InsertBetween(node.back, node, this); count++; version++; if (node == first) { first = newNode; } }
public CircularLinkedListNode <T> AddBefore(CircularLinkedListNode <T> node, T value) { VerifyReferencedNode(node); CircularLinkedListNode <T> newNode = new CircularLinkedListNode <T>(this, value, node.back, node); count++; version++; if (node == first) { first = newNode; } return(newNode); }
void IEnumerator.Reset() { if (list == null) { throw new ObjectDisposedException(null); } if (version != list.version) { throw new InvalidOperationException("list modified"); } current = null; index = -1; }
public void AddLast(CircularLinkedListNode <T> node) { VerifyBlankNode(node); if (first == null) { node.SelfReference(this); first = node; } else { node.InsertBetween(first.back, first, this); } count++; version++; }