-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmydb.h
More file actions
52 lines (47 loc) · 1.45 KB
/
mydb.h
File metadata and controls
52 lines (47 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include <stddef.h>
/* check `man dbopen` */
struct DBT {
void *data;
size_t size;
};
struct DB {
/* Public API */
/* Returns 0 on OK, -1 on Error */
int (*close)(struct DB *db);
int (*del)(struct DB *db, struct DBT *key);
/* * * * * * * * * * * * * *
* Returns malloc'ed data into 'struct DBT *data'.
* Caller must free data->data. 'struct DBT *data' must be alloced in
* caller.
* * * * * * * * * * * * * */
int (*get)(struct DB *db, struct DBT *key, struct DBT *data);
int (*put)(struct DB *db, struct DBT *key, struct DBT *data);
/* For future uses - sync cached pages with disk
* int (*sync)(const struct DB *db)
* */
/* Private API */
/* ... */
}; /* Need for supporting multiple backends (HASH/BTREE) */
struct DBC {
/* Maximum on-disk file size
* 512MB by default
* */
size_t db_size;
/* Maximum chunk (node/data chunk) size
* 4KB by default
* */
size_t chunk_size;
/* For future uses - maximum cached memory size
* 16MB by default
* size_t mem_size; */
};
/* don't store metadata in the file */
struct DB *dbcreate(char *file, struct DBC conf);
struct DB *dbopen (char *file, struct DBC conf);
int db_close(struct DB *db);
int db_del(struct DB *, void *, size_t);
int db_get(struct DB *, void *, size_t, void **, size_t *);
int db_put(struct DB *, void *, size_t, void * , size_t );
/* For future uses - sync cached pages with disk
* int db_sync(const struct DB *db);
* */