10#ifndef PBAT_COMMON_HEAP_H
11#define PBAT_COMMON_HEAP_H
13#include "pbat/HostDevice.h"
28template <
class T,
class Less = std::less<T>, auto kCapacity = 64>
37 PBAT_HOST_DEVICE
Heap(Less _less = Less{}) : heap{}, less(_less), size{0} {}
43 PBAT_HOST_DEVICE
void Push(T value)
45 assert(size < kCapacity);
47 std::push_heap(heap, heap + size, less);
54 PBAT_HOST_DEVICE T
Pop()
57 std::pop_heap(heap, heap + size--, less);
65 PBAT_HOST_DEVICE T
const&
Top()
const {
return heap[0]; }
71 PBAT_HOST_DEVICE
auto Size()
const {
return size; }
77 PBAT_HOST_DEVICE
bool IsEmpty()
const {
return size == 0; }
83 PBAT_HOST_DEVICE
bool IsFull()
const {
return size == kCapacity; }
PBAT_HOST_DEVICE auto Size() const
Get the size of the heap.
Definition Heap.h:71
PBAT_HOST_DEVICE bool IsEmpty() const
Check if the heap is empty.
Definition Heap.h:77
PBAT_HOST_DEVICE T const & Top() const
Get the top element of the heap.
Definition Heap.h:65
PBAT_HOST_DEVICE bool IsFull() const
Check if the heap is full.
Definition Heap.h:83
PBAT_HOST_DEVICE Heap(Less _less=Less{})
Construct a new Heap object.
Definition Heap.h:37
PBAT_HOST_DEVICE T Pop()
Pop the top element from the heap.
Definition Heap.h:54
PBAT_HOST_DEVICE void Push(T value)
Push an element to the heap.
Definition Heap.h:43
Common functionality.
Definition ArgSort.h:20