From d98f46ce647846b0aa30b2e16a30fd4e152a1bf5 Mon Sep 17 00:00:00 2001 From: Carlos Maiolino Date: Thu, 10 Jul 2025 22:55:07 +0200 Subject: Add new code Signed-off-by: Carlos Maiolino --- Algorithms/bplus-tree/include/bplus_tree.h | 63 ++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 Algorithms/bplus-tree/include/bplus_tree.h (limited to 'Algorithms/bplus-tree/include') diff --git a/Algorithms/bplus-tree/include/bplus_tree.h b/Algorithms/bplus-tree/include/bplus_tree.h new file mode 100644 index 0000000..7bb3e1d --- /dev/null +++ b/Algorithms/bplus-tree/include/bplus_tree.h @@ -0,0 +1,63 @@ +/** + * Distributed under the Boost Software License, Version 1.0. + * See accompanying file LICENSE or copy at http://www.boost.org/LICENSE_1_0.txt + */ + +#ifndef __BPLUS_TREE_H__ +#define __BPLUS_TREE_H__ + +#include +#include + +#include + +#ifdef __cplusplus +extern "C" +{ +#endif /* __cplusplus */ + +typedef uint64_t BplusKey; +typedef void* BplusValue; +typedef struct _BplusItem BplusItem; + +struct _BplusItem +{ + BplusKey key; + BplusValue value; +}; + +typedef struct _BplusTree BplusTree; +typedef struct _BplusIterator BplusIterator; + +typedef void (BplusForeachItemFunc)(BplusTree const* tree, BplusItem* item, void* argument); + +BplusTree* bplus_tree_new(); +BplusTree* bplus_tree_new_full(gboolean allow_duplicate_keys); +void bplus_tree_destroy(BplusTree* tree); +void bplus_tree_destroy_each(BplusTree* tree, BplusForeachItemFunc* foreach, void* argument); + +void bplus_tree_insert(BplusTree* tree, BplusKey const key, BplusValue const value); +BplusValue bplus_tree_remove(BplusTree* tree, BplusKey const key); +BplusValue bplus_tree_remove_first(BplusTree* tree); +void bplus_tree_remove_value(BplusTree* tree, BplusKey const key, BplusValue const value); +BplusValue bplus_tree_get(BplusTree* tree, BplusKey const key); + +BplusValue bplus_tree_get_first(BplusTree const* tree); +BplusValue bplus_tree_get_nth(BplusTree const* tree, size_t position); + +BplusIterator* bplus_iterator_new(BplusTree const* tree); +void bplus_iterator_destroy(BplusIterator* iterator); +gboolean bplus_iterator_next(BplusIterator* iterator); +gboolean bplus_iterator_previous(BplusIterator* iterator); +BplusItem const* bplus_iterator_get_item(BplusIterator const* iterator); +BplusIterator* bplus_tree_first(BplusTree const* tree); +BplusIterator* bplus_iterator_from_key(BplusTree const* tree, BplusKey const key); +BplusIterator* bplus_iterator_to_key(BplusTree const* tree, BplusKey const key); +BplusIterator* bplus_iterator_for_key(BplusTree const* tree, BplusKey const key); +BplusIterator* bplus_iterator_for_key_range(BplusTree const* tree, BplusKey const key_from, BplusKey const key_to); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif // ifndef __BPLUS_TREE_H__ -- cgit v1.2.3