diff options
| author | Tyge Løvset <[email protected]> | 2021-05-19 11:50:40 +0200 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2021-05-19 11:50:40 +0200 |
| commit | a9ad1ad0d4f4d6b8f702b2a14bc9a508829da9ff (patch) | |
| tree | 2b5eee8e0747a706c57133fab773d43358df4635 /docs/cpque_api.md | |
| parent | 353ed880f92403d29c32af8d36c4bb8b0cb9c821 (diff) | |
| download | STC-modified-a9ad1ad0d4f4d6b8f702b2a14bc9a508829da9ff.tar.gz STC-modified-a9ad1ad0d4f4d6b8f702b2a14bc9a508829da9ff.zip | |
More cleanups and refinements.
Diffstat (limited to 'docs/cpque_api.md')
| -rw-r--r-- | docs/cpque_api.md | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/docs/cpque_api.md b/docs/cpque_api.md index a5cd056e..6f7917f5 100644 --- a/docs/cpque_api.md +++ b/docs/cpque_api.md @@ -68,18 +68,20 @@ int main() stc64_t rng = stc64_init(1234); stc64_uniform_t dist = stc64_uniform_init(0, N * 10); - cpque_i heap = cpque_i_init(); - // Push ten million random numbers to priority queue, plus some negative ones. - c_forrange (N) - cpque_i_push(&heap, stc64_uniform(&rng, &dist)); - c_emplace(cpque_i, heap, {-231, -32, -873, -4, -343}); - - // Extract and display the fifty smallest. - c_forrange (50) { - printf("%zd ", *cpque_i_top(&heap)); - cpque_i_pop(&heap); + // Declare heap, with defered del() + c_with (cpque_i heap = cpque_i_init(), cpque_i_del(&heap)) + { + // Push ten million random numbers to priority queue, plus some negative ones. + c_forrange (N) + cpque_i_push(&heap, stc64_uniform(&rng, &dist)); + c_emplace(cpque_i, heap, {-231, -32, -873, -4, -343}); + + // Extract and display the fifty smallest. + c_forrange (50) { + printf("%zd ", *cpque_i_top(&heap)); + cpque_i_pop(&heap); + } } - cpque_i_del(&heap); } ``` Output: |
