19 using Lucene.Net.Support;
21 namespace Lucene.Net.Util
40 protected internal T[] heap;
45 public abstract bool LessThan(T a, T b);
84 protected internal virtual T SentinelObject
86 get {
return default(T); }
90 protected internal void Initialize(
int maxSize)
99 if (maxSize == Int32.MaxValue)
109 heapSize = Int32.MaxValue;
115 heapSize = maxSize + 1;
118 heap =
new T[heapSize];
119 this.maxSize = maxSize;
122 T sentinel = SentinelObject;
123 if (sentinel != null)
126 for (
int i = 2; i < heap.Length; i++)
128 heap[i] = SentinelObject;
141 public T Add(T element)
144 heap[size] = element;
158 public virtual T InsertWithOverflow(T element)
165 else if (size > 0 && !LessThan(element, heap[1]))
196 heap[1] = heap[size];
197 heap[size] =
default(T);
235 for (
int i = 0; i <= size; i++)
237 heap[i] =
default(T);
242 private void UpHeap()
247 while (j > 0 && LessThan(node, heap[j]))
256 private void DownHeap()
262 if (k <= size && LessThan(heap[k], heap[j]))
266 while (j <= size && LessThan(heap[j], node))
272 if (k <= size && LessThan(heap[k], heap[j]))