README.rst
1.. zephyr:code-sample:: system_hashmap
2 :name: System hashmap
3 :relevant-api: hashmap_apis
4
5 Insert, replace, and remove entries in a hashmap.
6
7Overview
8********
9
10This is a simple example that repeatedly:
11
12* inserts up to ``CONFIG_TEST_LIB_HASH_MAP_MAX_ENTRIES``
13* replaces up to the same number that were previously inserted
14* removes all previously inserted keys
15
16Building
17********
18
19This application can be built on :ref:`native_sim <native_sim>` as follows:
20
21.. zephyr-app-commands::
22 :zephyr-app: samples/basic/hash_map
23 :host-os: unix
24 :board: native_sim
25 :goals: build
26 :compact:
27
28To build for another board, change "native_sim" above to that board's name.
29
30Additionally, it is possible to use one of the other Hashmap implementations by specifying
31
32* ``CONFIG_SYS_HASH_MAP_CHOICE_SC=y`` (Separate Chaining)
33* ``CONFIG_SYS_HASH_MAP_CHOICE_OA_LP=y`` (Open Addressing / Linear Probe)
34* ``CONFIG_SYS_HASH_MAP_CHOICE_CXX=y`` (C Wrapper around the C++ ``std::unordered_map``)
35
36To stress the Hashmap implementation, adjust ``CONFIG_TEST_LIB_HASH_MAP_MAX_ENTRIES``.
37
38Running
39*******
40
41Run ``build/zephyr/zephyr.exe``
42
43Sample Output
44*************
45
46.. code-block:: console
47
48 System Hashmap sample
49
50 [00:00:11.000,000] <inf> hashmap_sample: n_insert: 118200 n_remove: 295500 n_replace: 329061 n_miss: 0 n_error: 0 max_size: 118200
51 [00:00:11.010,000] <inf> hashmap_sample: success
52