kzc_hash_map.hpp File Reference

Hash map. More...

Classes

struct  KzcHashMapIterator
 Accessor to the contents of a HashMap. More...
 
struct  KzcHashMapConfiguration
 Configuration parameters for a HashMap. 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...
 

Typedefs

typedef kzUint KzcHashMapChainLengthType
 Chain length elementary type. 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. 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...
 

Detailed Description

Hash map.

Hash map stores arbitrary key -> value mappings.

Copyright 2008-2017 by Rightware. All rights reserved.

Macro Definition Documentation

#define kzcHashMapIterationBreak (   hashMap)

Break from hash map iteration - do nothing on release build.

#define kzcHashMapIterate (   iterator_param)

Finds the next entry in the attached hash map.

Returns KZ_TRUE if next entry is found, otherwise KZ_FALSE.

#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.

Typedef Documentation

Chain length elementary type.

Enumeration Type Documentation

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.

Function Documentation

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. Initial capacity is given as a parameter. configuration specifies what type of keys are used in the map. The caller is responsible for deleting returned hash map object with kzcHashMapDelete function.

kzsError kzcHashMapCreate ( const struct KzcMemoryManager memoryManager,
struct KzcHashMapConfiguration  configuration,
struct KzcHashMap **  out_hashMap 
)

Creates a new initially empty hash map.

Stores key-value pairs. configuration specifies what type of keys are used in the map. The caller is responsible for deleting returned hash map object with kzcHashMapDelete function.

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.

Parameters
hashMapHash map to clear.
Returns
Error code.
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)

Variable Documentation

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.