diff options
| author | Tyge Løvset <[email protected]> | 2020-12-17 13:13:11 +0100 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2020-12-17 13:13:11 +0100 |
| commit | 512086cdf69bbfadd794fb5e751fb681222a4adf (patch) | |
| tree | ea3b87efda66382c2728990618ca3a6ae30bc3af /docs/cpqueue_api.md | |
| parent | 83a259d155742f669b972649ff8c9607c8abe081 (diff) | |
| download | STC-modified-512086cdf69bbfadd794fb5e751fb681222a4adf.tar.gz STC-modified-512086cdf69bbfadd794fb5e751fb681222a4adf.zip | |
Renamed cpqueue (priority queue) container to cpque.
Diffstat (limited to 'docs/cpqueue_api.md')
| -rw-r--r-- | docs/cpqueue_api.md | 86 |
1 files changed, 0 insertions, 86 deletions
diff --git a/docs/cpqueue_api.md b/docs/cpqueue_api.md deleted file mode 100644 index d0fa61cb..00000000 --- a/docs/cpqueue_api.md +++ /dev/null @@ -1,86 +0,0 @@ -# Container [cpqueue](../stc/cpqueue.h): Priority Queue - -This describes the API of the queue type **cpqueue**. Implemented as a heap. - -## Declaration - -```c -#define using_cpqueue(X, ctype, heap_variant) -``` -The macro `using_cpqueue()` must be instantiated in the global scope. -**cpqueue** uses normally a **cvec** type as underlying implementation, specified as `ctype`. -The `heap_variant` must be given as `<` or `>`, specifying *max-heap* or *min-heap* for the priority queue. -Note that the function `{ctype}_value_compare(x, y)` defined by the underlying vector type is used to -compare values (priorities). `X` is a type tag name and will affect the names of all cpqueue types and methods. -Declaring `using_cpqueue(my, cvec_my, >);`, `X` should be replaced by `my` in the following documentation. - -## Types - -| Type name | Type definition | Used to represent... | -|:-----------------------|:----------------------------------------|:--------------------------| -| `cpqueue_X` | `struct {cpqueue_X_value_t* data; ...}` | The cpqueue type | -| `cpqueue_X_value_t` | Depends on underlying container type | The cpqueue element type | -| `cpqueue_X_input_t` | " | cpqueue input type | -| `cpqueue_X_rawvalue_t` | " | cpqueue raw value type | - -## Header file - -All cpqueue definitions and prototypes may be included in your C source file by including a single header file. - -```c -#include "stc/cpqueue.h" -``` - -## Methods - -```c -cpqueue_X cpqueue_X_init(void); -cpqueue_X cpqueue_X_clone(cpqueue_X pq); -void cpqueue_X_make_heap(cpqueue_X* self); -void cpqueue_X_del(cpqueue_X* self); - -size_t cpqueue_X_size(cpqueue_X pq); -bool cpqueue_X_empty(cpqueue_X pq); -const -cpqueue_X_value_t* cpqueue_X_top(const cpqueue_X* self); - -void cpqueue_X_push_n(cpqueue_X *self, const cpqueue_X_input_t arr[], size_t size); -void cpqueue_X_emplace(cpqueue_X* self, cpqueue_X_rawvalue_t raw); -void cpqueue_X_push(cpqueue_X* self, cpqueue_X_value_t value); -void cpqueue_X_pop(cpqueue_X* self); -void cpqueue_X_erase_at(cpqueue_X* self, size_t idx); -``` - -## Example -```c -#include <stdio.h> -#include "stc/cpqueue.h" -#include "stc/crand.h" - -using_cvec(i, int64_t); -using_cpqueue(i, cvec_i, >); // adaptor type, '>' = min-heap - -int main() -{ - size_t N = 10000000; - crand_t rng = crand_init(1234); - crand_uniform_t dist = crand_uniform_init(0, N * 10); - - cpqueue_i heap = cpqueue_i_init(); - // Push ten million random numbers to priority queue, plus some negative ones. - c_forrange (N) - cpqueue_i_push(&heap, crand_uniform(&rng, &dist)); - c_push_items(&heap, cpqueue_i, {-231, -32, -873, -4, -343}); - - // Extract and display the fifty smallest. - c_forrange (50) { - printf("%zd ", *cpqueue_i_top(&heap)); - cpqueue_i_pop(&heap); - } - cpqueue_i_del(&heap); -} -``` -Output: -``` - -873 -343 -231 -32 -4 3 5 6 18 23 31 54 68 87 99 105 107 125 128 147 150 155 167 178 181 188 213 216 272 284 287 302 306 311 313 326 329 331 344 348 363 367 374 385 396 399 401 407 412 477 -```
\ No newline at end of file |
