YACDB
Yet Another C(rappy) Database
diskio.h
Go to the documentation of this file.
1
9#pragma once
10#include <assert.h>
11#include <stdio.h>
12#include <stdbool.h>
13#include <string.h>
14#include <sys/types.h>
15#include <unistd.h>
16#include "db_structs.h"
17#include "../../schema/include/record.h"
18
19// #define ORDER 4
20#define ORDER 4
21
28typedef unsigned long Key;
29
31{
32 Page page;
33 struct linked_overflow *next;
34};
35
37{
38 Key key;
39 void *value;
40 size_t size;
41
42 // Private field please ignore
43 struct linked_overflow *overflow;
44};
45
50struct node
51{
52 Page parent_addr;
53
54 enum page_type type;
55 size_t nb_keys;
56 struct key_value *key_vals[ORDER + 1];
57 Page child_addrs[ORDER + 2];
58};
59
65{
66 struct cached_node *next;
67 struct node *node;
68 Page addr;
69};
70
74struct yacdb db;
78bool is_leaf(struct node *node);
79
87struct node *read_node(Page addr);
88
92int write_node(struct node *node, Page addr);
93
97int remove_node(Page addr);
98
103
107int init_db();
108
109struct node *create_node();
110
115int add_to_cache(struct node *node, Page addr);
116
123struct node *get_from_cache(Page addr);
124
128int remove_node_from_cache(struct cached_node *last_node);
129
133void free_node(struct node *node);
Structures for interacting with the database.
size_t Page
A address to a page.
Definition: db_structs.h:18
struct node * get_from_cache(Page addr)
Get a node from the cache. This node will be a copy of the node in the cache.
Definition: diskio.c:1004
int add_to_cache(struct node *node, Page addr)
Adds a node to the beginning of the linked list that is cache. If the size of cache is greater than t...
Definition: diskio.c:935
int remove_node_from_cache(struct cached_node *last_node)
Removes a node from cache, erasing it permanently.
Definition: diskio.c:921
int remove_node(Page addr)
Removes a node from disk at a given address. If an error occurs returns -1.
Definition: diskio.c:508
void free_node(struct node *node)
Free's a node.
Definition: diskio.c:1040
struct yacdb db
The database.
Definition: diskio.h:74
bool is_leaf(struct node *node)
Verifies if the node is a leaf.
Definition: diskio.c:4
struct node * read_node(Page addr)
Reads a node from disk at a given address.
Definition: diskio.c:259
Page create_addr()
Creates an address for a new node. If an error occurs returns -1.
Definition: diskio.c:394
int write_node(struct node *node, Page addr)
Writes a node to disk (or cache) at a given address. If an error occurs returns -1.
Definition: diskio.c:745
unsigned long Key
A key to a record.
Definition: diskio.h:28
int init_db()
initializes the database
Definition: diskio.c:764
A struct for holding cached nodes.
Definition: diskio.h:65
Definition: diskio.h:37
Definition: diskio.h:31
The basic structure stored in memory.
Definition: diskio.h:51
struct key_value * key_vals[ORDER+1]
+1 for when handling splits
Definition: diskio.h:56
Definition: db_structs.h:47