コード例 #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);
        }
コード例 #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;
 }
コード例 #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);
        }
コード例 #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));
 }
コード例 #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);
        }
コード例 #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);
        }
コード例 #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);
        }
コード例 #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);
        }
コード例 #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);
        }
コード例 #10
0
 public LinkedPair(LinkedPair <KeyType, DataType> previous, KeyType key, DataType data) : this()
 {
     this.key      = key;
     this.data     = data;
     this.previous = previous;
 }
コード例 #11
0
 public LinkedPairEnumerator(LinkedPair <KeyType, DataType> pair)
 {
     firstPairInList   = pair.GetFirstLinkedPairInList();
     currentPairInList = firstPairInList;
 }
コード例 #12
0
 /// <summary>
 /// Replace previous link
 /// </summary>
 /// <param name="newPrevious">New previous pair</param>
 public void SetPrevious(LinkedPair <KeyType, DataType> newPrevious)
 {
     previous = newPrevious;
 }
コード例 #13
0
 /// <summary>
 /// Replace next link
 /// </summary>
 /// <param name="newNext">New next pair</param>
 public void SetNext(LinkedPair <KeyType, DataType> newNext)
 {
     next = newNext;
 }