コード例 #1
0
 public DoubleLinkedElement(T elem, int hashCode)
     : base(elem, hashCode)
 {
     // references to elements within all-element linked list
     this.before = null;
     this.after  = null;
 }
コード例 #2
0
 /// <param name="initCapacity">Recommended size of the internal array.</param>
 /// <param name="maxLoadFactor">used to determine when to expand the internal array</param>
 /// <param name="minLoadFactor">used to determine when to shrink the internal array</param>
 public LightWeightLinkedSet(int initCapacity, float maxLoadFactor, float minLoadFactor
                             )
     : base(initCapacity, maxLoadFactor, minLoadFactor)
 {
     head = null;
     tail = null;
 }
コード例 #3
0
 /// <summary>Remove the element corresponding to the key, given key.hashCode() == index.
 ///     </summary>
 /// <returns>Return the entry with the element if exists. Otherwise return null.</returns>
 protected internal override LightWeightHashSet.LinkedElement <T> RemoveElem(T key)
 {
     LightWeightLinkedSet.DoubleLinkedElement <T> found = (LightWeightLinkedSet.DoubleLinkedElement
                                                           <T>)(base.RemoveElem(key));
     if (found == null)
     {
         return(null);
     }
     // update linked list
     if (found.after != null)
     {
         found.after.before = found.before;
     }
     if (found.before != null)
     {
         found.before.after = found.after;
     }
     if (head == found)
     {
         head = head.after;
     }
     if (tail == found)
     {
         tail = tail.before;
     }
     return(found);
 }
コード例 #4
0
        /// <summary>Remove all elements from the set and return them in order.</summary>
        /// <remarks>
        /// Remove all elements from the set and return them in order. Traverse the
        /// link list, don't worry about hashtable - faster version of the parent
        /// method.
        /// </remarks>
        public override IList <T> PollAll()
        {
            IList <T> retList = new AList <T>(size);

            while (head != null)
            {
                retList.AddItem(head.element);
                head = head.after;
            }
            this.Clear();
            return(retList);
        }
コード例 #5
0
            public override T Next()
            {
                if (this._enclosing.modification != this.startModification)
                {
                    throw new ConcurrentModificationException("modification=" + this._enclosing.modification
                                                              + " != startModification = " + this.startModification);
                }
                if (this.next == null)
                {
                    throw new NoSuchElementException();
                }
                T e = this.next.element;

                // find the next element
                this.next = this.next.after;
                return(e);
            }
コード例 #6
0
        public override U[] ToArray <U>(U[] a)
        {
            if (a == null)
            {
                throw new ArgumentNullException("Input array can not be null");
            }
            if (a.Length < size)
            {
                a = (U[])System.Array.CreateInstance(a.GetType().GetElementType(), size);
            }
            int currentIndex = 0;

            LightWeightLinkedSet.DoubleLinkedElement <T> current = head;
            while (current != null)
            {
                T curr = current.element;
                a[currentIndex++] = (U)curr;
                current           = current.after;
            }
            return(a);
        }
コード例 #7
0
        /// <summary>Add given element to the hash table</summary>
        /// <returns>true if the element was not present in the table, false otherwise</returns>
        protected internal override bool AddElem(T element)
        {
            // validate element
            if (element == null)
            {
                throw new ArgumentException("Null element is not supported.");
            }
            // find hashCode & index
            int hashCode = element.GetHashCode();
            int index    = GetIndex(hashCode);

            // return false if already present
            if (GetContainedElem(index, element, hashCode) != null)
            {
                return(false);
            }
            modification++;
            size++;
            // update bucket linked list
            LightWeightLinkedSet.DoubleLinkedElement <T> le = new LightWeightLinkedSet.DoubleLinkedElement
                                                              <T>(element, hashCode);
            le.next        = entries[index];
            entries[index] = le;
            // insert to the end of the all-element linked list
            le.after  = null;
            le.before = tail;
            if (tail != null)
            {
                tail.after = le;
            }
            tail = le;
            if (head == null)
            {
                head = le;
            }
            return(true);
        }
コード例 #8
0
 /// <summary>Clear the set.</summary>
 /// <remarks>Clear the set. Resize it to the original capacity.</remarks>
 public override void Clear()
 {
     base.Clear();
     this.head = null;
     this.tail = null;
 }