File tree Expand file tree Collapse file tree 2 files changed +23
-0
lines changed
Expand file tree Collapse file tree 2 files changed +23
-0
lines changed Original file line number Diff line number Diff 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+
97120Want a demo?
98121------------
99122
File renamed without changes.
You can’t perform that action at this time.
0 commit comments