summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--source/query/query.c0
-rw-r--r--source/query/query.h0
-rw-r--r--source/storage/b_tree.c34
-rw-r--r--source/storage/b_tree.h44
-rw-r--r--source/storage/table.c0
-rw-r--r--source/storage/table.h0
-rw-r--r--sources.txt12
7 files changed, 90 insertions, 0 deletions
diff --git a/source/query/query.c b/source/query/query.c
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/source/query/query.c
diff --git a/source/query/query.h b/source/query/query.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/source/query/query.h
diff --git a/source/storage/b_tree.c b/source/storage/b_tree.c
new file mode 100644
index 0000000..4b42496
--- /dev/null
+++ b/source/storage/b_tree.c
@@ -0,0 +1,34 @@
1
2// TODO(nasr):
3// 1. splitting the tree when getting too big? (horizontally)
4// 2. joining trees?
5
6
7internal void
8b_tree_create(mem_arena *arena, u16 order)
9{
10
11
12}
13
14// NOTE(nasr): nodes that get passed as parameters should've already been loaded into memory
15internal void
16b_tree_search(node *node)
17{
18
19
20}
21
22internal void
23b_tree_insert()
24{
25
26}
27
28internal void
29b_tree_write()
30{
31 // TODO(nasr): write the b_tree to disk
32}
33
34
diff --git a/source/storage/b_tree.h b/source/storage/b_tree.h
new file mode 100644
index 0000000..10ad00d
--- /dev/null
+++ b/source/storage/b_tree.h
@@ -0,0 +1,44 @@
1#ifndef BTREE_H
2#define BTREE_H
3
4// maximum height of the tree the lower the lower the lower amount
5// of disk reads which translates into faster?
6#define B_TREE_ORDER 4
7
8typedef struct b_tree_node b_tree_node;
9struct b_tree_node
10{
11
12 // store the values
13 string8 keys[B_TREE_ORDER - 1];
14 csv_row *rows[B_TREE_ORDER - 1];
15
16 b_tree_node *parent;
17 // handle to store children faster than linked list
18 // because now we can iteratate over the nodes instead of having cache misses
19 // when jumping through linked nodes
20 b_tree_node *children[B_TREE_ORDER];
21
22 // NOTE(nasr): reference count ::: check how many leaves are using this node
23 // also not needed for now because we don't free individual node because of arena allocator
24 // i32 *refc;
25
26 i32 key_count;
27
28 b32 leaf;
29
30};
31
32typedef struct b_tree b_tree;
33struct b_tree
34{
35 // NOTE(nasr): make sure this always stays in memory
36 // so that initial fetch never requires a disk read
37 b_tree_node *root;
38
39};
40
41
42
43
44#endif /* BTREE_H */
diff --git a/source/storage/table.c b/source/storage/table.c
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/source/storage/table.c
diff --git a/source/storage/table.h b/source/storage/table.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/source/storage/table.h
diff --git a/sources.txt b/sources.txt
new file mode 100644
index 0000000..18b491b
--- /dev/null
+++ b/sources.txt
@@ -0,0 +1,12 @@
1 https://www.geeksforgeeks.org/dsa/introduction-of-b-tree-2/
2 github.com/tsoding/sv/blob/master/sv.h
3 https://github.com/semitrivial/csv_parser
4
5 Introduction to Algorithms, Fourth Edition
6 ISBN-10 : 026204630X
7 ISBN-13 : 978-0262046305
8
9 chapter 18: B-Trees
10
11
12 https://github.com/tidwall/btree.c/blob/master/btree.c