diff options
| author | Tyge Løvset <[email protected]> | 2021-09-08 15:22:44 +0200 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2021-09-08 15:22:44 +0200 |
| commit | ef9697b470d6b2a6d210a1f7439c3d4d6da9d7ee (patch) | |
| tree | 7cf539a25fef61f8d9bf4a44e48b5c022b2c0be5 /include | |
| parent | 02b570c24df856e4f60edd37266a1b3835aaad42 (diff) | |
| download | STC-modified-ef9697b470d6b2a6d210a1f7439c3d4d6da9d7ee.tar.gz STC-modified-ef9697b470d6b2a6d210a1f7439c3d4d6da9d7ee.zip | |
Fixed linkage stuff.
Diffstat (limited to 'include')
| -rw-r--r-- | include/stc/ccommon.h | 6 | ||||
| -rw-r--r-- | include/stc/clist.h | 26 | ||||
| -rw-r--r-- | include/stc/cmap.h | 53 |
3 files changed, 43 insertions, 42 deletions
diff --git a/include/stc/ccommon.h b/include/stc/ccommon.h index bad9dc8c..8250c4b6 100644 --- a/include/stc/ccommon.h +++ b/include/stc/ccommon.h @@ -109,6 +109,12 @@ #define c_default_del(ptr) ((void) (ptr))
+STC_API uint64_t c_default_hash(const void *key, size_t len);
+#define c_default_hash32(data, len_is_4) \
+ ((*(const uint32_t*)data * 0xc6a4a7935bd1e99d) >> 15)
+#define c_default_hash64(data, len_is_8) \
+ (*(const uint64_t *)data * 0xc6a4a7935bd1e99d)
+
/* Generic algorithms */
#define c_foreach(...) c_MACRO_OVERLOAD(c_foreach, __VA_ARGS__)
diff --git a/include/stc/clist.h b/include/stc/clist.h index 12be1146..9d920ead 100644 --- a/include/stc/clist.h +++ b/include/stc/clist.h @@ -55,6 +55,7 @@ */
#ifndef CLIST_H_INCLUDED
+#define CLIST_H_INCLUDED
#include "ccommon.h"
#include "forward.h"
#include <stdlib.h>
@@ -70,29 +71,28 @@ _c_clist_types(clist_VOID, int);
_c_clist_complete_types(clist_VOID, dummy);
+
+#define _c_clist_insert_after(self, Self, node, val) \
+ cx_node_t *entry = c_new (cx_node_t); \
+ if (node) entry->next = node->next, node->next = entry; \
+ else entry->next = entry; \
+ entry->value = val
+ // +: set self->last based on node
+
#endif // CLIST_H_INCLUDED
#define i_module clist
#include "template.h"
#if !defined i_fwd
-cx_deftypes(_c_clist_types, Self, i_val);
+ cx_deftypes(_c_clist_types, Self, i_val);
#endif
cx_deftypes(_c_clist_complete_types, Self, dummy);
typedef i_valraw cx_rawvalue_t;
-
-#ifndef CLIST_H_INCLUDED
-#define CLIST_H_INCLUDED
-#define _c_clist_insert_after(self, Self, node, val) \
- cx_node_t *entry = c_new (cx_node_t); \
- if (node) entry->next = node->next, node->next = entry; \
- else entry->next = entry; \
- entry->value = val
- // +: set self->last based on node
-
-#if !defined(STC_HEADER) || defined(i_imp) && (i_imp == 2)
-// NON TEMPLATED CODE
+#if !defined(STC_HEADER) || defined(i_imp) && i_imp == 2
+#ifndef CLIST_NON_TEMPLATED
+#define CLIST_NON_TEMPLATED
STC_DEF size_t
_clist_count(const clist_VOID* self) {
diff --git a/include/stc/cmap.h b/include/stc/cmap.h index f820d620..a03d5c83 100644 --- a/include/stc/cmap.h +++ b/include/stc/cmap.h @@ -57,34 +57,6 @@ int main(void) { #define _cmap_inits {NULL, NULL, 0, 0, 0.85f}
typedef struct { size_t idx; uint_fast8_t hx; } chash_bucket_t;
-
-#if !defined(STC_HEADER) || defined(STC_IMPLEMENTATION) || defined(i_imp)
-
-STC_INLINE uint64_t c_default_hash(const void *key, size_t len) {
- const uint64_t m = 0xb5ad4eceda1ce2a9;
- uint64_t k, h = m + len;
- const uint8_t *p = (const uint8_t *)key, *end = p + (len & ~7ull);
- for (; p != end; p += 8) {memcpy(&k, p, 8); h ^= m*k; }
- switch (len & 7) {
- case 7: h ^= (uint64_t) p[6] << 48;
- case 6: h ^= (uint64_t) p[5] << 40;
- case 5: h ^= (uint64_t) p[4] << 32;
- case 4: h ^= (uint64_t) p[3] << 24;
- case 3: h ^= (uint64_t) p[2] << 16;
- case 2: h ^= (uint64_t) p[1] << 8;
- case 1: h ^= (uint64_t) p[0]; h *= m;
- }
- return h ^ (h >> 15);
-}
-
-STC_INLINE uint64_t c_string_hash(const char *s)
- { return c_default_hash(s, strlen(s)); }
-STC_INLINE uint64_t c_default_hash32(const void* data, size_t ignored)
- { return *(const uint32_t *)data * 0xc6a4a7935bd1e99d; }
-STC_INLINE uint64_t c_default_hash64(const void* data, size_t ignored)
- { return *(const uint64_t *)data * 0xc6a4a7935bd1e99d; }
-
-#endif
#endif // CMAP_H_INCLUDED
#ifndef i_module
@@ -240,6 +212,29 @@ cx_memb(_erase_at)(Self* self, cx_iter_t it) { /* -------------------------- IMPLEMENTATION ------------------------- */
+#if !defined(STC_HEADER) || defined(i_imp) && i_imp == 2
+#ifndef CMAP_NON_TEMPLATED
+#define CMAP_NON_TEMPLATED
+
+STC_DEF uint64_t c_default_hash(const void *key, size_t len) {
+ const uint64_t m = 0xb5ad4eceda1ce2a9;
+ uint64_t k, h = m + len;
+ const uint8_t *p = (const uint8_t *)key, *end = p + (len & ~7ull);
+ for (; p != end; p += 8) { memcpy(&k, p, 8); h ^= m*k; }
+ switch (len & 7) {
+ case 7: h ^= (uint64_t) p[6] << 48;
+ case 6: h ^= (uint64_t) p[5] << 40;
+ case 5: h ^= (uint64_t) p[4] << 32;
+ case 4: h ^= (uint64_t) p[3] << 24;
+ case 3: h ^= (uint64_t) p[2] << 16;
+ case 2: h ^= (uint64_t) p[1] << 8;
+ case 1: h ^= (uint64_t) p[0]; h *= m;
+ }
+ return h ^ (h >> 15);
+}
+#endif
+#endif
+
#if !defined(STC_HEADER) || defined(STC_IMPLEMENTATION) || defined(i_imp)
//STC_INLINE size_t fastrange_uint64_t(uint64_t x, uint64_t n)
@@ -379,7 +374,7 @@ cx_memb(_erase_entry)(Self* self, cx_value_t* _val) { --self->size;
}
-#endif // IMPLEMENTATION
+#endif // TEMPLATED IMPLEMENTATION
#undef cx_keyref
#undef cx_MAP_ONLY
#undef cx_SET_ONLY
|
