diff options
| author | Tyge Løvset <[email protected]> | 2020-08-30 00:37:49 +0200 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2020-08-30 00:37:49 +0200 |
| commit | e6b2a7930bf360133fd0f78908dc3726f64c8ea7 (patch) | |
| tree | c82602d750396a0d71103a43e1c0e6b2b44cba9d | |
| parent | c15b39eed1f7041b1fb84a72da4e4e0fae1318a8 (diff) | |
| download | STC-modified-e6b2a7930bf360133fd0f78908dc3726f64c8ea7.tar.gz STC-modified-e6b2a7930bf360133fd0f78908dc3726f64c8ea7.zip | |
Minors.
| -rw-r--r-- | examples/priority.c | 15 | ||||
| -rw-r--r-- | stc/cdefs.h | 9 | ||||
| -rw-r--r-- | stc/cstr.h | 10 |
3 files changed, 15 insertions, 19 deletions
diff --git a/examples/priority.c b/examples/priority.c index 598f448a..7dfff7da 100644 --- a/examples/priority.c +++ b/examples/priority.c @@ -9,24 +9,25 @@ declare_cvec(i, int64_t); declare_cvec_pqueue(i, >); // min-heap (increasing values)
int main() {
- crand_rng32_t pcg = crand_rng32_init(time(NULL));
- crand_uniform_i32_t dist = crand_uniform_i32_init(pcg, 0, 100000000);
+ size_t N = 100000000;
+ crand_rng64_t pcg = crand_rng64_init(time(NULL));
+ crand_uniform_i64_t dist = crand_uniform_i64_init(pcg, 0, N * 10);
cvec_i heap = cvec_init;
// Push ten million random numbers to priority queue
- for (int i=0; i<10000000; ++i)
- cvec_i_pqueue_push(&heap, crand_uniform_i32(&dist));
+ for (int i=0; i<N; ++i)
+ cvec_i_pqueue_push(&heap, crand_uniform_i64(&dist));
// push some negative numbers too.
c_push(&heap, cvec_i_pqueue, c_items(-231, -32, -873, -4, -343));
- for (int i=0; i<10000000; ++i)
- cvec_i_pqueue_push(&heap, crand_uniform_i32(&dist));
+ for (int i=0; i<N; ++i)
+ cvec_i_pqueue_push(&heap, crand_uniform_i64(&dist));
// Extract the hundred smallest.
for (int i=0; i<100; ++i) {
- printf("%d ", cvec_i_pqueue_top(&heap));
+ printf("%zd ", cvec_i_pqueue_top(&heap));
cvec_i_pqueue_pop(&heap);
}
cvec_i_destroy(&heap);
diff --git a/stc/cdefs.h b/stc/cdefs.h index c8b961a4..73f3e9d3 100644 --- a/stc/cdefs.h +++ b/stc/cdefs.h @@ -61,11 +61,6 @@ #define c_max_alloca (512)
#define c_swap(T, x, y) do { T __t = x; x = y; y = __t; } while (0)
-#ifdef __cplusplus
-#define c_NULL nullptr
-#else
-#define c_NULL NULL
-#endif
#define c_default_from_raw(x) (x)
#define c_default_to_raw(ptr) (*(ptr))
@@ -79,9 +74,9 @@ #define c_foreach(it, prefix, container) \
for (prefix##_iter_t it = prefix##_begin(&container); it.item != it.end; prefix##_next(&it))
-#define c_items(...) {__VA_ARGS__}
+#define c_items(...) __VA_ARGS__
#define c_push(container, prefix, items) do { \
- const prefix##_input_t __arr[] = items; \
+ const prefix##_input_t __arr[] = { items }; \
prefix##_push_n(container, __arr, sizeof(__arr)/sizeof(prefix##_input_t)); \
} while (0)
@@ -185,9 +185,9 @@ cstr_find(const cstr_t* s, const char* needle) { /* cvec/cmap API functions: */
-#define cstr_to_raw(x) ((x)->str)
-#define cstr_compare_raw(x, y) strcmp(*(x), *(y))
-#define cstr_equals_raw(x, y) (strcmp(*(x), *(y)) == 0)
+#define cstr_to_raw(x) ((x)->str)
+#define cstr_compare_raw(x, y) strcmp(*(x), *(y))
+#define cstr_equals_raw(x, y) (strcmp(*(x), *(y)) == 0)
STC_INLINE uint32_t c_string_hash(const char* str) {
uint32_t hash = 5381, c; /* djb2 */
@@ -195,8 +195,8 @@ STC_INLINE uint32_t c_string_hash(const char* str) { return hash;
}
-STC_INLINE uint32_t cstr_hash_raw(const char* const* chr_pp, size_t ignored) {
- return c_string_hash(*chr_pp);
+STC_INLINE uint32_t cstr_hash_raw(const char* const* spp, size_t ignored) {
+ return c_string_hash(*spp);
}
/* -------------------------- IMPLEMENTATION ------------------------- */
|
