zephyr/samples/basic/hash_map
Alberto Escolar Piedras e807b7e1c2 samples/basic/hash_map: Remove clarification sentence
This current sentence would need to be clarified a bit
further to be really correct:
It is only when building with the host C library that it
applies, but with native_sim we can build with other
libC's.
The twister tests definitions are testing only with
embedded C libraries,
and there is anyway no harm if somebody defines the heap
size even if using the host libC.
So as such it would seem better to just remove this
sentence.

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2024-03-15 17:13:18 -04:00
..
src random: Rename random header 2023-10-10 14:23:50 +03:00
CMakeLists.txt samples: lib: os: hash_map: add Hashmap sample code 2023-02-22 19:14:05 +01:00
Kconfig samples/basic/hash_map: Remove clarification sentence 2024-03-15 17:13:18 -04:00
prj.conf samples: basic: hash_map: fix libc heap size setting 2023-07-26 14:53:51 +02:00
README.rst samples/basic: Switch from native_posix to native_sim 2023-11-14 13:06:01 +01:00
sample.yaml hwmv2: Introduce Hardware model version 2 and convert devices 2024-03-02 16:56:33 -05:00

.. zephyr:code-sample:: system_hashmap
   :name: System hashmap
   :relevant-api: hashmap_apis

   Insert, replace, and remove entries in a hashmap.

Overview
********

This is a simple example that repeatedly:

* inserts up to ``CONFIG_TEST_LIB_HASH_MAP_MAX_ENTRIES``
* replaces up to the same number that were previously inserted
* removes all previously inserted keys

Building
********

This application can be built on :ref:`native_sim <native_sim>` as follows:

.. zephyr-app-commands::
   :zephyr-app: samples/basic/hash_map
   :host-os: unix
   :board: native_sim
   :goals: build
   :compact:

To build for another board, change "native_sim" above to that board's name.

Additionally, it is possible to use one of the other Hashmap implementations by specifying

* ``CONFIG_SYS_HASH_MAP_CHOICE_SC=y`` (Separate Chaining)
* ``CONFIG_SYS_HASH_MAP_CHOICE_OA_LP=y`` (Open Addressing / Linear Probe)
* ``CONFIG_SYS_HASH_MAP_CHOICE_CXX=y`` (C Wrapper around the C++ ``std::unordered_map``)

To stress the Hashmap implementation, adjust ``CONFIG_TEST_LIB_HASH_MAP_MAX_ENTRIES``.

Running
*******

Run ``build/zephyr/zephyr.exe``

Sample Output
*************

.. code-block:: console

    System Hashmap sample

    [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
    [00:00:11.010,000] <inf> hashmap_sample: success