Cython hash table that trusts the keys are pre-hashed
Maintained. Last release 5 weeks ago, commits in 1 of the last 26 weeks. Weaker on commit activity and release cadence.
pip install preshedpreshed: Cython Hash Table for Pre-Hashed Keys
Simple but high performance Cython hash table mapping pre-randomized keys to
void* values. Inspired by
Jeff Preshing.
All Python APIs provded by the BloomFilter and PreshMap classes are
thread-safe on both the GIL-enabled build and the free-threaded build of Python
3.14 and newer. If you use the C API or the PreshCounter class, you must
provide external synchronization if you use the data structures by this library
in a multithreaded environment.
Installation
pip install preshed --only-binary preshed
Or with conda:
conda install -c conda-forge preshed
Usage
PreshMap
A hash map for pre-hashed keys, mapping uint64 to uint64 values.
from preshed.maps import PreshMap
map = PreshMap() # create with default size
map = PreshMap(initial_size=1024) # create with initial capacity (must be power of 2)
map[key] = value # set a value
value = map[key] # get a value (returns None if missing)
value = map.pop(key) # remove and return a value
del map[key] # delete a key
key in map # membership test
len(map) # number of entries
for key in map: # iterate over keys
pass
for key, value in map.items(): # iterate over key-value pairs
pass
for value in map.values(): # iterate over values
pass