134 heap.push_back(value);
136 std::push_heap(heap.begin(), heap.end(), compareT);
157 std::pop_heap(heap.begin(), heap.end(), compareT);
166 template <
typename T>
179 std::vector<Interval> heap;
193 heap.resize(capacity/2 + capacity%2 + 1);
224 if (
size_ == capacity_) {
231 heap[1].left = value;
232 heap[1].right = value;
235 if (value<heap[1].left) {
236 heap[1].left = value;
239 heap[1].right = value;
250 min_heap = (value<heap[last_pos].left)?
true :
false;
254 min_heap = (value<heap[last_pos/2].left)?
true :
false;
258 size_t pos = last_pos;
260 while (pos>1 && value < heap[par].left) {
261 heap[pos].left = heap[par].left;
265 heap[pos].left = value;
269 heap[last_pos].right = heap[last_pos].left;
273 size_t pos = last_pos;
275 while (pos>1 && heap[par].right < value) {
276 heap[pos].right = heap[par].right;
280 heap[pos].right = value;
284 heap[last_pos].left = heap[last_pos].right;
301 value = heap[1].left;
303 T elem = heap[last_pos].left;
309 heap[last_pos].left = heap[last_pos].right;
312 if (
size_<2)
return true;
315 size_t child = crt*2;
317 while (child <= last_pos) {
318 if (child < last_pos && heap[child+1].left < heap[child].left) ++child;
320 if (!(heap[child].left<elem))
break;
322 heap[crt].left = heap[child].left;
323 if (heap[child].right<elem) {
330 heap[crt].left = elem;
346 value = heap[1].right;
348 T elem = heap[last_pos].right;
354 heap[last_pos].right = heap[last_pos].left;
357 if (
size_<2)
return true;
360 size_t child = crt*2;
362 while (child <= last_pos) {
363 if (child < last_pos && heap[child].right < heap[child+1].right) ++child;
365 if (!(elem < heap[child].right))
break;
367 heap[crt].right = heap[child].right;
368 if (elem<heap[child].left) {
375 heap[crt].right = elem;
385 value = heap[1].left;
395 value = heap[1].right;
401 template <
typename T>
407 BoundedHeap(
size_t capacity) : interval_heap_(capacity), capacity_(capacity)
417 return interval_heap_.
size();
426 return interval_heap_.
empty();
434 interval_heap_.
clear();
439 if (interval_heap_.
size()==capacity_) {
442 if (
max<value)
return;
445 interval_heap_.
insert(value);
450 return interval_heap_.
popMin(value);
BoundedHeap(size_t capacity)
void insert(const T &value)
void insert(const T &value)
void insert(const T &value)
IntervalHeap(int capacity)
__host__ __device__ float length(float2 v)
void swap(cloudViewer::core::SmallVectorImpl< T > &LHS, cloudViewer::core::SmallVectorImpl< T > &RHS)
Implement std::swap in terms of SmallVector swap.
bool operator()(const T &t_1, const T &t_2) const