Esempio n. 1
0
        public virtual bool Enqueue(V value)
        {
            if (store.ContainsKey(value))
            {
                return(false);
            }

            QEntry <V> entry = new QEntry <V>(value);

            store.Add(value, entry);

            if (head == null && tail == null)
            {
                head = entry;
            }
            else if (tail != null || head != null)
            {
                entry.Prev = tail;
                tail.Next  = entry;
            }

            tail = entry;

            return(true);
        }
Esempio n. 2
0
 public virtual void Dispose()
 {
     if (store != null)
     {
         store.Clear();
         store = null;
     }
     tail = head = null;
 }
Esempio n. 3
0
        public virtual bool Remove(V value)
        {
            QEntry <V> entry = null;

            store.TryGetValue(value, out entry);

            if (entry != null)
            {
                if (!store.Remove(value))
                {
                    return(false);
                }

                if (store.Count == 0)
                {
                    head = tail = null;
                    return(true);
                }

                if (entry.Prev == null)
                {
                    // if peek is being removed then set peek to next and remove this one
                    head = head.Next;
                    if (head != null)
                    {
                        head.Prev = null;
                    }
                }
                else
                {
                    entry.Prev.Next = entry.Next;

                    //if not last entry of store then connect next of entry with previous
                    if (entry.Next != null)
                    {
                        entry.Next.Prev = entry.Prev;
                    }
                    else
                    {
                        tail = entry.Prev;
                    }
                }

                return(true);
            }

            return(false);
        }