Ejemplo n.º 1
0
        public IEnumerator <T> GetEnumerator()
        {
            SkipListNode <T> current = _head.Next[0];

            while (current != null)
            {
                yield return(current.Value);

                current = current.Next[0];
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Removes the first node matching the specified item
        /// </summary>
        /// <param name="item">The item to be removed</param>
        /// <returns>True if found and removed, otherwise, returns false</returns>
        public bool Remove(T item)
        {
            SkipListNode <T> current = _head;

            bool removed = false;

            // Walk down each level in the list making big jumps
            for (int level = _levels - 1; level >= 0; level--)
            {
                while (current.Next[level] != null)
                {
                    if (current.Next[level].Value.CompareTo(item) == 0)
                    {
                        // We have a match, remove it
                        current.Next[level] = current.Next[level].Next[level];
                        removed             = true;

                        break;
                    }

                    // If we went too far, go down a level
                    if (current.Next[level].Value.CompareTo(item) > 0)
                    {
                        break;
                    }

                    current = current.Next[level];
                }
            }

            if (removed)
            {
                _count--;
            }

            return(removed);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Clears the list
 /// </summary>
 public void Clear()
 {
     _head  = new SkipListNode <T>(default(T), 32 + 1);
     _count = 0;
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Constructor
 /// </summary>
 public SkipList()
 {
     // Init the head
     _head = new SkipListNode <T>(default(T), 32 + 1);
 }