diff options
| author | realtradam <[email protected]> | 2023-04-12 15:55:33 -0400 |
|---|---|---|
| committer | realtradam <[email protected]> | 2023-04-12 15:55:33 -0400 |
| commit | 0841165881871ee01b782129be681209aeed2423 (patch) | |
| tree | 8a76b61dcaab381b6b42305201ae8b6259f6b6c0 /docs/cpque_api.md | |
| parent | 554f3e8acf7855b5d6a90cc68cefb7445460b03c (diff) | |
| parent | 0516aa3ae823ed9a22b2c5f776948c8447c32c31 (diff) | |
| download | STC-modified-0841165881871ee01b782129be681209aeed2423.tar.gz STC-modified-0841165881871ee01b782129be681209aeed2423.zip | |
Merge branch 'master' into modified
Diffstat (limited to 'docs/cpque_api.md')
| -rw-r--r-- | docs/cpque_api.md | 43 |
1 files changed, 21 insertions, 22 deletions
diff --git a/docs/cpque_api.md b/docs/cpque_api.md index 991623d7..962ee162 100644 --- a/docs/cpque_api.md +++ b/docs/cpque_api.md @@ -18,7 +18,6 @@ See the c++ class [std::priority_queue](https://en.cppreference.com/w/cpp/contai #define i_valfrom // convertion func i_valraw => i_val #define i_valto // convertion func i_val* => i_valraw. -#define i_less_functor // takes self as first argument. See examples/functor.c for usage. #define i_tag // alternative typename: cpque_{i_tag}. i_tag defaults to i_val #include <stc/cpque.h> ``` @@ -61,7 +60,7 @@ i_val cpque_X_value_clone(i_val value); ## Example ```c -#include <stc/crandom.h> +#include <stc/crand.h> #include <stdio.h> #define i_val int64_t @@ -72,27 +71,27 @@ i_val cpque_X_value_clone(i_val value); int main() { intptr_t N = 10000000; - stc64_t rng = stc64_new(1234); - stc64_uniform_t dist = stc64_uniform_new(0, N * 10); - - // Declare heap, with defered drop() - c_auto (cpque_i, heap) - { - // Push ten million random numbers to priority queue. - c_forrange (N) - cpque_i_push(&heap, stc64_uniform(&rng, &dist)); - - // Add some negative ones. - int nums[] = {-231, -32, -873, -4, -343}; - c_forrange (i, c_ARRAYLEN(nums)) - cpque_i_push(&heap, nums[i]); - - // Extract and display the fifty smallest. - c_forrange (50) { - printf("%" PRId64 " ", *cpque_i_top(&heap)); - cpque_i_pop(&heap); - } + crand_t rng = crand_init(1234); + crand_unif_t dist = crand_unif_init(0, N * 10); + + // Define heap + cpque_i heap = {0}; + + // Push ten million random numbers to priority queue. + c_forrange (N) + cpque_i_push(&heap, crand_unif(&rng, &dist)); + + // Add some negative ones. + int nums[] = {-231, -32, -873, -4, -343}; + c_forrange (i, c_arraylen(nums)) + cpque_i_push(&heap, nums[i]); + + // Extract and display the fifty smallest. + c_forrange (50) { + printf("%" PRId64 " ", *cpque_i_top(&heap)); + cpque_i_pop(&heap); } + cpque_i_drop(&heap); } ``` Output: |
