/// <summary> /// Replace previous link /// </summary> /// <param name="newPrevious">New previous pair</param> /// <returns>Old previous pair</returns> public LinkedPair <KeyType, DataType> ReplacePrevious(LinkedPair <KeyType, DataType> newPrevious) { LinkedPair <KeyType, DataType> oldPrevious = previous; previous = newPrevious; return(oldPrevious); }
public LinkedPair(KeyType key, DataType data, LinkedPair <KeyType, DataType> previous, LinkedPair <KeyType, DataType> next) : this() { this.key = key; this.data = data; this.previous = previous; this.next = next; }
/// <summary> /// Replace next link /// </summary> /// <param name="newNext">New next pair</param> /// <returns>Old next pair</returns> public LinkedPair <KeyType, DataType> ReplaceNext(LinkedPair <KeyType, DataType> newNext) { LinkedPair <KeyType, DataType> oldNext = next; next = newNext; return(oldNext); }
/// <summary> /// Wrapper for <see cref="CompareTo(object)"/>. Same fail condition /// </summary> /// <param name="pair"></param> /// <returns></returns> public int CompareTo(LinkedPair <KeyType, DataType> pair) { if (!isDataComparable) { throw new NotSupportedException("Given data type is not comparable"); } return(((IComparable)GetData()).CompareTo(pair)); }
/// <summary> /// Searches for a <see cref="LinkedPair{KeyType, DataType}"/> with a specified key that is linked with this one /// </summary> /// <param name="key">Search key</param> /// <returns>Matched pair. Can be null</returns> public LinkedPair <KeyType, DataType> GetLinkedPairWithKeyInList(KeyType key) { LinkedPair <KeyType, DataType> pair = GetLinkedPairWithKeyInListForwardSearch(key); if (pair == null) { pair = GetLinkedPairWithKeyInListBackwardSearch(key); } return(pair); }
/// <summary> /// Search for a <see cref="LinkedPair{KeyType, DataType}"/> with a specified key that is linked with this one, only searching backwards in the list /// </summary> /// <param name="key">Search key</param> /// <returns>Matched pair. Can be null</returns> public LinkedPair <KeyType, DataType> GetLinkedPairWithKeyInListBackwardSearch(KeyType key) { if (this.key.Equals(key)) { return(this); } for (LinkedPair <KeyType, DataType> previous = this.GetPrevious(); previous != null; previous = previous.GetPrevious()) { if (previous.key.Equals(key)) { return(previous); } } return(null); }
/// <summary> /// Searches for a <see cref="LinkedPair{KeyType, DataType}"/> with a specified key that is linked with this one, only searching forwards in the list /// </summary> /// <param name="key">Search key</param> /// <returns>Mathed pair. Can be null</returns> public LinkedPair <KeyType, DataType> GetLinkedPairWithKeyInListForwardSearch(KeyType key) { if (this.key.Equals(key)) { return(this); } for (LinkedPair <KeyType, DataType> next = this.GetNext(); next != null; next = next.GetNext()) { if (next.key.Equals(key)) { return(next); } } return(null); }
/// <summary> /// Gets the first pair in the linked list /// </summary> /// <returns></returns> public LinkedPair <KeyType, DataType> GetFirstLinkedPairInList() { LinkedPair <KeyType, DataType> current = this; while (true) { LinkedPair <KeyType, DataType> previous = current.GetPrevious(); if (previous == null) { break; } else { current = previous; } } return(current); }
/// <summary> /// Gets the last pair in the linked list /// </summary> /// <returns></returns> public LinkedPair <KeyType, DataType> GetLastLinkedPairInLink() { LinkedPair <KeyType, DataType> current = this; while (true) { LinkedPair <KeyType, DataType> next = current.GetNext(); if (next == null) { break; } else { current = next; } } return(current); }
public LinkedPair(LinkedPair <KeyType, DataType> previous, KeyType key, DataType data) : this() { this.key = key; this.data = data; this.previous = previous; }
public LinkedPairEnumerator(LinkedPair <KeyType, DataType> pair) { firstPairInList = pair.GetFirstLinkedPairInList(); currentPairInList = firstPairInList; }
/// <summary> /// Replace previous link /// </summary> /// <param name="newPrevious">New previous pair</param> public void SetPrevious(LinkedPair <KeyType, DataType> newPrevious) { previous = newPrevious; }
/// <summary> /// Replace next link /// </summary> /// <param name="newNext">New next pair</param> public void SetNext(LinkedPair <KeyType, DataType> newNext) { next = newNext; }