Hash map. More...
#include "kzc_hash_code.h"
#include "kzc_comparator.h"
#include <system/kzs_types.h>
#include <system/debug/kzs_error.h>
#include <system/kzs_header.h>
#include "kzc_hash_map_accessors_h.inl"
Classes | |
struct | KzcHashMapIteratorIndexing |
Hash map iterator for unordered KzcHashMap. More... | |
struct | KzcHashMapIterator |
Iterator to the contents of a KzcHashMap. More... | |
struct | KzcHashMapConfiguration |
Configuration parameters for a KzcHashMap. More... | |
Macros | |
#define | kzcHashMapIterationBreak(hashMap) |
Break from hash map iteration - do nothing on release build. More... | |
#define | kzcHashMapIterate(iterator_param) |
Finds the next entry in the attached hash map. More... | |
#define | kzcHashMapIteratorRemove(iterator_param) |
Removes current entry of hash map pointed by the iterator. More... | |
Enumerations | |
enum | KzcHashMapKeyType { KZC_HASH_MAP_KEY_TYPE_INT, KZC_HASH_MAP_KEY_TYPE_UINT, KZC_HASH_MAP_KEY_TYPE_FLOAT, KZC_HASH_MAP_KEY_TYPE_POINTER, KZC_HASH_MAP_KEY_TYPE_STRING, KZC_HASH_MAP_KEY_TYPE_CUSTOM } |
Key type identifier for hash map. More... | |
Functions | |
kzsError | kzcHashMapCreateWithCapacity (const struct KzcMemoryManager *memoryManager, struct KzcHashMapConfiguration configuration, kzUint capacity, struct KzcHashMap **out_hashMap) |
Creates a new initially empty hash map. More... | |
kzsError | kzcHashMapCreate (const struct KzcMemoryManager *memoryManager, struct KzcHashMapConfiguration configuration, struct KzcHashMap **out_hashMap) |
Creates a new initially empty hash map with zero capacity. More... | |
kzsError | kzcHashMapCreateOrderedWithCapacity (const struct KzcMemoryManager *memoryManager, struct KzcHashMapConfiguration configuration, kzUint capacity, struct KzcHashMap **out_hashMap) |
Creates a new initially empty hash map, which ensures that the iteration order is same as the order of elements. More... | |
kzsError | kzcHashMapCreateOrdered (const struct KzcMemoryManager *memoryManager, struct KzcHashMapConfiguration configuration, struct KzcHashMap **out_hashMap) |
Creates a new initially empty hash map, which ensures that the iteration order is same as the order of elements. More... | |
kzsError | kzcHashMapDelete (struct KzcHashMap *hashMap) |
Frees the memory allocated for the hash map. More... | |
kzsError | kzcHashMapClear (struct KzcHashMap *hashMap) |
Clears the content of the hash map. More... | |
struct KzcHashMapConfiguration | kzcHashMapGetConfiguration (const struct KzcHashMap *hashMap) |
Get hash map configuration. More... | |
kzUint | kzcHashMapGetSize (const struct KzcHashMap *HashMap) |
Returns the number of entries stored in the hash map. More... | |
kzBool | kzcHashMapIsEmpty (const struct KzcHashMap *hashMap) |
Checks if the hash map is empty or not. More... | |
struct KzcHashMapIterator | kzcHashMapGetIterator (const struct KzcHashMap *hashMap) |
Returns an iterator to the hash map. More... | |
kzBool | kzcHashMapIterate_private (struct KzcHashMapIterator *iterator) |
kzsError | kzcHashMapIteratorRemove_private (struct KzcHashMapIterator *it) |
Variables | |
const struct KzcHashMapConfiguration | KZC_HASH_MAP_CONFIGURATION_INT |
Configuration for hash maps where key type is an integer. More... | |
const struct KzcHashMapConfiguration | KZC_HASH_MAP_CONFIGURATION_UINT |
Configuration for hash maps where key type is an unsigned integer. More... | |
const struct KzcHashMapConfiguration | KZC_HASH_MAP_CONFIGURATION_FLOAT |
Configuration for hash maps where key type is a float. More... | |
const struct KzcHashMapConfiguration | KZC_HASH_MAP_CONFIGURATION_POINTER |
Configuration for hash maps where key type is an arbitrary pointer. More... | |
const struct KzcHashMapConfiguration | KZC_HASH_MAP_CONFIGURATION_STRING |
Configuration for hash maps where key type is a string. More... | |
Hash map.
A hash map stores arbitrary key-value mappings in a way that allows retrieving the value for a key in constant time. If the Kanzi library was built in the debug mode (i.e. _DEBUG was defined), the hash map will assert if elements are added or removed during iteration of the hash map's elements. Also, kzcHashMapIterationBreak() should be used when breaking out of an iteration loop before iterating over all of the elements.
Copyright 2008-2020 by Rightware. All rights reserved.
#define kzcHashMapIterationBreak | ( | hashMap | ) |
Break from hash map iteration - do nothing on release build.
#define kzcHashMapIterate | ( | iterator_param | ) |
#define kzcHashMapIteratorRemove | ( | iterator_param | ) |
Removes current entry of hash map pointed by the iterator.
Next iteration gives the entry that would have been next. Iterator should not be dereferenced at current state.
enum KzcHashMapKeyType |
Key type identifier for hash map.
To use custom hash and comparator functions set key type to KZC_HASH_MAP_KEY_TYPE_CUSTOM.
Enumerator | |
---|---|
KZC_HASH_MAP_KEY_TYPE_INT |
Integer key. |
KZC_HASH_MAP_KEY_TYPE_UINT |
Unsigned integer key. |
KZC_HASH_MAP_KEY_TYPE_FLOAT |
Float key. |
KZC_HASH_MAP_KEY_TYPE_POINTER |
Pointer key. |
KZC_HASH_MAP_KEY_TYPE_STRING |
String key (kzString). |
KZC_HASH_MAP_KEY_TYPE_CUSTOM |
Pointer key with custom hash function and comparator. |
kzsError kzcHashMapCreateWithCapacity | ( | const struct KzcMemoryManager * | memoryManager, |
struct KzcHashMapConfiguration | configuration, | ||
kzUint | capacity, | ||
struct KzcHashMap ** | out_hashMap | ||
) |
Creates a new initially empty hash map.
Stores key-value pairs.
memoryManager | The memory manager to use for memory allocations. |
configuration | Specifies what type of keys are stored in the map. |
capacity | Initial capacity of the hash map. This is the number of chains (of starting length 2) in the map. |
out_hashMap | Pointer that is set to point to the new hash map on successful return. |
kzsError kzcHashMapCreate | ( | const struct KzcMemoryManager * | memoryManager, |
struct KzcHashMapConfiguration | configuration, | ||
struct KzcHashMap ** | out_hashMap | ||
) |
Creates a new initially empty hash map with zero capacity.
Stores key-value pairs.
memoryManager | The memory manager to use for memory allocations. |
configuration | Specifies what type of keys are stored in the map. |
out_hashMap | Pointer that is set to point to the new hash map on successful return. |
kzsError kzcHashMapCreateOrderedWithCapacity | ( | const struct KzcMemoryManager * | memoryManager, |
struct KzcHashMapConfiguration | configuration, | ||
kzUint | capacity, | ||
struct KzcHashMap ** | out_hashMap | ||
) |
Creates a new initially empty hash map, which ensures that the iteration order is same as the order of elements.
Stores key-value pairs.
memoryManager | The memory manager to use for memory allocations. |
configuration | Specifies what type of keys are stored in the map. |
capacity | Initial capacity of the hash map. This is the number of chains (of starting length 2) in the map. |
out_hashMap | Pointer that is set to point to the new hash map on successful return. |
kzsError kzcHashMapCreateOrdered | ( | const struct KzcMemoryManager * | memoryManager, |
struct KzcHashMapConfiguration | configuration, | ||
struct KzcHashMap ** | out_hashMap | ||
) |
Creates a new initially empty hash map, which ensures that the iteration order is same as the order of elements.
memoryManager | The memory manager to use for memory allocations. |
configuration | Specifies what type of keys are stored in the map. |
out_hashMap | Pointer that is set to point to the new hash map on successful return. |
kzsError kzcHashMapDelete | ( | struct KzcHashMap * | hashMap | ) |
Frees the memory allocated for the hash map.
kzsError kzcHashMapClear | ( | struct KzcHashMap * | hashMap | ) |
Clears the content of the hash map.
The capacity of the hash map does not change.
struct KzcHashMapConfiguration kzcHashMapGetConfiguration | ( | const struct KzcHashMap * | hashMap | ) |
Get hash map configuration.
kzUint kzcHashMapGetSize | ( | const struct KzcHashMap * | HashMap | ) |
Returns the number of entries stored in the hash map.
kzBool kzcHashMapIsEmpty | ( | const struct KzcHashMap * | hashMap | ) |
Checks if the hash map is empty or not.
struct KzcHashMapIterator kzcHashMapGetIterator | ( | const struct KzcHashMap * | hashMap | ) |
Returns an iterator to the hash map.
Call kzcHashMapIterate() before accessing the first and any subsequent entries.
kzBool kzcHashMapIterate_private | ( | struct KzcHashMapIterator * | iterator | ) |
kzsError kzcHashMapIteratorRemove_private | ( | struct KzcHashMapIterator * | it | ) |
const struct KzcHashMapConfiguration KZC_HASH_MAP_CONFIGURATION_INT |
Configuration for hash maps where key type is an integer.
const struct KzcHashMapConfiguration KZC_HASH_MAP_CONFIGURATION_UINT |
Configuration for hash maps where key type is an unsigned integer.
const struct KzcHashMapConfiguration KZC_HASH_MAP_CONFIGURATION_FLOAT |
Configuration for hash maps where key type is a float.
const struct KzcHashMapConfiguration KZC_HASH_MAP_CONFIGURATION_POINTER |
Configuration for hash maps where key type is an arbitrary pointer.
const struct KzcHashMapConfiguration KZC_HASH_MAP_CONFIGURATION_STRING |
Configuration for hash maps where key type is a string.