// Adds this element to the list, with replacing the specified element. // This is equivalent to calling the sequence: LinkBefore(Replace); replace.Unlink(); public void LinkReplace(DoubleLinkBaseAdv <T> link, DoubleLinkBaseAdv <T> replace) { Debug.Assert(link != null); Debug.Assert(replace != null); Debug.Assert(replace.List == this); if (link.IsLinked) { link.Unlink(); } link.Previous = replace.Previous; link.Next = replace.Next; if (link.Previous != null) { link.Previous.Next = link; } if (link.Next != null) { link.Next.Previous = link; } replace.Next = null; replace.Previous = null; }
// Adds this element to a list, before the given element. public void LinkBefore(DoubleLinkBaseAdv <T> link, DoubleLinkBaseAdv <T> before) { Debug.Assert(link != null); Debug.Assert(before != null); Debug.Assert(before.List == this); if (link.IsLinked) { link.Unlink(); } link.List = this; link.Previous = before.Previous; before.Previous = link; link.Next = before; if (link.Previous != null) { link.Previous.Next = link; } count++; }
// Adds this element to the list, after the specified element public void LinkAfter(DoubleLinkBaseAdv <T> link, DoubleLinkBaseAdv <T> after) { Debug.Assert(link != null); Debug.Assert(after != null); Debug.Assert(after.List == this); if (link.IsLinked) { link.Unlink(); } link.List = this; link.Next = after.Next; after.Next = link; link.Previous = after; if (link.Next != null) { link.Next.Previous = link; } count++; }
// Remove link from list public void Unlink(DoubleLinkBaseAdv <T> link) { Debug.Assert(link != null); Debug.Assert(link.List != this); if (link.IsLinked) { link.Unlink(); } link.List = this; if (link.Next != null) { link.Next.Previous = link.Previous; } if (link.Previous != null) { link.Previous.Next = link.Next; } link.Next = link.Previous = null; link.List = null; count--; }