> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.nvidia.com/holoscan/sdk-user-guide/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.nvidia.com/holoscan/sdk-user-guide/_mcp/server.

# holoscan::pose_tree::HashMap

> A hash map implementation using open addressing with linear probing.

```cpp showLineNumbers={false}
template <typename Key, typename Value>
class HashMap
```

A hash map implementation using open addressing with linear probing.

This class provides a fixed-capacity hash map that uses pre-allocated memory and linear probing for collision resolution. It supports basic operations like insert, get, erase, and has. The hash map is designed for performance-critical scenarios where memory allocation should be minimized.

```cpp showLineNumbers={false}
#include <holoscan/pose_tree/hash_map.hpp>
```

**Template parameters**

**`Key`** `typename`

The key type for the hash map.

---

**`Value`** `typename`

The value type for the hash map.

---

---

## Constructors

### HashMap \[#hashmap]

```cpp showLineNumbers={false}
holoscan::pose_tree::HashMap<Key, Value>::HashMap() = default
```

Default constructor used to be able to pre-allocate memory.

---

## Methods

### initialize \[#initialize]

```cpp showLineNumbers={false}
expected_t<void> holoscan::pose_tree::HashMap<Key, Value>::initialize(
    int32_t size,
    int32_t capacity
)
```

Reserve memory for the hash map.

**Returns:** Success or error status.

**Parameters**

**`size`** `int32_t`

Maximum number of elements the hash map can store.

---

**`capacity`** `int32_t`

Total capacity of the internal array (should be larger than size for efficiency).

---

### has \[#has]

```cpp showLineNumbers={false}
bool holoscan::pose_tree::HashMap<Key, Value>::has(
    const Key &key
) const
```

Check if a key exists in the hash map.

**Returns:** True if the key exists, false otherwise.

**Parameters**

**`key`** `const Key &`

The key to search for.

---

### get \[#get]

```cpp showLineNumbers={false}
expected_t<Value> holoscan::pose_tree::HashMap<Key, Value>::get(
    const Key &key
) const
```

Get the value associated with a key.

**Returns:** Value associated with the key on success, Error::kKeyNotFound if key doesn't exist.

**Parameters**

**`key`** `const Key &`

The key to search for.

---

### try\_get \[#tryget]

#### Mutable

```cpp showLineNumbers={false}
expected_t<Value *> holoscan::pose_tree::HashMap<Key, Value>::try_get(
    const Key &key
)
```

Try to get the value ptr associated with a key.

**Returns:** Value associated with the key on success, Error::kKeyNotFound if key doesn't exist.

**Parameters**

**`key`** `const Key &`

The key to search for.

---

#### Const

const

```cpp showLineNumbers={false}
expected_t<const Value *> holoscan::pose_tree::HashMap<Key, Value>::try_get(
    const Key &key
) const
```

Try to get the value ptr associated with a key.

**Returns:** Value associated with the key on success, Error::kKeyNotFound if key doesn't exist.

**Parameters**

**`key`** `const Key &`

The key to search for.

---

### insert \[#insert]

#### Single element (1)

```cpp showLineNumbers={false}
expected_t<Value *> holoscan::pose_tree::HashMap<Key, Value>::insert(
    const Key &key,
    const Value &value
)
```

Insert a key-value pair into the hash map.

**Returns:** Success or error status. Error::kHashMapFull if the map is full, Error::kKeyAlreadyExists if the key already exists.

**Parameters**

**`key`** `const Key &`

The key to insert.

---

**`value`** `const Value &`

The value to associate with the key.

---

#### Single element (2)

```cpp showLineNumbers={false}
template <typename ValueType,
          typename = std::enable_if_t<!std::is_same_v<std::decay_t<ValueType>, Value>>>
expected_t<Value *> holoscan::pose_tree::HashMap<Key, Value>::insert(
    const Key &key,
    ValueType &&value
)
```

Insert a key-value pair into the hash map (perfect forwarding version).

**Returns:** Success or error status. Error::kHashMapFull if the map is full, Error::kKeyAlreadyExists if the key already exists.

**Parameters**

**`key`** `const Key &`

The key to insert.

---

**`value`** `ValueType &&`

The value to associate with the key.

---

### erase \[#erase]

