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); }
public void Remove(T value) { LinkedListEntry <T> entry = this.Find(value); if (entry != null) { this.Remove(entry); } }
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); }
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); }
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); }
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); }
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); }
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); }
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(); }
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); }
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(); }
public void Clear() { _head = null; _tail = null; _count = 0; }