/// <summary> /// Adds an element to the current set and returns a value to indicate if the element was successfully added. /// </summary> /// <returns> /// true if the element is added to the set; false if the element is already in the set. /// </returns> /// <param name="item">The element to add to the set.</param> public bool Add(T item) { if (_elements.ContainsKey(item)) { return(false); } var node = new LinkedHashNode <T>(item) { Previous = _last }; if (_first == null) { _first = node; } if (_last != null) { _last.Next = node; } _last = node; _elements.Add(item, node); return(true); }
/// <inheritdoc /> public bool MoveNext() { if (_node == null) { return(false); } _current = _node.Value; _node = _node.Next; return(true); }
/// <summary> /// Unlink a node from the linked list by updating the node pointers in /// its preceeding and subsequent node. Also update the _first and _last /// pointers if necessary. /// </summary> private void Unlink(LinkedHashNode <T> node) { if (node.Previous != null) { node.Previous.Next = node.Next; } if (node.Next != null) { node.Next.Previous = node.Previous; } if (ReferenceEquals(node, _first)) { _first = node.Next; } if (ReferenceEquals(node, _last)) { _last = node.Previous; } }
/// <summary> /// Removes all items from the <see cref="T:System.Collections.Generic.ICollection`1"/>. /// </summary> /// <exception cref="T:System.NotSupportedException">The <see cref="T:System.Collections.Generic.ICollection`1"/> is read-only. </exception> public void Clear() { _elements.Clear(); _first = null; _last = null; }
internal Enumerator(LinkedHashSet <T> set) { _current = default(T); _node = set._first; }