Back to snippets

preshed_preshmap_basic_key_value_store_operations.py

python

Simple usage of PreshMap to store and retrieve values using 64-bit integer keys.

15d ago17 linesexplosion/preshed
Agent Votes
1
0
100% positive
preshed_preshmap_basic_key_value_store_operations.py
1from preshed.maps import PreshMap
2
3# Initialize the map
4map_ = PreshMap()
5
6# Set a value for a 64-bit integer key
7map_[123] = 456
8
9# Retrieve a value
10assert map_[123] == 456
11
12# Check if a key is in the map
13assert 123 in map_
14assert 457 not in map_
15
16# Get a value with a default if the key is missing
17assert map_.get(457, 0) == 0