Skip to content

A library that implements sorted string tables with fixed size payload in Python.

License

Notifications You must be signed in to change notification settings

toshic/python-sstable

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

A library that implements sorted string tables with fixed size payload in Python.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published