summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--benchmarks/shootout_hashmaps.cpp10
-rw-r--r--examples/make.sh2
-rw-r--r--include/stc/carc.h75
-rw-r--r--include/stc/cbox.h86
-rw-r--r--include/stc/template.h2
5 files changed, 75 insertions, 100 deletions
diff --git a/benchmarks/shootout_hashmaps.cpp b/benchmarks/shootout_hashmaps.cpp
index 5fea8c9a..62ba5979 100644
--- a/benchmarks/shootout_hashmaps.cpp
+++ b/benchmarks/shootout_hashmaps.cpp
@@ -144,7 +144,7 @@ size_t seed;
sum += ++ M##_EMPLACE(X, RAND(keybits), i); \
} \
difference = clock() - before; \
- printf(#M ": time: %5.02f, size: %" PRIuMAX ", buckets: %8zu, sum: %" PRIuMAX "\n", \
+ printf(#M ": time: %5.03f, size: %" PRIuMAX ", buckets: %8zu, sum: %" PRIuMAX "\n", \
(float) difference / CLOCKS_PER_SEC, (size_t) M##_SIZE(X), (size_t) M##_BUCKETS(X), sum); \
M##_DTOR(X); \
}
@@ -159,7 +159,7 @@ size_t seed;
for (size_t i = 0; i < n; ++i) \
erased += M##_ERASE(X, i); \
difference = clock() - before; \
- printf(#M ": time: %5.02f, size: %" PRIuMAX ", buckets: %8zu, erased %" PRIuMAX "\n", \
+ printf(#M ": time: %5.03f, size: %" PRIuMAX ", buckets: %8zu, erased %" PRIuMAX "\n", \
(float) difference / CLOCKS_PER_SEC, (size_t) M##_SIZE(X), (size_t) M##_BUCKETS(X), erased); \
M##_DTOR(X); \
}
@@ -177,7 +177,7 @@ size_t seed;
for (size_t i = 0; i < n; ++i) \
erased += M##_ERASE(X, RAND(keybits)); \
difference = clock() - before; \
- printf(#M ": time: %5.02f, size: %" PRIuMAX ", buckets: %8zu, erased %" PRIuMAX "\n", \
+ printf(#M ": time: %5.03f, size: %" PRIuMAX ", buckets: %8zu, erased %" PRIuMAX "\n", \
(float) difference / CLOCKS_PER_SEC, (size_t) M##_SIZE(X), (size_t) M##_BUCKETS(X), erased); \
M##_DTOR(X); \
}
@@ -195,7 +195,7 @@ size_t seed;
for (size_t k=0; k < x; k++) M##_FOR (X, it) \
sum += M##_ITEM(X, it); \
difference = clock() - before; \
- printf(#M ": time: %5.02f, size: %" PRIuMAX ", buckets: %8zu, repeats: %" PRIuMAX ", sum: %" PRIuMAX "\n", \
+ printf(#M ": time: %5.03f, size: %" PRIuMAX ", buckets: %8zu, repeats: %" PRIuMAX ", sum: %" PRIuMAX "\n", \
(float) difference / CLOCKS_PER_SEC, (size_t) M##_SIZE(X), (size_t) M##_BUCKETS(X), x, sum); \
M##_DTOR(X); \
}
@@ -217,7 +217,7 @@ size_t seed;
for (size_t i = 0; i < x; ++i) \
found += M##_FIND(X, RAND(keybits)); \
difference = clock() - before; \
- printf(#M ": time: %5.02f, size: %" PRIuMAX ", buckets: %8zu, lookups: %" PRIuMAX ", found: %" PRIuMAX "\n", \
+ printf(#M ": time: %5.03f, size: %" PRIuMAX ", buckets: %8zu, lookups: %" PRIuMAX ", found: %" PRIuMAX "\n", \
(float) difference / CLOCKS_PER_SEC, (size_t) M##_SIZE(X), (size_t) M##_BUCKETS(X), x*2, found); \
M##_DTOR(X); \
}
diff --git a/examples/make.sh b/examples/make.sh
index facdedc1..6652d85c 100644
--- a/examples/make.sh
+++ b/examples/make.sh
@@ -1,5 +1,5 @@
#!/bin/bash
-cc='gcc -s -O2 -Wall -std=c99 -pedantic'
+cc='gcc -s -O2 -Wall -std=c99 -pedantic -Wfatal-errors'
#cc='clang -s -O2 -Wall -std=c99 -pedantic'
#cc='clang -s -O2 -Wall -std=c99 -pedantic -DSTC_CSTR_V1 -DSTC_CSMAP_V1'
#cc='gcc -x c++ -s -O2 -Wall -std=c++20'
diff --git a/include/stc/carc.h b/include/stc/carc.h
index 245ba708..6c591d2c 100644
--- a/include/stc/carc.h
+++ b/include/stc/carc.h
@@ -90,44 +90,38 @@ _cx_deftypes(_c_carc_types, _cx_self, i_key);
#endif
_cx_carc_rep { long counter; i_key value; };
-STC_INLINE _cx_self
-_cx_memb(_init)(void) { return c_make(_cx_self){NULL, NULL}; }
+STC_INLINE _cx_self _cx_memb(_init)(void)
+ { return c_make(_cx_self){NULL, NULL}; }
-STC_INLINE long
-_cx_memb(_use_count)(_cx_self ptr) { return ptr.use_count ? *ptr.use_count : 0; }
+STC_INLINE long _cx_memb(_use_count)(_cx_self ptr)
+ { return ptr.use_count ? *ptr.use_count : 0; }
-STC_INLINE _cx_self
-_cx_memb(_from_ptr)(_cx_value* p) {
+STC_INLINE _cx_self _cx_memb(_from_ptr)(_cx_value* p) {
_cx_self ptr = {p};
- if (p) *(ptr.use_count = c_alloc(long)) = 1;
+ if (p)
+ *(ptr.use_count = c_alloc(long)) = 1;
return ptr;
}
-STC_INLINE _cx_self
-_cx_memb(_make)(_cx_value val) { // c++: std::make_shared<_cx_value>(val)
- _cx_self ptr; _cx_carc_rep *rep = c_alloc(_cx_carc_rep);
+// c++: std::make_shared<_cx_value>(val)
+STC_INLINE _cx_self _cx_memb(_make)(_cx_value val) {
+ _cx_self ptr;
+ _cx_carc_rep *rep = c_alloc(_cx_carc_rep);
*(ptr.use_count = &rep->counter) = 1;
*(ptr.get = &rep->value) = val;
return ptr;
}
-STC_INLINE _cx_raw _cx_memb(_toraw)(const _cx_self* self) {
- return i_keyto(self->get);
-}
-
-STC_INLINE _cx_value _cx_memb(_get)(const _cx_self* self) {
- return *self->get;
-}
+STC_INLINE _cx_raw _cx_memb(_toraw)(const _cx_self* self)
+ { return i_keyto(self->get); }
-STC_INLINE _cx_self
-_cx_memb(_move)(_cx_self* self) {
+STC_INLINE _cx_self _cx_memb(_move)(_cx_self* self) {
_cx_self ptr = *self;
self->get = NULL, self->use_count = NULL;
return ptr;
}
-STC_INLINE void
-_cx_memb(_drop)(_cx_self* self) {
+STC_INLINE void _cx_memb(_drop)(_cx_self* self) {
if (self->use_count && _i_atomic_dec_and_test(self->use_count)) {
i_keydrop(self->get);
if ((char *)self->get != (char *)self->use_count + offsetof(_cx_carc_rep, value))
@@ -136,47 +130,42 @@ _cx_memb(_drop)(_cx_self* self) {
}
}
-STC_INLINE void
-_cx_memb(_reset)(_cx_self* self) {
+STC_INLINE void _cx_memb(_reset)(_cx_self* self) {
_cx_memb(_drop)(self);
self->use_count = NULL, self->get = NULL;
}
-STC_INLINE void
-_cx_memb(_reset_to)(_cx_self* self, _cx_value* p) {
+STC_INLINE void _cx_memb(_reset_to)(_cx_self* self, _cx_value* p) {
_cx_memb(_drop)(self);
*self = _cx_memb(_from_ptr)(p);
}
#if !defined _i_no_clone && !defined _i_no_emplace
- STC_INLINE _cx_self
- _cx_memb(_from)(_cx_raw raw) {
- return _cx_memb(_make)(i_keyfrom(raw));
- }
+ STC_INLINE _cx_self _cx_memb(_from)(_cx_raw raw)
+ { return _cx_memb(_make)(i_keyfrom(raw)); }
#endif // !_i_no_clone
// does not use i_keyclone, so OK to always define.
-STC_INLINE _cx_self
-_cx_memb(_clone)(_cx_self ptr) {
- if (ptr.use_count) _i_atomic_inc(ptr.use_count);
+STC_INLINE _cx_self _cx_memb(_clone)(_cx_self ptr) {
+ if (ptr.use_count)
+ _i_atomic_inc(ptr.use_count);
return ptr;
}
-STC_INLINE void
-_cx_memb(_copy)(_cx_self* self, _cx_self ptr) {
- if (ptr.use_count) _i_atomic_inc(ptr.use_count);
+STC_INLINE void _cx_memb(_copy)(_cx_self* self, _cx_self ptr) {
+ if (ptr.use_count)
+ _i_atomic_inc(ptr.use_count);
_cx_memb(_drop)(self);
*self = ptr;
}
-STC_INLINE void
-_cx_memb(_take)(_cx_self* self, _cx_self ptr) {
- if (self->get != ptr.get) _cx_memb(_drop)(self);
+STC_INLINE void _cx_memb(_take)(_cx_self* self, _cx_self ptr) {
+ if (self->get != ptr.get)
+ _cx_memb(_drop)(self);
*self = ptr;
}
-STC_INLINE uint64_t
-_cx_memb(_value_hash)(const _cx_value* x) {
+STC_INLINE uint64_t _cx_memb(_value_hash)(const _cx_value* x) {
#if c_option(c_no_cmp)
return c_default_hash(&x);
#else
@@ -185,8 +174,7 @@ _cx_memb(_value_hash)(const _cx_value* x) {
#endif
}
-STC_INLINE int
-_cx_memb(_value_cmp)(const _cx_value* x, const _cx_value* y) {
+STC_INLINE int _cx_memb(_value_cmp)(const _cx_value* x, const _cx_value* y) {
#if c_option(c_no_cmp)
return c_default_cmp(&x, &y);
#else
@@ -195,8 +183,7 @@ _cx_memb(_value_cmp)(const _cx_value* x, const _cx_value* y) {
#endif
}
-STC_INLINE bool
-_cx_memb(_value_eq)(const _cx_value* x, const _cx_value* y) {
+STC_INLINE bool _cx_memb(_value_eq)(const _cx_value* x, const _cx_value* y) {
#if c_option(c_no_cmp)
return x == y;
#else
diff --git a/include/stc/cbox.h b/include/stc/cbox.h
index b4b583fa..cb5cada3 100644
--- a/include/stc/cbox.h
+++ b/include/stc/cbox.h
@@ -79,86 +79,78 @@ _cx_deftypes(_c_cbox_types, _cx_self, i_key);
#endif
// constructors (takes ownsership)
-STC_INLINE _cx_self
-_cx_memb(_init)(void) { return c_make(_cx_self){NULL}; }
+STC_INLINE _cx_self _cx_memb(_init)(void)
+ { return c_make(_cx_self){NULL}; }
-STC_INLINE long
-_cx_memb(_use_count)(_cx_self box) { return (long)(box.get != NULL); }
+STC_INLINE long _cx_memb(_use_count)(_cx_self box)
+ { return (long)(box.get != NULL); }
-STC_INLINE _cx_self
-_cx_memb(_from_ptr)(_cx_value* p) { return c_make(_cx_self){p}; }
+STC_INLINE _cx_self _cx_memb(_from_ptr)(_cx_value* p)
+ { return c_make(_cx_self){p}; }
-STC_INLINE _cx_self
-_cx_memb(_make)(_cx_value val) { // c++: std::make_unique<i_key>(val)
+// c++: std::make_unique<i_key>(val)
+STC_INLINE _cx_self _cx_memb(_make)(_cx_value val) {
_cx_self ptr = {c_alloc(_cx_value)};
*ptr.get = val; return ptr;
}
-STC_INLINE _cx_raw
-_cx_memb(_toraw)(const _cx_self* self) {
- return i_keyto(self->get);
-}
-
-STC_INLINE _cx_value
-_cx_memb(_get)(const _cx_self* self) {
- return *self->get;
-}
+STC_INLINE _cx_raw _cx_memb(_toraw)(const _cx_self* self)
+ { return i_keyto(self->get); }
// destructor
-STC_INLINE void
-_cx_memb(_drop)(_cx_self* self) {
- if (self->get) { i_keydrop(self->get); c_free(self->get); }
+STC_INLINE void _cx_memb(_drop)(_cx_self* self) {
+ if (self->get) {
+ i_keydrop(self->get);
+ c_free(self->get);
+ }
}
-STC_INLINE _cx_self
-_cx_memb(_move)(_cx_self* self) {
- _cx_self ptr = *self; self->get = NULL;
+STC_INLINE _cx_self _cx_memb(_move)(_cx_self* self) {
+ _cx_self ptr = *self;
+ self->get = NULL;
return ptr;
}
-STC_INLINE void
-_cx_memb(_reset)(_cx_self* self) {
- _cx_memb(_drop)(self); self->get = NULL;
+STC_INLINE void _cx_memb(_reset)(_cx_self* self) {
+ _cx_memb(_drop)(self);
+ self->get = NULL;
}
// take ownership of p
-STC_INLINE void
-_cx_memb(_reset_to)(_cx_self* self, _cx_value* p) {
- if (self->get) i_keydrop(self->get);
+STC_INLINE void _cx_memb(_reset_to)(_cx_self* self, _cx_value* p) {
+ if (self->get)
+ i_keydrop(self->get);
self->get = p;
}
#if !defined _i_no_clone
#if !defined _i_no_emplace
- STC_INLINE _cx_self
- _cx_memb(_from)(_cx_raw raw) {
- return _cx_memb(_make)(i_keyfrom(raw));
- }
+ STC_INLINE _cx_self _cx_memb(_from)(_cx_raw raw)
+ { return _cx_memb(_make)(i_keyfrom(raw)); }
#endif
- STC_INLINE _cx_self
- _cx_memb(_clone)(_cx_self other) {
- if (!other.get) return other;
+ STC_INLINE _cx_self _cx_memb(_clone)(_cx_self other) {
+ if (!other.get)
+ return other;
_cx_self out = {c_alloc(i_key)};
*out.get = i_keyclone(*other.get);
return out;
}
- STC_INLINE void
- _cx_memb(_copy)(_cx_self* self, _cx_self other) {
- if (self->get == other.get) return;
+ STC_INLINE void _cx_memb(_copy)(_cx_self* self, _cx_self other) {
+ if (self->get == other.get)
+ return;
_cx_memb(_drop)(self);
*self = _cx_memb(_clone)(other);
}
#endif // !_i_no_clone
-STC_INLINE void
-_cx_memb(_take)(_cx_self* self, _cx_self other) {
- if (other.get != self->get) _cx_memb(_drop)(self);
+STC_INLINE void _cx_memb(_take)(_cx_self* self, _cx_self other) {
+ if (other.get != self->get)
+ _cx_memb(_drop)(self);
*self = other;
}
-STC_INLINE uint64_t
-_cx_memb(_value_hash)(const _cx_value* x) {
+STC_INLINE uint64_t _cx_memb(_value_hash)(const _cx_value* x) {
#if c_option(c_no_cmp)
return c_default_hash(&x);
#else
@@ -167,8 +159,7 @@ _cx_memb(_value_hash)(const _cx_value* x) {
#endif
}
-STC_INLINE int
-_cx_memb(_value_cmp)(const _cx_value* x, const _cx_value* y) {
+STC_INLINE int _cx_memb(_value_cmp)(const _cx_value* x, const _cx_value* y) {
#if c_option(c_no_cmp)
return c_default_cmp(&x, &y);
#else
@@ -177,8 +168,7 @@ _cx_memb(_value_cmp)(const _cx_value* x, const _cx_value* y) {
#endif
}
-STC_INLINE bool
-_cx_memb(_value_eq)(const _cx_value* x, const _cx_value* y) {
+STC_INLINE bool _cx_memb(_value_eq)(const _cx_value* x, const _cx_value* y) {
#if c_option(c_no_cmp)
return x == y;
#else
diff --git a/include/stc/template.h b/include/stc/template.h
index f5e77238..f55a3354 100644
--- a/include/stc/template.h
+++ b/include/stc/template.h
@@ -114,7 +114,6 @@
#elif defined i_key_arcbox
#define i_key_bind i_key_arcbox
#define i_keyraw c_paste(i_key_arcbox, _value)
- #define i_keyto c_paste(i_key_arcbox, _get)
#define i_eq c_paste(i_key_arcbox, _value_eq)
#endif
@@ -197,7 +196,6 @@
#elif defined i_val_arcbox
#define i_val_bind i_val_arcbox
#define i_valraw c_paste(i_val_arcbox, _value)
- #define i_valto c_paste(i_val_arcbox, _get)
#endif
#ifdef i_val_bind