```cpp showLineNumbers={false}
expected_t<void> holoscan::pose_tree::HashMap<Key, Value>::erase(
    const Key &key
)
```

Remove a key-value pair from the hash map.

**Returns:** Success or error status. Error::kKeyNotFound if the key doesn't exist.

**Parameters**

**`key`** `const Key &`

The key to remove.

---

### size \[#size]

```cpp showLineNumbers={false}
int32_t holoscan::pose_tree::HashMap<Key, Value>::size() const
```

Get the current number of elements in the hash map.

**Returns:** Current size of the hash map.

### capacity \[#capacity]

```cpp showLineNumbers={false}
int32_t holoscan::pose_tree::HashMap<Key, Value>::capacity() const
```

Get the capacity of the hash map.

**Returns:** Max capacity of the hash map.

### insert\_impl \[#insertimpl]

```cpp showLineNumbers={false}
template <typename ValueType>
expected_t<Value *> holoscan::pose_tree::HashMap<Key, Value>::insert_impl(
    const Key &key,
    ValueType &&value
)
```

Internal implementation for inserting key-value pairs.

**Returns:** Success or error status.

**Parameters**

**`key`** `const Key &`

The key to insert.

---

**`value`** `ValueType &&`

The value to associate with the key.

---

### fill\_holes \[#fillholes]

```cpp showLineNumbers={false}
void holoscan::pose_tree::HashMap<Key, Value>::fill_holes(
    int index
)
```

Fill holes in the hash table after deletion to maintain linear probing invariants.

This method is called after an element is deleted to ensure that subsequent lookups continue to work correctly with linear probing.

**Parameters**

**`index`** `int`

The index where a deletion occurred.

---

### get\_index \[#getindex]

```cpp showLineNumbers={false}
expected_t<int32_t> holoscan::pose_tree::HashMap<Key, Value>::get_index(
    const Key &key
) const
```

Get the index where the key is.

**Returns:** The index associated with the key on success, Error::kKeyNotFound if key doesn't exist.

**Parameters**

**`key`** `const Key &`

The key to search for.

---

---

## Types

### Typedefs

| Name           | Definition             | Description                         |
| -------------- | ---------------------- | ----------------------------------- |
| `expected_t`   | `expected< T, Error >` | Expected type used by this class.   |
| `unexpected_t` | `unexpected< Error >`  | Unexpected type used by this class. |
| `hash_t`       | `uint64_t`             | Hash type used internally.          |

### Error

Error codes used by this class.

| Name                | Value | Description                                                                                                                                        |
| ------------------- | ----- | -------------------------------------------------------------------------------------------------------------------------------------------------- |
| `kInvalidArgument`  |       | kInvalidArgument is returned when a function is called with argument that does not make sense such as negative size or capacity smaller than size. |
| `kOutOfMemory`      |       | kOutOfMemory is returned when a memory allocation fails.                                                                                           |
| `kHashMapFull`      |       | kHashMapFull is returned if the hash map is full.                                                                                                  |
| `kKeyNotFound`      |       | kKeyNotFound is returned if the key is not found in the hash map.                                                                                  |
| `kKeyAlreadyExists` |       | kKeyAlreadyExists is returned if the key already exists in the hash map.                                                                           |

---

## Member variables

| Name        | Type                        | Description                                        |
| ----------- | --------------------------- | -------------------------------------------------- |
| `entries_`  | `std::unique_ptr< Entry[]>` | Array of entries in the hash map.                  |
| `size_`     | `int32_t`                   | Current number of elements in the hash map.        |
| `max_size_` | `int32_t`                   | Maximum number of elements the hash map can store. |
| `capacity_` | `int32_t`                   | Total capacity of the internal array.              |

---

## Inner classes

### Entry

```cpp showLineNumbers={false}
struct holoscan::pose_tree::HashMap::Entry
```

Internal structure representing an entry in the hash map.

| Name          | Type     | Description                        |
| ------------- | -------- | ---------------------------------- |
| `hash`        | `hash_t` | Hash value of the key.             |
| `key`         | `Key`    | The key.                           |
| `is_occupied` | `bool`   | Whether this entry is occupied.    |
| `value`       | `Value`  | The value associated with the key. |