- class swh.perfecthash.Shard(path: str)#
Low level management for files indexed with a perfect hash table.
This class allows creating a Read Shard by adding key/object pairs and looking up the content of an object when given the key.
Initialize with an existing Read Shard.
path – path to an existing Read Shard file or device
- static key_len()#
- create(objects_count: int) Shard #
Wipe out the content of the Read Shard. It must be followed by object_count calls to the write method otherwise the content of the Read Shard will be inconsistent. When all objects are inserted, the Read Shard must be made persistent by calling the save method.
objects_count – number of objects in the Read Shard.
- save() int #
Create the perfect hash table the lookup method relies on to find the content of the objects.
It must be called after create and write otherwise the content of the Read Shard will be inconsistent.
0 on success, -1 on error.
- lookup(key: Key) HashObject #
Fetch the object matching the key in the Read Shard.
Fetching an object is O(1): one lookup in the index to obtain the offset of the object in the Read Shard and one read to get the payload.
key – the key associated with the object to retrieve.
the object as bytes.