-
Notifications
You must be signed in to change notification settings - Fork 8
priority_queue
Defined in header <ctl/priority_queue.h>, CTL prefix pqu, derived from vector.
#undef POD
#define T int
#include <ctl/priority_queue.h>
pqu_int a = pqu_int_init ();
for (i=0; i<1000; i++)
pqu_int_push(&a, i);
for (i=0; i<20; i++)
pqu_int_pop(&a);
pqu_int_free(&a);
A priority queue is a container adaptor that provides constant time lookup of the largest (by default) element, at the expense of logarithmic insertion and extraction.
The function names are composed of the prefix pqu_, the user-defined type
T and the method name. E.g pqu_int
with #define T int
.
A user-provided Compare can be supplied to change the ordering, e.g. using greater would cause the smallest element to appear as the top().
Working with a priority_queue is similar to managing a heap in some random access container, with the benefit of not being able to accidentally invalidate the heap.
T
value type
A
being pqu_T
container type
I
being pqu_T_it
iterator type
There is no B
node type.
init (int T_compare(T*,T*))
constructs the priority_queue.
free (A* self)
destructs the priority_queue.
copy (A* self)
returns a copy of the container.
top (A* self)
access the first element
empty (A* self)
checks whether the container is empty
size (A* self)
returns the number of elements
max_size ()
returns the maximum possible number of elements
capacity (A* self)
returns the number of elements that can be held in currently allocated storage
push (A* self, T key)
inserts the element
emplace (A* self, T values...)
constructs elements in-place. (C++11, NYI)
pop (A* self)
removes the top element
swap (A* self, A* other)
swaps the contents