-
Notifications
You must be signed in to change notification settings - Fork 25
/
README.txt
146 lines (114 loc) · 3.82 KB
/
README.txt
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
A New DBM in Pure C
Demo:
=====
db_t db;
db_option_t option;
option.table = 256; /* table number,keep this small if data not too much */
option.bucket = 256; /* initialize bucket number in per table,will incrase when key add */
option.rdonly = 0;
if (db_open(&db, /* data file */ "foo.db", /* index file */ "foo.db", &option) != DB_OK) {
fprintf(stderr, "open db failed\n");
return 0;
}
if (db_put(&db, "hi", strlen(...), "hello,world", strlen(...)) != DB_OK) {
fprintf(stderr, "NOT OK\n");
}
if ((len = db_get(&db, "hi", strlen(...), val, sizeof(val))) == 0) {
fprintf(stderr, "NOT FOUND\n");
}
db_close(&db);
Limited:
========
In 32 bit platform database file size is limited 4GiB*
Key/Value length is 32 bit unsigned int
*Depends Your Operation System,Mostly can't get 4GiB map
Design:
=======
+----------+
| |
| header |
| |
+----------+
| table[0] |---------+
+----------+ |
| table[1] |------------+
+----------+ | |
| table[2] | | |
+----------+ | |
| . | | |
| . | | |
| . | | |
+----------+ | |
| table[N] | | |
+----------+ | |
+-----| bucket[0]|<--------| |
| +----------+ |
| | bucket[1]| |
| +----------+ |
+--------| bucket[2]| |
| | +----------+ |
| | | . | |
| | | . |<-----------+
| | | . |
| | +----------+
| | | bucket[N]|
| | +----------+
| +---->| klen |
| +----------+
| | vlen |
| +----------+
| | . |
| | klen |
| | bytes |
| | . |
| +----------+
| | . |
| | vlen |
| | bytes |
| | . |
| +----------+
+------->| klen |
+----------+
| vlen |
+----------+
| . |
| klen |
| bytes |
| . |
+----------+
| . |
| vlen |
| bytes |
| . |
+----------+
| . |
| . |
| . |
+----------+
Goal:
=====
Keep it simple, stupid
Next Release will has Dynamic Hash Implementation*
And Mmap Maybe not required.
*Litwin, Witold (1980), "Linear hashing: A new tool for file and table addressing"
FAQ:
====
Q: Do you use `mmap'? What if I don't want use `mmap'?
A: Yes.Just use others,there is a lot of key/value database you can choose.
Q: I tried this library,It's waste to much disk space and memory!
A: I'll write compaction function later,will reduce disk space in high update application,you can use db-export and db-import to a new database file.The future compaction function will do same thing.Memory is control by the kernel,Sorry.
Q: Compression?
A: Maybe.
Q: Encryption?
A: Maybe.
Q: I use this in my Web Server,I have a problem!
A: Please contact the author.
Q: I use this in my Mobile Phone,I have a problem!
A: Please contact the author.
Q: I want do X,Will be OK?
A: Just try.If don't,Please contact the author.
Q: I have a problem!
A: Please contact the author.
License:
========
Public Domain License