diff options
| author | Tyge Løvset <[email protected]> | 2022-04-25 20:03:04 +0200 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2022-04-25 20:03:04 +0200 |
| commit | 29b1fb689c71837616023b3adc78eda3d32026b2 (patch) | |
| tree | 63f0bd3532f1819fb31d32c9c1c203eade79ea0c /include | |
| parent | 72b40c6f5bbfbf11eba112a42ca5536c4c8e7d8f (diff) | |
| download | STC-modified-29b1fb689c71837616023b3adc78eda3d32026b2.tar.gz STC-modified-29b1fb689c71837616023b3adc78eda3d32026b2.zip | |
Removed size argument to `i_hash` template parameter and `c_default_hash`. This was a "design error", and is not worth keeping for backward compability. Please update your code where you use i_hash template parameter (simply remove second argument).
Diffstat (limited to 'include')
| -rw-r--r-- | include/stc/alt/cstr.h | 13 | ||||
| -rw-r--r-- | include/stc/carc.h | 6 | ||||
| -rw-r--r-- | include/stc/cbox.h | 6 | ||||
| -rw-r--r-- | include/stc/ccommon.h | 18 | ||||
| -rw-r--r-- | include/stc/cmap.h | 4 | ||||
| -rw-r--r-- | include/stc/cstr.h | 4 | ||||
| -rw-r--r-- | include/stc/csview.h | 4 |
7 files changed, 31 insertions, 24 deletions
diff --git a/include/stc/alt/cstr.h b/include/stc/alt/cstr.h index 06f8eae1..f81736dc 100644 --- a/include/stc/alt/cstr.h +++ b/include/stc/alt/cstr.h @@ -168,9 +168,16 @@ STC_INLINE int c_strncasecmp(const char* s1, const char* s2, size_t nmax) { }
/* container adaptor functions: */
-#define cstr_cmp(xp, yp) strcmp((xp)->str, (yp)->str)
-#define cstr_eq(xp, yp) (!cstr_cmp(xp, yp))
-#define cstr_hash(xp, dummy) c_strhash((xp)->str)
+#define cstr_cmp(xp, yp) strcmp((xp)->str, (yp)->str)
+
+STC_INLINE bool cstr_eq(const cstr* x, const cstr* y) {
+ size_t xs = _cstr_p(x)->size, ys = _cstr_p(y)->size;
+ return xs == ys && !memcmp(x->str, y->str, xs);
+}
+STC_INLINE uint64_t cstr_hash(const cstr *self) {
+ return c_fasthash(self->str, _cstr_p(self)->size);
+}
+
/* -------------------------- IMPLEMENTATION ------------------------- */
#if defined(_i_implement)
diff --git a/include/stc/carc.h b/include/stc/carc.h index 1cdca419..80b9a879 100644 --- a/include/stc/carc.h +++ b/include/stc/carc.h @@ -169,12 +169,12 @@ _cx_memb(_take)(_cx_self* self, _cx_self ptr) { }
STC_INLINE uint64_t
-_cx_memb(_value_hash)(const _cx_value* x, size_t n) {
+_cx_memb(_value_hash)(const _cx_value* x) {
#if c_option(c_no_cmp)
- return c_default_hash(&x, sizeof x);
+ return c_default_hash(&x);
#else
_cx_raw rx = i_keyto(x);
- return i_hash((&rx), (sizeof rx));
+ return i_hash((&rx));
#endif
}
diff --git a/include/stc/cbox.h b/include/stc/cbox.h index fa6ef2a9..14459640 100644 --- a/include/stc/cbox.h +++ b/include/stc/cbox.h @@ -146,12 +146,12 @@ _cx_memb(_take)(_cx_self* self, _cx_self other) { }
STC_INLINE uint64_t
-_cx_memb(_value_hash)(const _cx_value* x, size_t n) {
+_cx_memb(_value_hash)(const _cx_value* x) {
#if c_option(c_no_cmp)
- return c_default_hash(&x, sizeof x);
+ return c_default_hash(&x);
#else
_cx_raw rx = i_keyto(x);
- return i_hash((&rx), (sizeof rx));
+ return i_hash((&rx));
#endif
}
diff --git a/include/stc/ccommon.h b/include/stc/ccommon.h index 1c19bde7..dd048c43 100644 --- a/include/stc/ccommon.h +++ b/include/stc/ccommon.h @@ -92,27 +92,27 @@ #define c_default_toraw(ptr) (*(ptr))
#define c_default_drop(ptr) ((void) (ptr))
+#define c_default_hash(p) c_fasthash(p, sizeof *(p))
+
#define c_option(flag) ((i_opt) & (flag))
#define c_is_fwd (1<<0)
#define c_no_atomic (1<<1)
#define c_no_clone (1<<2)
#define c_no_cmp (1<<3)
-#define c_hash (1<<4)
-#define c_eq (1<<5)
-#define c_static (1<<6)
-#define c_header (1<<7)
-#define c_implement (1<<8)
+#define c_static (1<<4)
+#define c_header (1<<5)
+#define c_implement (1<<6)
/* Generic algorithms */
typedef const char* crawstr;
#define crawstr_cmp(xp, yp) strcmp(*(xp), *(yp))
#define crawstr_eq(xp, yp) (!strcmp(*(xp), *(yp)))
-#define crawstr_hash(p, dummy) c_strhash(*(p))
+#define crawstr_hash(p) c_strhash(*(p))
#define _c_ROTL(x, k) (x << (k) | x >> (8*sizeof(x) - (k)))
-STC_INLINE uint64_t c_default_hash(const void* key, size_t len) {
+STC_INLINE uint64_t c_fasthash(const void* key, size_t len) {
uint64_t u8, h = 1; size_t n = len >> 3;
uint32_t u4;
const uint8_t *x = (const uint8_t*) key;
@@ -127,8 +127,8 @@ STC_INLINE uint64_t c_default_hash(const void* key, size_t len) { return _c_ROTL(h, 26) ^ h;
}
-STC_INLINE uint64_t c_strhash(const char *s)
- { return c_default_hash(s, strlen(s)); }
+STC_INLINE uint64_t c_strhash(const char *str)
+ { return c_fasthash(str, strlen(str)); }
STC_INLINE char* c_strnstrn(const char *s, const char *needle, size_t slen, const size_t nlen) {
if (!nlen) return (char *)s;
diff --git a/include/stc/cmap.h b/include/stc/cmap.h index 978d624a..25356e16 100644 --- a/include/stc/cmap.h +++ b/include/stc/cmap.h @@ -294,7 +294,7 @@ STC_DEF void _cx_memb(_clear)(_cx_self* self) { STC_DEF chash_bucket_t
_cx_memb(_bucket_)(const _cx_self* self, const _cx_rawkey* rkeyptr) {
- const uint64_t _hash = i_hash(rkeyptr, (sizeof *rkeyptr));
+ const uint64_t _hash = i_hash(rkeyptr);
uint8_t _hx; _cx_size _cap = self->bucket_count;
chash_bucket_t b = {c_paste(fastrange_,i_size)(_hash, _cap), (uint8_t)(_hash | 0x80)};
const uint8_t* _hashx = self->_hashx;
@@ -380,7 +380,7 @@ _cx_memb(_erase_entry)(_cx_self* self, _cx_value* _val) { if (! _hashx[j])
break;
_cx_rawkey _raw = i_keyto(_i_keyref(_slot + j));
- k = c_paste(fastrange_,i_size)(i_hash((&_raw), (sizeof _raw)), _cap);
+ k = c_paste(fastrange_,i_size)(i_hash((&_raw)), _cap);
if ((j < i) ^ (k <= i) ^ (k > j)) /* is k outside (i, j]? */
_slot[i] = _slot[j], _hashx[i] = _hashx[j], i = j;
}
diff --git a/include/stc/cstr.h b/include/stc/cstr.h index b669b6d5..b48a9151 100644 --- a/include/stc/cstr.h +++ b/include/stc/cstr.h @@ -262,9 +262,9 @@ STC_INLINE void cstr_insert_s(cstr* self, size_t pos, cstr s) { STC_INLINE bool cstr_getline(cstr *self, FILE *fp)
{ return cstr_getdelim(self, '\n', fp); }
-STC_INLINE uint64_t cstr_hash(const cstr *self, size_t dummylen) {
+STC_INLINE uint64_t cstr_hash(const cstr *self) {
csview sv = cstr_sv(self);
- return c_default_hash(sv.str, sv.size);
+ return c_fasthash(sv.str, sv.size);
}
/* -------------------------- IMPLEMENTATION ------------------------- */
diff --git a/include/stc/csview.h b/include/stc/csview.h index be430a79..dd8559b5 100644 --- a/include/stc/csview.h +++ b/include/stc/csview.h @@ -128,8 +128,8 @@ STC_INLINE int csview_cmp(const csview* x, const csview* y) STC_INLINE bool csview_eq(const csview* x, const csview* y)
{ return x->size == y->size && !memcmp(x->str, y->str, x->size); }
-STC_INLINE uint64_t csview_hash(const csview *self, size_t sz)
- { return c_default_hash(self->str, self->size); }
+STC_INLINE uint64_t csview_hash(const csview *self)
+ { return c_fasthash(self->str, self->size); }
/* -------------------------- IMPLEMENTATION ------------------------- */
#if defined(_i_implement)
|
