Skip to content

Commit 99d3ade

Browse files
Merge pull request #23 from borgbackup/misc
misc. changes
2 parents fa2cf4a + d4b8d46 commit 99d3ade

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

README.rst

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,29 @@ HashTable / HashTableNT have an API similar to a dict:
9494
- ``items()``, ``len()``
9595
- ``read()``, ``write()``, ``size()``
9696

97+
Example code
98+
------------
99+
100+
::
101+
102+
# HashTableNT mapping 256bit key [bytes] --> Chunk value [namedtuple]
103+
Chunk = namedtuple("Chunk", ["refcount", "size"])
104+
# 256bit (32Byte) key, 2x 32bit (4Byte) values
105+
ht = HashTableNT(key_size=32, value_format="<II", value_type=Chunk)
106+
107+
key = b"x" * 32 # the key is usually from a cryptographic hash fn
108+
value = Chunk(refcount=1, size=42)
109+
ht[key] = value
110+
assert ht[key] == value
111+
112+
for key, value in ht.items():
113+
assert isinstance(key, bytes)
114+
assert isinstance(value, Chunk)
115+
116+
file = "dump.bin" # giving an fd of a file opened in binary mode also works
117+
ht.write(file)
118+
ht = HashTableNT.read(file)
119+
97120
Want a demo?
98121
------------
99122

0 commit comments

Comments
 (0)