39 static inline int left (
int i) {
return i*2+1; }
40 static inline int right (
int i) {
return (i+1)*2; }
41 static inline int parent(
int i) {
return (i-1) >> 1; }
49 while (i != 0 &&
lt(x, heap[p])){
65 if (!
lt(heap[child], x))
break;
66 heap[i] = heap[child];
76 Heap(
const Comp& c) : lt(c) { }
80 bool inHeap (
int n)
const {
return n < indices.
size() && indices[n] >= 0; }
81 int operator[](
int index)
const { assert(index < heap.
size());
return heap[index]; }
104 indices[n] = heap.
size();
113 heap[0] = heap.
last();
114 indices[heap[0]] = 0;
124 for (
int i = 0; i < heap.
size(); i++)
125 indices[heap[i]] = -1;
128 for (
int i = 0; i < ns.
size(); i++){
132 for (
int i = heap.
size() / 2 - 1; i >= 0; i--)
138 for (
int i = 0; i < heap.
size(); i++)
139 indices[heap[i]] = -1;
void percolateDown(int i)
void clear(bool dealloc=false)
int operator[](int index) const
void build(vec< int > &ns)
const T & last(void) const
void clear(bool dealloc=false)