Esempio n. 1
0
        /// <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);
        }
Esempio n. 2
0
 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;
 }
Esempio n. 3
0
        /// <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);
        }
Esempio n. 4
0
 /// <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));
 }
Esempio n. 5
0
        /// <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);
        }
Esempio n. 6
0
        /// <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);
        }
Esempio n. 7
0
        /// <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);
        }
Esempio n. 8
0
        /// <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);
        }
Esempio n. 9
0
        /// <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);
        }
Esempio n. 10
0
 public LinkedPair(LinkedPair <KeyType, DataType> previous, KeyType key, DataType data) : this()
 {
     this.key      = key;
     this.data     = data;
     this.previous = previous;
 }
Esempio n. 11
0
 public LinkedPairEnumerator(LinkedPair <KeyType, DataType> pair)
 {
     firstPairInList   = pair.GetFirstLinkedPairInList();
     currentPairInList = firstPairInList;
 }
Esempio n. 12
0
 /// <summary>
 /// Replace previous link
 /// </summary>
 /// <param name="newPrevious">New previous pair</param>
 public void SetPrevious(LinkedPair <KeyType, DataType> newPrevious)
 {
     previous = newPrevious;
 }
Esempio n. 13
0
 /// <summary>
 /// Replace next link
 /// </summary>
 /// <param name="newNext">New next pair</param>
 public void SetNext(LinkedPair <KeyType, DataType> newNext)
 {
     next = newNext;
 }