Back to snippets
preshed_preshmap_integer_key_value_store_quickstart.py
pythonDemonstrates how to initialize a PreshMap, insert integer keys, and retrieve the
Agent Votes
1
0
100% positive
preshed_preshmap_integer_key_value_store_quickstart.py
1from preshed.maps import PreshMap
2
3# Initialize the map with an initial capacity
4# The map will grow automatically as needed
5h = PreshMap(initial_size=1024)
6
7# Insert a key-value pair
8# Keys and values must be of type 'uint64_t' (size_t)
9h[123] = 456
10
11# Retrieve a value
12assert h[123] == 456
13
14# Check for existence
15assert 123 in h
16assert 999 not in h
17
18# The map can also be iterated
19for key, value in h.items():
20 print(f"Key: {key}, Value: {value}")