diff options
| author | Tyge Løvset <[email protected]> | 2022-02-18 16:25:25 +0100 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2022-02-18 16:25:25 +0100 |
| commit | 4ac5ef68726057ff97e56c951e4faeaa29995e40 (patch) | |
| tree | cc8f82362d1fa6a94c8e279d7ce0b6f3581225c2 /include | |
| parent | fde8f4a37c42a3611b544185806155a02e24227e (diff) | |
| download | STC-modified-4ac5ef68726057ff97e56c951e4faeaa29995e40.tar.gz STC-modified-4ac5ef68726057ff97e56c951e4faeaa29995e40.zip | |
Some improvements and cleanup: CRegex, CMap.
Diffstat (limited to 'include')
| -rw-r--r-- | include/stc/ccommon.h | 10 | ||||
| -rw-r--r-- | include/stc/cmap.h | 12 | ||||
| -rw-r--r-- | include/stc/forward.h | 10 |
3 files changed, 16 insertions, 16 deletions
diff --git a/include/stc/ccommon.h b/include/stc/ccommon.h index 292ac9cc..e5a595e0 100644 --- a/include/stc/ccommon.h +++ b/include/stc/ccommon.h @@ -122,13 +122,11 @@ STC_INLINE uint64_t c_default_hash(const void* key, size_t len) { while (--len) h = (h << 10) - h + *x++;
return _c_ROTL(h, 26) ^ h;
}
-STC_INLINE uint64_t c_hash32(const void* key, size_t len) {
- uint32_t x; memcpy(&x, key, 4);
- return x*0xc6a4a7935bd1e99d >> 15;
+STC_INLINE uint64_t c_hash32(const void* key, size_t n) {
+ return *(uint32_t *)key*0xc6a4a7935bd1e99d;
}
-STC_INLINE uint64_t c_hash64(const void* key, size_t len) {
- uint64_t x; memcpy(&x, key, 8);
- return x*0xc6a4a7935bd1e99d;
+STC_INLINE uint64_t c_hash64(const void* key, size_t n) {
+ return *(uint64_t *)key*0xc6a4a7935bd1e99d;
}
STC_INLINE char* c_strnstrn(const char *s, const char *needle, size_t slen, const size_t nlen) {
diff --git a/include/stc/cmap.h b/include/stc/cmap.h index af247ffc..a5ca353e 100644 --- a/include/stc/cmap.h +++ b/include/stc/cmap.h @@ -233,10 +233,10 @@ _cx_memb(_erase_at)(_cx_self* self, _cx_iter it) { #if defined(_i_implement)
#ifndef CMAP_H_INCLUDED
-//STC_INLINE size_t fastrange_uint64_t(uint64_t x, uint64_t n)
-// { uint64_t lo, hi; c_umul128(x, n, &lo, &hi); return hi; }
-#define fastrange_uint32_t(x, n) (uint32_t)((uint32_t)(x)*(uint64_t)(n) >> 32)
-#define chash_index_(h, entryPtr) ((entryPtr) - (h).table)
+STC_INLINE size_t fastrange_size_t(uint64_t x, uint64_t n)
+ { uint64_t lo, hi; c_umul128(x, n, &lo, &hi); return (size_t)hi; }
+STC_INLINE size_t fastrange_uint32_t(uint64_t x, uint64_t n)
+ { return (size_t)((uint32_t)x*n >> 32); }
#endif // CMAP_H_INCLUDED
STC_DEF _cx_self
@@ -362,11 +362,11 @@ _cx_memb(_reserve)(_cx_self* self, const size_t _newcap) { STC_DEF void
_cx_memb(_erase_entry)(_cx_self* self, _cx_value* _val) {
- _cx_size i = chash_index_(*self, _val), j = i, k;
+ _cx_size i = _val - self->table, j = i, k;
const _cx_size _cap = self->bucket_count;
_cx_value* _slot = self->table;
uint8_t* _hashx = self->_hashx;
- _cx_memb(_value_drop)(&_slot[i]);
+ _cx_memb(_value_drop)(_val);
for (;;) { /* delete without leaving tombstone */
if (++j == _cap)
j = 0;
diff --git a/include/stc/forward.h b/include/stc/forward.h index ca1fd540..e57aedfd 100644 --- a/include/stc/forward.h +++ b/include/stc/forward.h @@ -29,10 +29,12 @@ #define forward_carr3(CX, VAL) _c_carr3_types(CX, VAL)
#define forward_cdeq(CX, VAL) _c_cdeq_types(CX, VAL)
#define forward_clist(CX, VAL) _c_clist_types(CX, VAL)
-#define forward_cmap(CX, KEY, VAL, SZ) _c_chash_types(CX, KEY, VAL, SZ, c_true, c_false)
-#define forward_csmap(CX, KEY, VAL, SZ) _c_aatree_types(CX, KEY, VAL, SZ, c_true, c_false)
-#define forward_cset(CX, KEY, SZ) _c_chash_types(CX, cset, KEY, KEY, SZ, c_false, c_true)
-#define forward_csset(CX, KEY, SZ) _c_aatree_types(CX, KEY, KEY, SZ, c_false, c_true)
+#define forward_cmap(CX, KEY, VAL) _c_chash_types(CX, KEY, VAL, uint32_t, c_true, c_false)
+#define forward_cmap_big(CX, KEY, VAL) _c_chash_types(CX, KEY, VAL, size_t, c_true, c_false)
+#define forward_cset(CX, KEY) _c_chash_types(CX, cset, KEY, KEY, uint32_t, c_false, c_true)
+#define forward_cset_big(CX, KEY) _c_chash_types(CX, cset, KEY, KEY, size_t, c_false, c_true)
+#define forward_csmap(CX, KEY, VAL) _c_aatree_types(CX, KEY, VAL, uint32_t, c_true, c_false)
+#define forward_csset(CX, KEY) _c_aatree_types(CX, KEY, KEY, uint32_t, c_false, c_true)
#define forward_cbox(CX, VAL) _c_cbox_types(CX, VAL)
#define forward_carc(CX, VAL) _c_carc_types(CX, VAL)
#define forward_cpque(CX, VAL) _c_cpque_types(CX, VAL)
|
