Exemplo n.º 1
0
        private void Callback(IntPtr param, bool timerOrWaitFired)
        {
            int id = param.ToInt32();

            // This could be faster...
            Timer timer = null;
            LinkedListEntry <Timer> e = _timers.HeadEntry;

            while (e != null)
            {
                if (e.Value.ID == id)
                {
                    timer = e.Value;
                    if (timer.Mode == TimerMode.OneShot)
                    {
                        lock (_syncRoot)
                            _timers.Remove(e);
                        timer.Dispose();
                    }
                    break;
                }
                e = e.Next;
                _searchCount++;
            }
            //Debug.Assert( timer != null );
            if (timer == null)
            {
                return;
            }

            timer.Callback(timer);
        }
Exemplo n.º 2
0
        public void Remove(T value)
        {
            LinkedListEntry <T> entry = this.Find(value);

            if (entry != null)
            {
                this.Remove(entry);
            }
        }
Exemplo n.º 3
0
        public LinkedListEntry <T> Find(T value)
        {
            LinkedListEntry <T> entry = _head;

            while (entry != null)
            {
                if (entry.Value.Equals(value))
                {
                    return(entry);
                }
                entry = entry.Next;
            }
            return(null);
        }
Exemplo n.º 4
0
        public LinkedListEntry <T> Enqueue(T value)
        {
            LinkedListEntry <T> entry = new LinkedListEntry <T>();

            entry.Value = value;
            if (_tail != null)
            {
                _tail.Next = entry;
            }
            entry.Previous = _tail;
            _tail          = entry;
            if (_head == null)
            {
                _head = entry;
            }
            _count++;
            this.AssertCount();
            return(entry);
        }
Exemplo n.º 5
0
        public LinkedListEntry <T> InsertAtHead(T value)
        {
            LinkedListEntry <T> entry = new LinkedListEntry <T>();

            entry.Value = value;
            entry.Next  = _head;
            if (_head != null)
            {
                _head.Previous = entry;
            }
            _head = entry;
            if (_tail == null)
            {
                _tail = entry;
            }
            _count++;
            this.AssertCount();
            return(entry);
        }
Exemplo n.º 6
0
        private void AssertCount()
        {
            int headCount         = 0;
            int tailCount         = 0;
            LinkedListEntry <T> e = _head;

            while (e != null)
            {
                headCount++;
                e = e.Next;
            }
            e = _tail;
            while (e != null)
            {
                tailCount++;
                e = e.Previous;
            }
            Debug.Assert(headCount == tailCount);
            Debug.Assert(headCount == _count);
        }
Exemplo n.º 7
0
        public LinkedListEntry <T> InsertAfter(T value, LinkedListEntry <T> preceeding)
        {
            LinkedListEntry <T> entry = new LinkedListEntry <T>();

            entry.Value = value;
            if (preceeding.Next != null)
            {
                preceeding.Next.Previous = entry;
            }
            entry.Next      = preceeding.Next;
            entry.Previous  = preceeding;
            preceeding.Next = entry;
            if (entry.Next == null)
            {
                _tail = entry;
            }
            _count++;
            this.AssertCount();
            return(entry);
        }
Exemplo n.º 8
0
        public LinkedListEntry <T> InsertBefore(T value, LinkedListEntry <T> proceeding)
        {
            LinkedListEntry <T> entry = new LinkedListEntry <T>();

            entry.Value = value;
            if (proceeding.Previous != null)
            {
                proceeding.Previous.Next = entry;
            }
            entry.Next          = proceeding;
            entry.Previous      = proceeding.Previous;
            proceeding.Previous = entry;
            if (entry.Previous == null)
            {
                _head = entry;
            }
            _count++;
            this.AssertCount();
            return(entry);
        }
Exemplo n.º 9
0
 public void Remove(LinkedListEntry <T> entry)
 {
     if (entry.Previous == null)
     {
         _head = entry.Next;
     }
     else
     {
         entry.Previous.Next = entry.Next;
     }
     if (entry.Next == null)
     {
         _tail = entry.Previous;
     }
     else
     {
         entry.Next.Previous = entry.Previous;
     }
     _count--;
     this.AssertCount();
 }
Exemplo n.º 10
0
        public T Dequeue()
        {
            LinkedListEntry <T> entry = _head;

            if (entry == null)
            {
                return(default(T));
            }
            _head = entry.Next;
            if (entry.Next != null)
            {
                entry.Next.Previous = null;
            }
            else
            {
                _tail = null;
            }
            _count--;
            this.AssertCount();
            return(entry.Value);
        }
Exemplo n.º 11
0
 public void MoveToHead(LinkedListEntry <T> entry)
 {
     if (entry == _head)
     {
         return;
     }
     this.Remove(entry);
     entry.Next     = _head;
     entry.Previous = null;
     if (_head != null)
     {
         _head.Previous = entry;
     }
     _head = entry;
     if (_tail == null)
     {
         _tail = entry;
     }
     _count++;
     this.AssertCount();
 }
Exemplo n.º 12
0
 public void Clear()
 {
     _head  = null;
     _tail  = null;
     _count = 0;
 }