summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2022-11-02 16:30:44 -0400
committerDavid Robillard <d@drobilla.net>2022-11-02 17:31:55 -0400
commitdedf8b645ad676e7947c83f320198d43f4341570 (patch)
treed0bb9cf6033437020e8e75aa8f7d6bbe8b4b51c0
parent4f454ff117cac82c4ce86fc22d37fd317e925a18 (diff)
downloadzix-dedf8b645ad676e7947c83f320198d43f4341570.tar.gz
zix-dedf8b645ad676e7947c83f320198d43f4341570.tar.bz2
zix-dedf8b645ad676e7947c83f320198d43f4341570.zip
Remove function_types.h
-rw-r--r--doc/Doxyfile.in1
-rw-r--r--include/zix/btree.h38
-rw-r--r--include/zix/function_types.h33
-rw-r--r--include/zix/tree.h22
-rw-r--r--include/zix/zix.h1
-rw-r--r--meson.build1
-rw-r--r--src/btree.c70
-rw-r--r--src/tree.c21
-rw-r--r--test/cpp/test_headers_cpp.cpp1
-rw-r--r--test/headers/test_headers.c1
10 files changed, 83 insertions, 106 deletions
diff --git a/doc/Doxyfile.in b/doc/Doxyfile.in
index 92730af..13e8ca0 100644
--- a/doc/Doxyfile.in
+++ b/doc/Doxyfile.in
@@ -56,7 +56,6 @@ INPUT = @ZIX_SRCDIR@/include/zix/zix.h \
@ZIX_SRCDIR@/include/zix/bump_allocator.h \
\
@ZIX_SRCDIR@/include/zix/digest.h \
- @ZIX_SRCDIR@/include/zix/function_types.h \
\
@ZIX_SRCDIR@/include/zix/bitset.h \
@ZIX_SRCDIR@/include/zix/btree.h \
diff --git a/include/zix/btree.h b/include/zix/btree.h
index 05b520e..f3b365a 100644
--- a/include/zix/btree.h
+++ b/include/zix/btree.h
@@ -6,7 +6,6 @@
#include "zix/allocator.h"
#include "zix/attributes.h"
-#include "zix/function_types.h"
#include "zix/status.h"
#include <stdbool.h>
@@ -40,6 +39,15 @@ typedef struct ZixBTreeImpl ZixBTree;
/// A B-Tree node (opaque)
typedef struct ZixBTreeNodeImpl ZixBTreeNode;
+/// Function for comparing two B-Tree elements
+typedef int (*ZixBTreeCompareFunc)(const void* ZIX_UNSPECIFIED a,
+ const void* ZIX_UNSPECIFIED b,
+ const void* ZIX_UNSPECIFIED user_data);
+
+/// Function to destroy a B-Tree element
+typedef void (*ZixBTreeDestroyFunc)(void* ZIX_UNSPECIFIED ptr,
+ const void* ZIX_UNSPECIFIED user_data);
+
/**
An iterator over a B-Tree.
@@ -72,9 +80,9 @@ static const ZixBTreeIter zix_btree_end_iter = {
*/
ZIX_API
ZixBTree* ZIX_ALLOCATED
-zix_btree_new(ZixAllocator* ZIX_NULLABLE allocator,
- ZixCompareFunc ZIX_NONNULL cmp,
- const void* ZIX_NULLABLE cmp_data);
+zix_btree_new(ZixAllocator* ZIX_NULLABLE allocator,
+ ZixBTreeCompareFunc ZIX_NONNULL cmp,
+ const void* ZIX_UNSPECIFIED cmp_data);
/**
Free `t` and all the nodes it contains.
@@ -88,9 +96,9 @@ zix_btree_new(ZixAllocator* ZIX_NULLABLE allocator,
*/
ZIX_API
void
-zix_btree_free(ZixBTree* ZIX_NULLABLE t,
- ZixDestroyFunc ZIX_NULLABLE destroy,
- const void* ZIX_NULLABLE destroy_user_data);
+zix_btree_free(ZixBTree* ZIX_NULLABLE t,
+ ZixBTreeDestroyFunc ZIX_NULLABLE destroy,
+ const void* ZIX_NULLABLE destroy_user_data);
/**
Clear everything from `t`, leaving it empty.
@@ -104,9 +112,9 @@ zix_btree_free(ZixBTree* ZIX_NULLABLE t,
*/
ZIX_API
void
-zix_btree_clear(ZixBTree* ZIX_NONNULL t,
- ZixDestroyFunc ZIX_NULLABLE destroy,
- const void* ZIX_NULLABLE destroy_user_data);
+zix_btree_clear(ZixBTree* ZIX_NONNULL t,
+ ZixBTreeDestroyFunc ZIX_NULLABLE destroy,
+ const void* ZIX_NULLABLE destroy_user_data);
/// Return the number of elements in `t`
ZIX_PURE_API
@@ -164,11 +172,11 @@ zix_btree_find(const ZixBTree* ZIX_NONNULL t,
*/
ZIX_API
ZixStatus
-zix_btree_lower_bound(const ZixBTree* ZIX_NONNULL t,
- ZixCompareFunc ZIX_NULLABLE compare_key,
- const void* ZIX_NULLABLE compare_key_user_data,
- const void* ZIX_UNSPECIFIED key,
- ZixBTreeIter* ZIX_NONNULL ti);
+zix_btree_lower_bound(const ZixBTree* ZIX_NONNULL t,
+ ZixBTreeCompareFunc ZIX_NULLABLE compare_key,
+ const void* ZIX_NULLABLE compare_key_user_data,
+ const void* ZIX_UNSPECIFIED key,
+ ZixBTreeIter* ZIX_NONNULL ti);
/// Return the data at the given position in the tree
ZIX_PURE_API
diff --git a/include/zix/function_types.h b/include/zix/function_types.h
deleted file mode 100644
index d0c7193..0000000
--- a/include/zix/function_types.h
+++ /dev/null
@@ -1,33 +0,0 @@
-// 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>
-
-ZIX_BEGIN_DECLS
-
-/**
- @defgroup zix_function_types Function Types
- @ingroup zix_utilities
- @{
-*/
-
-/// 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);
-
-/**
- @}
-*/
-
-ZIX_END_DECLS
-
-#endif /* ZIX_FUNCTION_TYPES_H */
diff --git a/include/zix/tree.h b/include/zix/tree.h
index 8114c97..1b5c4ec 100644
--- a/include/zix/tree.h
+++ b/include/zix/tree.h
@@ -6,7 +6,6 @@
#include "zix/allocator.h"
#include "zix/attributes.h"
-#include "zix/function_types.h"
#include "zix/status.h"
#include <stdbool.h>
@@ -26,15 +25,24 @@ typedef struct ZixTreeImpl ZixTree;
/// An iterator over a @ref ZixTree
typedef struct ZixTreeNodeImpl ZixTreeIter;
+/// Function for comparing two Tree elements
+typedef int (*ZixTreeCompareFunc)(const void* ZIX_UNSPECIFIED a,
+ const void* ZIX_UNSPECIFIED b,
+ const void* ZIX_UNSPECIFIED user_data);
+
+/// Function to destroy a Tree element
+typedef void (*ZixTreeDestroyFunc)(void* ZIX_UNSPECIFIED ptr,
+ const void* ZIX_UNSPECIFIED user_data);
+
/// Create a new (empty) tree
ZIX_API
ZixTree* ZIX_ALLOCATED
-zix_tree_new(ZixAllocator* ZIX_NULLABLE allocator,
- bool allow_duplicates,
- ZixCompareFunc ZIX_NONNULL cmp,
- void* ZIX_UNSPECIFIED cmp_data,
- ZixDestroyFunc ZIX_NULLABLE destroy,
- const void* ZIX_NULLABLE destroy_user_data);
+zix_tree_new(ZixAllocator* ZIX_NULLABLE allocator,
+ bool allow_duplicates,
+ ZixTreeCompareFunc ZIX_NONNULL cmp,
+ void* ZIX_UNSPECIFIED cmp_data,
+ ZixTreeDestroyFunc ZIX_NULLABLE destroy,
+ const void* ZIX_NULLABLE destroy_user_data);
/// Free `t`
ZIX_API
diff --git a/include/zix/zix.h b/include/zix/zix.h
index b144cee..db54ce4 100644
--- a/include/zix/zix.h
+++ b/include/zix/zix.h
@@ -18,7 +18,6 @@
#include "zix/attributes.h"
#include "zix/digest.h"
-#include "zix/function_types.h"
#include "zix/status.h"
#include "zix/string_view.h"
diff --git a/meson.build b/meson.build
index bc084b4..1cf503c 100644
--- a/meson.build
+++ b/meson.build
@@ -195,7 +195,6 @@ c_headers = files(
'include/zix/bump_allocator.h',
'include/zix/digest.h',
'include/zix/filesystem.h',
- 'include/zix/function_types.h',
'include/zix/hash.h',
'include/zix/path.h',
'include/zix/ring.h',
diff --git a/src/btree.c b/src/btree.c
index 30a1538..83ed5eb 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;
- ZixCompareFunc cmp;
- const void* cmp_data;
- size_t size;
+ ZixAllocator* allocator;
+ ZixBTreeNode* root;
+ ZixBTreeCompareFunc 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 ZixCompareFunc cmp,
- const void* const cmp_data)
+zix_btree_new(ZixAllocator* const allocator,
+ const ZixBTreeCompareFunc cmp,
+ const void* const cmp_data)
{
#if !((defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L) || \
(defined(__cplusplus) && __cplusplus >= 201103L))
@@ -120,10 +120,10 @@ zix_btree_new(ZixAllocator* const allocator,
}
static void
-zix_btree_free_children(ZixBTree* const t,
- ZixBTreeNode* const n,
- const ZixDestroyFunc destroy,
- const void* const destroy_user_data)
+zix_btree_free_children(ZixBTree* const t,
+ ZixBTreeNode* const n,
+ const ZixBTreeDestroyFunc destroy,
+ const void* const destroy_user_data)
{
if (!n->is_leaf) {
for (ZixShort i = 0; i < n->n_vals + 1U; ++i) {
@@ -147,9 +147,9 @@ zix_btree_free_children(ZixBTree* const t,
}
void
-zix_btree_free(ZixBTree* const t,
- const ZixDestroyFunc destroy,
- const void* const destroy_user_data)
+zix_btree_free(ZixBTree* const t,
+ const ZixBTreeDestroyFunc destroy,
+ const void* const destroy_user_data)
{
if (t) {
zix_btree_clear(t, destroy, destroy_user_data);
@@ -159,9 +159,9 @@ zix_btree_free(ZixBTree* const t,
}
void
-zix_btree_clear(ZixBTree* const t,
- ZixDestroyFunc destroy,
- const void* destroy_user_data)
+zix_btree_clear(ZixBTree* const t,
+ ZixBTreeDestroyFunc destroy,
+ const void* destroy_user_data)
{
zix_btree_free_children(t, t->root, destroy, destroy_user_data);
@@ -288,12 +288,12 @@ zix_btree_node_is_sorted_with_respect_to(const ZixCompareFunc compare,
#endif
static unsigned
-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)
+zix_btree_find_value(const ZixBTreeCompareFunc 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 ZixCompareFunc compare,
}
static unsigned
-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)
+zix_btree_find_pattern(const ZixBTreeCompareFunc 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(
@@ -853,11 +853,11 @@ zix_btree_find(const ZixBTree* const t,
}
ZixStatus
-zix_btree_lower_bound(const ZixBTree* const t,
- const ZixCompareFunc compare_key,
- const void* const compare_key_user_data,
- const void* const key,
- ZixBTreeIter* const ti)
+zix_btree_lower_bound(const ZixBTree* const t,
+ const ZixBTreeCompareFunc compare_key,
+ const void* const compare_key_user_data,
+ const void* const key,
+ ZixBTreeIter* const ti)
{
assert(t);
assert(ti);
diff --git a/src/tree.c b/src/tree.c
index a362ea8..3c705c6 100644
--- a/src/tree.c
+++ b/src/tree.c
@@ -3,7 +3,6 @@
#include "zix/tree.h"
-#include "zix/function_types.h"
#include "zix/status.h"
#include <assert.h>
@@ -11,14 +10,14 @@
typedef struct ZixTreeNodeImpl ZixTreeNode;
struct ZixTreeImpl {
- ZixAllocator* allocator;
- ZixTreeNode* root;
- ZixDestroyFunc destroy;
- const void* destroy_user_data;
- ZixCompareFunc cmp;
- void* cmp_data;
- size_t size;
- bool allow_duplicates;
+ ZixAllocator* allocator;
+ ZixTreeNode* root;
+ ZixTreeDestroyFunc destroy;
+ const void* destroy_user_data;
+ ZixTreeCompareFunc cmp;
+ void* cmp_data;
+ size_t size;
+ bool allow_duplicates;
};
struct ZixTreeNodeImpl {
@@ -53,9 +52,9 @@ zix_tree_noop_destroy(void* const ptr, const void* const user_data)
ZixTree*
zix_tree_new(ZixAllocator* const allocator,
bool allow_duplicates,
- ZixCompareFunc cmp,
+ ZixTreeCompareFunc cmp,
void* cmp_data,
- ZixDestroyFunc destroy,
+ ZixTreeDestroyFunc destroy,
const void* destroy_user_data)
{
ZixTree* t = (ZixTree*)zix_malloc(allocator, sizeof(ZixTree));
diff --git a/test/cpp/test_headers_cpp.cpp b/test/cpp/test_headers_cpp.cpp
index 7c9a1df..d637988 100644
--- a/test/cpp/test_headers_cpp.cpp
+++ b/test/cpp/test_headers_cpp.cpp
@@ -12,7 +12,6 @@
#include "zix/bump_allocator.h" // IWYU pragma: keep
#include "zix/digest.h" // IWYU pragma: keep
#include "zix/filesystem.h" // IWYU pragma: keep
-#include "zix/function_types.h" // IWYU pragma: keep
#include "zix/hash.h" // IWYU pragma: keep
#include "zix/path.h" // IWYU pragma: keep
#include "zix/ring.h" // IWYU pragma: keep
diff --git a/test/headers/test_headers.c b/test/headers/test_headers.c
index d62dc2e..265c9a2 100644
--- a/test/headers/test_headers.c
+++ b/test/headers/test_headers.c
@@ -8,7 +8,6 @@
#include "zix/bump_allocator.h" // IWYU pragma: keep
#include "zix/digest.h" // IWYU pragma: keep
#include "zix/filesystem.h" // IWYU pragma: keep
-#include "zix/function_types.h" // IWYU pragma: keep
#include "zix/hash.h" // IWYU pragma: keep
#include "zix/path.h" // IWYU pragma: keep
#include "zix/ring.h" // IWYU pragma: keep