diff options
-rw-r--r-- | benchmark/dict_bench.c | 2 | ||||
-rw-r--r-- | benchmark/tree_bench.c | 2 | ||||
-rw-r--r-- | include/zix/btree.h | 7 | ||||
-rw-r--r-- | include/zix/function_types.h | 37 | ||||
-rw-r--r-- | include/zix/hash.h | 2 | ||||
-rw-r--r-- | include/zix/ring.h | 2 | ||||
-rw-r--r-- | include/zix/sem.h | 2 | ||||
-rw-r--r-- | include/zix/status.h (renamed from include/zix/common.h) | 25 | ||||
-rw-r--r-- | include/zix/thread.h | 2 | ||||
-rw-r--r-- | include/zix/tree.h | 5 | ||||
-rw-r--r-- | meson.build | 3 | ||||
-rw-r--r-- | src/btree.c | 52 | ||||
-rw-r--r-- | src/errno_status.c | 2 | ||||
-rw-r--r-- | src/errno_status.h | 2 | ||||
-rw-r--r-- | src/ring.c | 2 | ||||
-rw-r--r-- | src/sem.c | 2 | ||||
-rw-r--r-- | src/status.c | 2 | ||||
-rw-r--r-- | src/thread.c | 2 | ||||
-rw-r--r-- | src/tree.c | 7 | ||||
-rw-r--r-- | test/headers/test_headers.c | 3 | ||||
-rw-r--r-- | test/test_btree.c | 2 | ||||
-rw-r--r-- | test/test_hash.c | 2 | ||||
-rw-r--r-- | test/test_sem.c | 2 | ||||
-rw-r--r-- | test/test_status.c | 2 | ||||
-rw-r--r-- | test/test_tree.c | 2 |
25 files changed, 104 insertions, 69 deletions
diff --git a/benchmark/dict_bench.c b/benchmark/dict_bench.c index 640e50e..85a4755 100644 --- a/benchmark/dict_bench.c +++ b/benchmark/dict_bench.c @@ -5,9 +5,9 @@ #include "warnings.h" #include "zix/attributes.h" -#include "zix/common.h" #include "zix/digest.h" #include "zix/hash.h" +#include "zix/status.h" ZIX_DISABLE_GLIB_WARNINGS #include <glib.h> diff --git a/benchmark/tree_bench.c b/benchmark/tree_bench.c index 1fca1a3..7754857 100644 --- a/benchmark/tree_bench.c +++ b/benchmark/tree_bench.c @@ -8,7 +8,7 @@ #include "zix/attributes.h" #include "zix/btree.h" -#include "zix/common.h" +#include "zix/status.h" #include "zix/tree.h" ZIX_DISABLE_GLIB_WARNINGS diff --git a/include/zix/btree.h b/include/zix/btree.h index 1b36908..33f47d1 100644 --- a/include/zix/btree.h +++ b/include/zix/btree.h @@ -6,7 +6,8 @@ #include "zix/allocator.h" #include "zix/attributes.h" -#include "zix/common.h" +#include "zix/function_types.h" +#include "zix/status.h" #include <stdbool.h> #include <stddef.h> @@ -74,7 +75,7 @@ static const ZixBTreeIter zix_btree_end_iter = { ZIX_API ZixBTree* ZIX_ALLOCATED zix_btree_new(ZixAllocator* ZIX_NULLABLE allocator, - ZixComparator ZIX_NONNULL cmp, + ZixCompareFunc ZIX_NONNULL cmp, const void* ZIX_NULLABLE cmp_data); /** @@ -166,7 +167,7 @@ zix_btree_find(const ZixBTree* ZIX_NONNULL t, ZIX_API ZixStatus zix_btree_lower_bound(const ZixBTree* ZIX_NONNULL t, - ZixComparator ZIX_NULLABLE compare_key, + ZixCompareFunc ZIX_NULLABLE compare_key, const void* ZIX_NULLABLE compare_key_user_data, const void* ZIX_NULLABLE key, ZixBTreeIter* ZIX_NONNULL ti); diff --git a/include/zix/function_types.h b/include/zix/function_types.h new file mode 100644 index 0000000..8822847 --- /dev/null +++ b/include/zix/function_types.h @@ -0,0 +1,37 @@ +// Copyright 2016-2022 David Robillard <d@drobilla.net> +// SPDX-License-Identifier: ISC + +#ifndef ZIX_FUNCTION_TYPES_H +#define ZIX_FUNCTION_TYPES_H + +#include "zix/attributes.h" + +#include <stdbool.h> + +#ifdef __cplusplus +extern "C" { +#endif + +/** + @defgroup zix_function_types Function Types + @ingroup zix + @{ +*/ + +/// Function for comparing two elements +typedef int (*ZixCompareFunc)(const void* a, + const void* b, + const void* user_data); + +/// Function to destroy an element +typedef void (*ZixDestroyFunc)(void* ptr, const void* user_data); + +/** + @} +*/ + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /* ZIX_FUNCTION_TYPES_H */ diff --git a/include/zix/hash.h b/include/zix/hash.h index c1521e0..397e055 100644 --- a/include/zix/hash.h +++ b/include/zix/hash.h @@ -6,7 +6,7 @@ #include "zix/allocator.h" #include "zix/attributes.h" -#include "zix/common.h" +#include "zix/status.h" #include <stdbool.h> #include <stddef.h> diff --git a/include/zix/ring.h b/include/zix/ring.h index 6fb78ac..66662b7 100644 --- a/include/zix/ring.h +++ b/include/zix/ring.h @@ -6,7 +6,7 @@ #include "zix/allocator.h" #include "zix/attributes.h" -#include "zix/common.h" +#include "zix/status.h" #include <stdint.h> diff --git a/include/zix/sem.h b/include/zix/sem.h index 25088bf..3777497 100644 --- a/include/zix/sem.h +++ b/include/zix/sem.h @@ -5,7 +5,7 @@ #define ZIX_SEM_H #include "zix/attributes.h" -#include "zix/common.h" +#include "zix/status.h" #ifdef __APPLE__ # include <mach/mach.h> diff --git a/include/zix/common.h b/include/zix/status.h index 788fdaa..fcd45fb 100644 --- a/include/zix/common.h +++ b/include/zix/status.h @@ -1,22 +1,22 @@ // Copyright 2016-2022 David Robillard <d@drobilla.net> // SPDX-License-Identifier: ISC -#ifndef ZIX_COMMON_H -#define ZIX_COMMON_H +#ifndef ZIX_STATUS_H +#define ZIX_STATUS_H #include "zix/attributes.h" -#include <stdbool.h> +#ifdef __cplusplus +extern "C" { +#endif /** @defgroup zix Zix C API @{ + @defgroup zix_status Status Codes + @{ */ -#ifdef __cplusplus -extern "C" { -#endif - /// A status code returned by functions typedef enum { ZIX_STATUS_SUCCESS, ///< Success @@ -38,20 +38,13 @@ ZIX_CONST_API const char* zix_strerror(ZixStatus status); -/// Function for comparing two elements -typedef int (*ZixComparator)(const void* a, - const void* b, - const void* user_data); - -/// Function to destroy an element -typedef void (*ZixDestroyFunc)(void* ptr, const void* user_data); - /** @} + @} */ #ifdef __cplusplus } /* extern "C" */ #endif -#endif /* ZIX_COMMON_H */ +#endif /* ZIX_STATUS_H */ diff --git a/include/zix/thread.h b/include/zix/thread.h index af036b1..14c525d 100644 --- a/include/zix/thread.h +++ b/include/zix/thread.h @@ -5,7 +5,7 @@ #define ZIX_THREAD_H #include "zix/attributes.h" -#include "zix/common.h" +#include "zix/status.h" #ifdef _WIN32 # include <windows.h> diff --git a/include/zix/tree.h b/include/zix/tree.h index f363ffc..7b77a7c 100644 --- a/include/zix/tree.h +++ b/include/zix/tree.h @@ -6,7 +6,8 @@ #include "zix/allocator.h" #include "zix/attributes.h" -#include "zix/common.h" +#include "zix/function_types.h" +#include "zix/status.h" #include <stdbool.h> #include <stddef.h> @@ -32,7 +33,7 @@ ZIX_API ZixTree* ZIX_ALLOCATED zix_tree_new(ZixAllocator* ZIX_NULLABLE allocator, bool allow_duplicates, - ZixComparator ZIX_NONNULL cmp, + ZixCompareFunc ZIX_NONNULL cmp, void* ZIX_NULLABLE cmp_data, ZixDestroyFunc ZIX_NULLABLE destroy, const void* ZIX_NULLABLE destroy_user_data); diff --git a/meson.build b/meson.build index 31f9fc0..8e515f3 100644 --- a/meson.build +++ b/meson.build @@ -97,11 +97,12 @@ c_headers = files( 'include/zix/bitset.h', 'include/zix/btree.h', 'include/zix/bump_allocator.h', - 'include/zix/common.h', 'include/zix/digest.h', + 'include/zix/function_types.h', 'include/zix/hash.h', 'include/zix/ring.h', 'include/zix/sem.h', + 'include/zix/status.h', 'include/zix/thread.h', 'include/zix/tree.h', ) diff --git a/src/btree.c b/src/btree.c index 0725612..30a1538 100644 --- a/src/btree.c +++ b/src/btree.c @@ -25,11 +25,11 @@ typedef uint16_t ZixShort; #define ZIX_BTREE_INODE_VALS (ZIX_BTREE_LEAF_VALS / 2U) struct ZixBTreeImpl { - ZixAllocator* allocator; - ZixBTreeNode* root; - ZixComparator cmp; - const void* cmp_data; - size_t size; + ZixAllocator* allocator; + ZixBTreeNode* root; + ZixCompareFunc cmp; + const void* cmp_data; + size_t size; }; struct ZixBTreeNodeImpl { @@ -88,9 +88,9 @@ zix_btree_child(const ZixBTreeNode* const node, const unsigned i) } ZixBTree* -zix_btree_new(ZixAllocator* const allocator, - const ZixComparator cmp, - const void* const cmp_data) +zix_btree_new(ZixAllocator* const allocator, + const ZixCompareFunc cmp, + const void* const cmp_data) { #if !((defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L) || \ (defined(__cplusplus) && __cplusplus >= 201103L)) @@ -263,11 +263,11 @@ zix_btree_split_child(ZixAllocator* const allocator, #ifdef ZIX_BTREE_SORTED_CHECK /// Check that `n` is sorted with respect to search key `e` static bool -zix_btree_node_is_sorted_with_respect_to(const ZixComparator compare, - const void* const compare_user_data, - void* const* const values, - const unsigned n_values, - const void* const key) +zix_btree_node_is_sorted_with_respect_to(const ZixCompareFunc compare, + const void* const compare_user_data, + void* const* const values, + const unsigned n_values, + const void* const key) { if (n_values <= 1U) { return true; @@ -288,12 +288,12 @@ zix_btree_node_is_sorted_with_respect_to(const ZixComparator compare, #endif static unsigned -zix_btree_find_value(const ZixComparator compare, - const void* const compare_user_data, - void* const* const values, - const unsigned n_values, - const void* const key, - bool* const equal) +zix_btree_find_value(const ZixCompareFunc compare, + const void* const compare_user_data, + void* const* const values, + const unsigned n_values, + const void* const key, + bool* const equal) { unsigned first = 0U; unsigned count = n_values; @@ -323,12 +323,12 @@ zix_btree_find_value(const ZixComparator compare, } static unsigned -zix_btree_find_pattern(const ZixComparator compare_key, - const void* const compare_key_user_data, - void* const* const values, - const unsigned n_values, - const void* const key, - bool* const equal) +zix_btree_find_pattern(const ZixCompareFunc compare_key, + const void* const compare_key_user_data, + void* const* const values, + const unsigned n_values, + const void* const key, + bool* const equal) { #ifdef ZIX_BTREE_SORTED_CHECK assert(zix_btree_node_is_sorted_with_respect_to( @@ -854,7 +854,7 @@ zix_btree_find(const ZixBTree* const t, ZixStatus zix_btree_lower_bound(const ZixBTree* const t, - const ZixComparator compare_key, + const ZixCompareFunc compare_key, const void* const compare_key_user_data, const void* const key, ZixBTreeIter* const ti) diff --git a/src/errno_status.c b/src/errno_status.c index 1830234..142d456 100644 --- a/src/errno_status.c +++ b/src/errno_status.c @@ -3,7 +3,7 @@ #include "errno_status.h" -#include "zix/common.h" +#include "zix/status.h" #include <errno.h> #include <stddef.h> diff --git a/src/errno_status.h b/src/errno_status.h index da26b66..2f81e4e 100644 --- a/src/errno_status.h +++ b/src/errno_status.h @@ -5,7 +5,7 @@ #define ZIX_ERRNO_STATUS_H #include "zix/attributes.h" -#include "zix/common.h" +#include "zix/status.h" /// Return an errno value converted to a status code ZIX_CONST_FUNC @@ -7,7 +7,7 @@ #include "zix_config.h" #include "zix/allocator.h" -#include "zix/common.h" +#include "zix/status.h" #if USE_MLOCK # include <sys/mman.h> @@ -6,7 +6,7 @@ #include "errno_status.h" #include "zix_config.h" -#include "zix/common.h" +#include "zix/status.h" #ifdef __APPLE__ # include <mach/mach.h> diff --git a/src/status.c b/src/status.c index 9cdab32..4b06b97 100644 --- a/src/status.c +++ b/src/status.c @@ -1,7 +1,7 @@ // Copyright 2014-2020 David Robillard <d@drobilla.net> // SPDX-License-Identifier: ISC -#include "zix/common.h" +#include "zix/status.h" const char* zix_strerror(const ZixStatus status) diff --git a/src/thread.c b/src/thread.c index c13f2ab..9b8af20 100644 --- a/src/thread.c +++ b/src/thread.c @@ -5,7 +5,7 @@ #include "errno_status.h" -#include "zix/common.h" +#include "zix/status.h" #ifdef _WIN32 # include <windows.h> @@ -3,7 +3,8 @@ #include "zix/tree.h" -#include "zix/common.h" +#include "zix/function_types.h" +#include "zix/status.h" #include <assert.h> @@ -14,7 +15,7 @@ struct ZixTreeImpl { ZixTreeNode* root; ZixDestroyFunc destroy; const void* destroy_user_data; - ZixComparator cmp; + ZixCompareFunc cmp; void* cmp_data; size_t size; bool allow_duplicates; @@ -52,7 +53,7 @@ zix_tree_noop_destroy(void* const ptr, const void* const user_data) ZixTree* zix_tree_new(ZixAllocator* const allocator, bool allow_duplicates, - ZixComparator cmp, + ZixCompareFunc cmp, void* cmp_data, ZixDestroyFunc destroy, const void* destroy_user_data) diff --git a/test/headers/test_headers.c b/test/headers/test_headers.c index 43c5482..80a1852 100644 --- a/test/headers/test_headers.c +++ b/test/headers/test_headers.c @@ -6,11 +6,12 @@ #include "zix/bitset.h" // IWYU pragma: keep #include "zix/btree.h" // IWYU pragma: keep #include "zix/bump_allocator.h" // IWYU pragma: keep -#include "zix/common.h" // IWYU pragma: keep #include "zix/digest.h" // IWYU pragma: keep +#include "zix/function_types.h" // IWYU pragma: keep #include "zix/hash.h" // IWYU pragma: keep #include "zix/ring.h" // IWYU pragma: keep #include "zix/sem.h" // IWYU pragma: keep +#include "zix/status.h" // IWYU pragma: keep #include "zix/thread.h" // IWYU pragma: keep #include "zix/tree.h" // IWYU pragma: keep diff --git a/test/test_btree.c b/test/test_btree.c index 63224a8..259bb2a 100644 --- a/test/test_btree.c +++ b/test/test_btree.c @@ -10,7 +10,7 @@ #include "zix/allocator.h" #include "zix/attributes.h" -#include "zix/common.h" +#include "zix/status.h" #include <assert.h> #include <inttypes.h> diff --git a/test/test_hash.c b/test/test_hash.c index 287dbaa..5101aa8 100644 --- a/test/test_hash.c +++ b/test/test_hash.c @@ -11,9 +11,9 @@ #include "zix/allocator.h" #include "zix/attributes.h" -#include "zix/common.h" #include "zix/digest.h" #include "zix/hash.h" +#include "zix/status.h" #include <assert.h> #include <inttypes.h> diff --git a/test/test_sem.c b/test/test_sem.c index 9517659..0118f50 100644 --- a/test/test_sem.c +++ b/test/test_sem.c @@ -4,8 +4,8 @@ #undef NDEBUG #include "zix/attributes.h" -#include "zix/common.h" #include "zix/sem.h" +#include "zix/status.h" #include "zix/thread.h" #include <assert.h> diff --git a/test/test_status.c b/test/test_status.c index a47181c..ca47d6e 100644 --- a/test/test_status.c +++ b/test/test_status.c @@ -3,7 +3,7 @@ #undef NDEBUG -#include "zix/common.h" +#include "zix/status.h" #include <assert.h> #include <stdio.h> diff --git a/test/test_tree.c b/test/test_tree.c index 1e4173d..f227143 100644 --- a/test/test_tree.c +++ b/test/test_tree.c @@ -8,7 +8,7 @@ #include "zix/allocator.h" #include "zix/attributes.h" -#include "zix/common.h" +#include "zix/status.h" #include "zix/tree.h" #include <assert.h> |