summaryrefslogtreecommitdiff
path: root/BTree/btree.h
diff options
context:
space:
mode:
authorCarlos Maiolino <[email protected]>2025-07-10 22:55:07 +0200
committerCarlos Maiolino <[email protected]>2025-07-10 22:56:55 +0200
commitd98f46ce647846b0aa30b2e16a30fd4e152a1bf5 (patch)
tree267474fcc77cf20b428f6f4c7f768ca09f4cfe0e /BTree/btree.h
parent869e68986aa8f69af6e7842260a68d1e5c6f796f (diff)
Add new code
Signed-off-by: Carlos Maiolino <[email protected]>
Diffstat (limited to 'BTree/btree.h')
-rw-r--r--BTree/btree.h43
1 files changed, 43 insertions, 0 deletions
diff --git a/BTree/btree.h b/BTree/btree.h
new file mode 100644
index 0000000..0acdb15
--- /dev/null
+++ b/BTree/btree.h
@@ -0,0 +1,43 @@
+#include <sys/types.h>
+#include <stdbool.h>
+#include <unistd.h>
+
+/* Hardcoded BTree order */
+#define BT_ORDER 3
+
+/* Btree is an index of this structure */
+struct Data {
+ int id;
+ char name[20];
+};
+
+struct BTree_node {
+ bool is_leaf; /* Is this a leaf block? */
+ int num_recs;
+ int key_idx[BT_ORDER];
+
+ /* Points to next level when node or to data when leaf */
+ void *ptrs[BT_ORDER];
+};
+
+struct BTree_head {
+ struct BTree_node *root; /* root pointer */
+ unsigned int height; /* How many levels? */
+ unsigned int order; /* BTree order */
+ unsigned int num_recs; /* num of entrys in the tree */
+};
+
+struct BTree_head * init_head(void);
+void destroy_head(struct BTree_head *head);
+
+/*
+ * BTree Operations:
+ *
+ * All operations Return 0 for success, non zero otherwise
+ *
+ */
+int btree_add(struct Data* item);
+int btree_delete(void);
+int btree_search(void);
+int btree_dump(void);
+void usage(void);