-
Notifications
You must be signed in to change notification settings - Fork 5
/
README
56 lines (44 loc) · 1.5 KB
/
README
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
A library that implements sorted string tables with fixed size payload in Python.
Structure of SSTable file:
* 16 bytes of header (see below)
* Array of offsets. Each offset points to start of the string. For the first string offset = 0.
* One extra offset equals points to the byte right after last string+payload
* Strings. Each string is followed by payload, to calculate size of string
calculate difference between current and next offsets and decrease by size of payload
Header format:
* 8 bytes: magic
* 2 bytes: version
* 2 bytes: size of extra structure
* 4 bytes: number of strings inside
All numbers inside are unsigned, all counters and offsets are integers
EXAMPLE:
# Create a string with 5 keys inside
# payload size = 10
buf = struct.pack("8sHHIIIIIII15s15s15s15s15s", "YPySSTbl", 1, 10, 5, 0, 15, 30, 45, 60, 75, "AAkey0123456789", "FFKeyFFFFFFFFFf", "MMKey9876543210", "QQKeyQQQQQQQQQq", "zzKeyABCDEFGHIJ")
s = sstable(buf)
s.load()
# Search for a key
print s.search("zzKey")
# Overwrite key
s.insert("zzKey", "0011223344", True)
print s.search("zzKey")
# Reinitialize sstable, set payload size = 10
s.init(10)
# Insert some keys
s.insert("zzKey", "ABCDEFGHIJ")
print s.search("zzKey")
s.insert("QQKey", "QQQQQQQQQq")
# Check keys inserted at the beginning
print s.search("zzKey")
print s.search("QQKey")
# Delete it and check again
s.delete("QQKey")
print s.search("zzKey")
try:
print s.search("QQKey")
except KeyError as e:
print e
try:
s.delete("QQKey")
except KeyError as e:
print e