diff options
author | David Robillard <d@drobilla.net> | 2020-11-11 13:28:26 +0100 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2020-11-11 13:28:26 +0100 |
commit | f02ff178ad0fc9c180a718cfa6786e2e5465f28a (patch) | |
tree | 7bcd14c417bb5d1d43503ec0dd2137749c81972e /src/zix | |
parent | 3faa8cc20b2c0fd3ba414e5af2bbddc96cd30f7c (diff) | |
download | sord-f02ff178ad0fc9c180a718cfa6786e2e5465f28a.tar.gz sord-f02ff178ad0fc9c180a718cfa6786e2e5465f28a.tar.bz2 sord-f02ff178ad0fc9c180a718cfa6786e2e5465f28a.zip |
Update zix
Diffstat (limited to 'src/zix')
-rw-r--r-- | src/zix/btree.c | 35 | ||||
-rw-r--r-- | src/zix/btree.h | 10 | ||||
-rw-r--r-- | src/zix/common.h | 15 | ||||
-rw-r--r-- | src/zix/digest.c | 16 | ||||
-rw-r--r-- | src/zix/digest.h | 8 | ||||
-rw-r--r-- | src/zix/hash.c | 14 | ||||
-rw-r--r-- | src/zix/hash.h | 2 |
7 files changed, 57 insertions, 43 deletions
diff --git a/src/zix/btree.c b/src/zix/btree.c index 0a8010f..3dc2d57 100644 --- a/src/zix/btree.c +++ b/src/zix/btree.c @@ -108,7 +108,7 @@ zix_btree_node_new(const bool leaf) return node; } -ZIX_API ZixBTree* +ZixBTree* zix_btree_new(const ZixComparator cmp, const void* const cmp_data, const ZixDestroyFunc destroy) @@ -147,7 +147,7 @@ zix_btree_free_rec(ZixBTree* const t, ZixBTreeNode* const n) } } -ZIX_API void +void zix_btree_free(ZixBTree* const t) { if (t) { @@ -156,7 +156,7 @@ zix_btree_free(ZixBTree* const t) } } -ZIX_API size_t +size_t zix_btree_size(const ZixBTree* const t) { return t->size; @@ -292,7 +292,7 @@ zix_btree_node_find(const ZixBTree* const t, return first; } -ZIX_API ZixStatus +ZixStatus zix_btree_insert(ZixBTree* const t, void* const e) { ZixBTreeNode* parent = NULL; // Parent of n @@ -504,7 +504,7 @@ zix_btree_remove_max(ZixBTree* const t, ZixBTreeNode* n) return n->vals[--n->n_vals]; } -ZIX_API ZixStatus +ZixStatus zix_btree_remove(ZixBTree* const t, const void* const e, void** const out, @@ -622,7 +622,7 @@ zix_btree_remove(ZixBTree* const t, return ZIX_STATUS_ERROR; } -ZIX_API ZixStatus +ZixStatus zix_btree_find(const ZixBTree* const t, const void* const e, ZixBTreeIter** const ti) @@ -653,7 +653,7 @@ zix_btree_find(const ZixBTree* const t, return ZIX_STATUS_NOT_FOUND; } -ZIX_API ZixStatus +ZixStatus zix_btree_lower_bound(const ZixBTree* const t, const void* const e, ZixBTreeIter** const ti) @@ -709,7 +709,7 @@ zix_btree_lower_bound(const ZixBTree* const t, return ZIX_STATUS_SUCCESS; } -ZIX_API void* +void* zix_btree_get(const ZixBTreeIter* const ti) { const ZixBTreeIterFrame* const frame = &ti->stack[ti->level]; @@ -718,7 +718,7 @@ zix_btree_get(const ZixBTreeIter* const ti) return frame->node->vals[frame->index]; } -ZIX_API ZixBTreeIter* +ZixBTreeIter* zix_btree_begin(const ZixBTree* const t) { ZixBTreeIter* const i = zix_btree_iter_new(t); @@ -741,13 +741,13 @@ zix_btree_begin(const ZixBTree* const t) return i; } -ZIX_API ZixBTreeIter* +ZixBTreeIter* zix_btree_end(const ZixBTree* const t) { return zix_btree_iter_new(t); } -ZIX_API ZixBTreeIter* +ZixBTreeIter* zix_btree_iter_copy(const ZixBTreeIter* const i) { if (!i) { @@ -762,20 +762,19 @@ zix_btree_iter_copy(const ZixBTreeIter* const i) return j; } -ZIX_API bool +bool zix_btree_iter_is_end(const ZixBTreeIter* const i) { return !i || i->stack[0].node == NULL; } -ZIX_API bool +bool zix_btree_iter_equals(const ZixBTreeIter* const lhs, const ZixBTreeIter* const rhs) { if (zix_btree_iter_is_end(lhs) && zix_btree_iter_is_end(rhs)) { return true; - } else if (zix_btree_iter_is_end(lhs) || zix_btree_iter_is_end(rhs)) { - return false; - } else if (!lhs || !rhs || lhs->level != rhs->level) { + } else if (zix_btree_iter_is_end(lhs) || zix_btree_iter_is_end(rhs) || + lhs->level != rhs->level) { return false; } @@ -785,7 +784,7 @@ zix_btree_iter_equals(const ZixBTreeIter* const lhs, const ZixBTreeIter* const r (lhs->level + 1) * sizeof(ZixBTreeIterFrame)); } -ZIX_API void +void zix_btree_iter_increment(ZixBTreeIter* const i) { ZixBTreeIterFrame* f = &i->stack[i->level]; @@ -826,7 +825,7 @@ zix_btree_iter_increment(ZixBTreeIter* const i) } } -ZIX_API void +void zix_btree_iter_free(ZixBTreeIter* const i) { free(i); diff --git a/src/zix/btree.h b/src/zix/btree.h index 4c972f6..c1610a8 100644 --- a/src/zix/btree.h +++ b/src/zix/btree.h @@ -68,7 +68,7 @@ zix_btree_free(ZixBTree* t); /** Return the number of elements in `t`. */ -ZIX_API size_t +ZIX_PURE_API size_t zix_btree_size(const ZixBTree* t); /** @@ -113,7 +113,7 @@ zix_btree_lower_bound(const ZixBTree* t, const void* e, ZixBTreeIter** ti); /** Return the data associated with the given tree item. */ -ZIX_API void* +ZIX_PURE_API void* zix_btree_get(const ZixBTreeIter* ti); /** @@ -121,7 +121,7 @@ zix_btree_get(const ZixBTreeIter* ti); The returned iterator must be freed with zix_btree_iter_free(). */ -ZIX_API ZixBTreeIter* +ZIX_PURE_API ZixBTreeIter* zix_btree_begin(const ZixBTree* t); /** @@ -141,13 +141,13 @@ zix_btree_iter_copy(const ZixBTreeIter* i); /** Return true iff `lhs` is equal to `rhs`. */ -ZIX_API bool +ZIX_PURE_API bool zix_btree_iter_equals(const ZixBTreeIter* lhs, const ZixBTreeIter* rhs); /** Return true iff `i` is an iterator to the end of its tree. */ -ZIX_API bool +ZIX_PURE_API bool zix_btree_iter_is_end(const ZixBTreeIter* i); /** diff --git a/src/zix/common.h b/src/zix/common.h index 3271858..f7ec4c3 100644 --- a/src/zix/common.h +++ b/src/zix/common.h @@ -46,6 +46,21 @@ # define ZIX_API # define ZIX_PRIVATE static #endif + +#ifdef __GNUC__ +# define ZIX_PURE_FUNC __attribute__((pure)) +# define ZIX_CONST_FUNC __attribute__((const)) +# define ZIX_MALLOC_FUNC __attribute__((malloc)) +#else +# define ZIX_PURE_FUNC +# define ZIX_CONST_FUNC +# define ZIX_MALLOC_FUNC +#endif + +#define ZIX_PURE_API ZIX_API ZIX_PURE_FUNC +#define ZIX_CONST_API ZIX_API ZIX_CONST_FUNC +#define ZIX_MALLOC_API ZIX_API ZIX_MALLOC_FUNC + /** @endcond */ #ifdef __cplusplus diff --git a/src/zix/digest.c b/src/zix/digest.c index 889cfde..2ac1715 100644 --- a/src/zix/digest.c +++ b/src/zix/digest.c @@ -27,13 +27,13 @@ // SSE 4.2 CRC32 -ZIX_API uint32_t +uint32_t zix_digest_start(void) { return 1; } -ZIX_API uint32_t +uint32_t zix_digest_add(uint32_t hash, const void* const buf, const size_t len) { const uint8_t* str = (const uint8_t*)buf; @@ -57,7 +57,7 @@ zix_digest_add(uint32_t hash, const void* const buf, const size_t len) return hash; } -ZIX_API uint32_t +uint32_t zix_digest_add_64(uint32_t hash, const void* const buf, const size_t len) { assert((uintptr_t)buf % sizeof(uint64_t) == 0); @@ -73,7 +73,7 @@ zix_digest_add_64(uint32_t hash, const void* const buf, const size_t len) return hash; } -ZIX_API uint32_t +uint32_t zix_digest_add_ptr(const uint32_t hash, const void* const ptr) { #if UINTPTR_MAX == UINT64_MAX @@ -87,13 +87,13 @@ zix_digest_add_ptr(const uint32_t hash, const void* const ptr) // Classic DJB hash -ZIX_API uint32_t +uint32_t zix_digest_start(void) { return 5381; } -ZIX_API uint32_t +uint32_t zix_digest_add(uint32_t hash, const void* const buf, const size_t len) { const uint8_t* str = (const uint8_t*)buf; @@ -105,7 +105,7 @@ zix_digest_add(uint32_t hash, const void* const buf, const size_t len) return hash; } -ZIX_API uint32_t +uint32_t zix_digest_add_64(uint32_t hash, const void* const buf, const size_t len) { assert((uintptr_t)buf % sizeof(uint64_t) == 0); @@ -114,7 +114,7 @@ zix_digest_add_64(uint32_t hash, const void* const buf, const size_t len) return zix_digest_add(hash, buf, len); } -ZIX_API uint32_t +uint32_t zix_digest_add_ptr(const uint32_t hash, const void* const ptr) { return zix_digest_add(hash, &ptr, sizeof(ptr)); diff --git a/src/zix/digest.h b/src/zix/digest.h index 16ba9b9..c9f3ec0 100644 --- a/src/zix/digest.h +++ b/src/zix/digest.h @@ -29,7 +29,7 @@ extern "C" { /** Return an initial empty digest value. */ -ZIX_API uint32_t +ZIX_CONST_API uint32_t zix_digest_start(void); /** @@ -37,7 +37,7 @@ zix_digest_start(void); This can be used for any size or alignment. */ -ZIX_API uint32_t +ZIX_PURE_API uint32_t zix_digest_add(uint32_t hash, const void* buf, size_t len); /** @@ -45,7 +45,7 @@ zix_digest_add(uint32_t hash, const void* buf, size_t len); Both `buf` and `len` must be evenly divisible by 8 (64 bits). */ -ZIX_API uint32_t +ZIX_PURE_API uint32_t zix_digest_add_64(uint32_t hash, const void* buf, size_t len); /** @@ -53,7 +53,7 @@ zix_digest_add_64(uint32_t hash, const void* buf, size_t len); This hashes the value of the pointer itself, and does not dereference `ptr`. */ -ZIX_API uint32_t +ZIX_CONST_API uint32_t zix_digest_add_ptr(uint32_t hash, const void* ptr); #ifdef __cplusplus diff --git a/src/zix/hash.c b/src/zix/hash.c index c4a2dba..35eaf24 100644 --- a/src/zix/hash.c +++ b/src/zix/hash.c @@ -51,7 +51,7 @@ zix_hash_value(ZixHashEntry* entry) return entry + 1; } -ZIX_API ZixHash* +ZixHash* zix_hash_new(ZixHashFunc hash_func, ZixEqualFunc equal_func, size_t value_size) @@ -72,7 +72,7 @@ zix_hash_new(ZixHashFunc hash_func, return hash; } -ZIX_API void +void zix_hash_free(ZixHash* hash) { if (!hash) { @@ -92,7 +92,7 @@ zix_hash_free(ZixHash* hash) free(hash); } -ZIX_API size_t +size_t zix_hash_size(const ZixHash* hash) { return hash->count; @@ -144,7 +144,7 @@ find_entry(const ZixHash* hash, return NULL; } -ZIX_API void* +void* zix_hash_find(const ZixHash* hash, const void* value) { const unsigned h_nomod = hash->hash_func(value); @@ -153,7 +153,7 @@ zix_hash_find(const ZixHash* hash, const void* value) return entry ? zix_hash_value(entry) : 0; } -ZIX_API ZixStatus +ZixStatus zix_hash_insert(ZixHash* hash, const void* value, void** inserted) { unsigned h_nomod = hash->hash_func(value); @@ -191,7 +191,7 @@ zix_hash_insert(ZixHash* hash, const void* value, void** inserted) return ZIX_STATUS_SUCCESS; } -ZIX_API ZixStatus +ZixStatus zix_hash_remove(ZixHash* hash, const void* value) { const unsigned h_nomod = hash->hash_func(value); @@ -221,7 +221,7 @@ zix_hash_remove(ZixHash* hash, const void* value) return ZIX_STATUS_NOT_FOUND; } -ZIX_API void +void zix_hash_foreach(ZixHash* hash, ZixHashVisitFunc f, void* user_data) diff --git a/src/zix/hash.h b/src/zix/hash.h index 9546a64..2550676 100644 --- a/src/zix/hash.h +++ b/src/zix/hash.h @@ -73,7 +73,7 @@ zix_hash_free(ZixHash* hash); /** Return the number of elements in `hash`. */ -ZIX_API size_t +ZIX_PURE_API size_t zix_hash_size(const ZixHash* hash); /** |