|
Zen API
|
Represents a collection of key-value pairs stored in a hash table.
kMap represents a hash-table of key-value pairs. The kMap constructor accepts kType arguments that determine the key type and value type. The map will automatically grow as new items are inserted.
For maps that contain key or value objects (e.g. kString) as opposed to values (e.g. kText32), the objects are not automatically destroyed when the map is destroyed. To recursively destroy both the map and its keys/values, use kObject_Dispose.
Inheritance diagram for kMap:Public Member Functions | |
| kSize | kCollection_Count (kCollection collection) |
| Gets the collection element count. More... | |
| kIterator | kCollection_GetIterator (kCollection collection) |
| Returns an iterator to the first element in the collection. More... | |
| kBool | kCollection_HasNext (kCollection collection, kIterator iterator) |
| Determines whether a collection has another item. More... | |
| kType | kCollection_ItemType (kCollection collection) |
| Gets the collection element type. More... | |
| void * | kCollection_Next (kCollection collection, kIterator *iterator) |
| Gets the next collection element and then advances the iterator. More... | |
| kStatus | kMap_Add (kMap map, const void *key, const void *value) |
| Adds a new key-value pair. More... | |
| kStatus | kMap_Allocate (kMap map, kType keyType, kType valueType, kSize initialCapacity) |
| Reallocates the map. More... | |
| kStatus | kMap_Assign (kMap map, kMap source) |
| Performs a shallow copy of the source map. More... | |
| kSize | kMap_Capacity (kMap map) |
| Returns the number of elements for which space has been allocated. More... | |
| kStatus | kMap_Clear (kMap map) |
| Sets the count of map items to zero. More... | |
| kStatus | kMap_Construct (kMap *map, kType keyType, kType valueType, kSize initialCapacity, kAlloc allocator) |
| Constructs a kMap object. More... | |
| kSize | kMap_Count (kMap map) |
| Returns the count of map elements. More... | |
| kStatus | kMap_Find (kMap map, const void *key, void *value) |
| Finds the value associated with the given key. More... | |
| kStatus | kMap_FindItem (kMap map, const void *key, kMapItem *item) |
| Finds the map item associated with the given key. More... | |
| kMapItem | kMap_First (kMap map) |
| Gets a reference to the first map item (key-value pair). More... | |
| const void * | kMap_Key (kMap map, kMapItem item) |
| Returns a pointer to the key associated with a map item. More... | |
| kType | kMap_KeyType (kMap map) |
| Returns the key type. More... | |
| kMapItem | kMap_Next (kMap map, kMapItem item) |
| Given a map item, gets a reference to the next map item. More... | |
| kStatus | kMap_Purge (kMap map) |
| Disposes any elements in the map and sets the count of map items to zero. More... | |
| kStatus | kMap_Remove (kMap map, const void *key, void *oldKey, void *oldValue) |
| Removes a key-value pair from the map. More... | |
| kStatus | kMap_RemoveItem (kMap map, kMapItem item) |
| Removes an item from the map. More... | |
| kStatus | kMap_Replace (kMap map, const void *key, const void *value) |
| Adds or replaces a key-value pair. More... | |
| kStatus | kMap_Reserve (kMap map, kSize capacity) |
| Ensures that capacity is reserved for at least the specified number of map items. More... | |
| kStatus | kMap_SetEqualsFx (kMap map, kEqualsFx function) |
| Sets a custom key equality comparator. More... | |
| kSize | kMap_SetHashFx (kMap map, kHashFx function) |
| Sets a custom hash code generator. More... | |
| kStatus | kMap_SetValue (kMap map, kMapItem item, const void *value) |
| Sets the value associated with a map item. More... | |
| void * | kMap_Value (kMap map, kMapItem item) |
| Returns a pointer to the value associated with a map item. More... | |
| kType | kMap_ValueType (kMap map) |
| Returns the value type. More... | |
| kAlloc | kObject_Alloc (kObject object) |
| Gets the memory allocator associated with this object. More... | |
| kStatus | kObject_Clone (kObject *object, kObject source, kAlloc allocator) |
| Constructs a new object by copying an existing object, including any aggregated child elements. More... | |
| kStatus | kObject_Destroy (kObject object) |
| Destroys the object. More... | |
| kStatus | kObject_Dispose (kObject object) |
| Destroys the object and any aggregated child elements. More... | |
| kBool | kObject_Equals (kObject object, kObject other) |
| Determines whether the object is equal to another object. More... | |
| kSize | kObject_HashCode (kObject object) |
| Gets a hash code representing the state of this object. More... | |
| kBool | kObject_Is (kObject object, kType type) |
| Determines whether this object is an instance of the specified type. More... | |
| kBool | kObject_IsShared (kObject object) |
| Reports whether the object is currently shared (reference count greater than one). More... | |
| kStatus | kObject_SetPool (kObject object, kObjectPool pool) |
| Sets the object pool associated with this object. More... | |
| kStatus | kObject_Share (kObject object) |
| Increments the reference count associated with this object. More... | |
| kSize | kObject_Size (kObject object) |
| Estimates the memory consumed by this object, including any aggregated child elements. More... | |
| kType | kObject_Type (kObject object) |
| Returns the type of the object. More... | |
|
inherited |
Gets the collection element count.
| collection | Collection object. |
|
inherited |
Returns an iterator to the first element in the collection.
| collection | Collection object. |
|
inherited |
Determines whether a collection has another item.
| collection | Collection object. |
| iterator | Collection iterator. |
|
inherited |
Gets the collection element type.
| collection | Collection object. |
|
inherited |
Gets the next collection element and then advances the iterator.
| collection | Collection object. |
| iterator | Pointer to collection iterator. |
Adds a new key-value pair.
| map | Map object. |
| key | Pointer to key. |
| value | Pointer to value. |
Reallocates the map.
Existing items are discarded.
| map | Map object. |
| keyType | Type of map key. |
| valueType | Type of map value. |
| initialCapacity | Capacity initially reserved for map items. |
Performs a shallow copy of the source map.
Source key-value pairs are copied by value; if the source map contains objects, the object handles are copied but the objects are not cloned.
| map | Map object. |
| source | Map to be copied. |
Returns the number of elements for which space has been allocated.
| map | Map object. |
Sets the count of map items to zero.
| map | Map object. |
| kStatus kMap_Construct | ( | kMap * | map, |
| kType | keyType, | ||
| kType | valueType, | ||
| kSize | initialCapacity, | ||
| kAlloc | allocator | ||
| ) |
Constructs a kMap object.
| map | Map object. |
| keyType | Type of map key. |
| valueType | Type of map value. |
| initialCapacity | Capacity initially reserved for map items. |
| allocator | Memory allocator. |
Returns the count of map elements.
| map | Map object. |
Finds the value associated with the given key.
| map | Map object. |
| key | Pointer to key. |
| value | Optionally receives value (can be kNULL). |
Finds the map item associated with the given key.
| map | Map object. |
| key | Pointer to key. |
| item | Optionally receives map item (can be kNULL). |
Gets a reference to the first map item (key-value pair).
Returns a pointer to the key associated with a map item.
| map | Map object. |
| item | Map item. |
Given a map item, gets a reference to the next map item.
Disposes any elements in the map and sets the count of map items to zero.
| map | Map object. |
Removes a key-value pair from the map.
| map | Map object. |
| key | Pointer to key. |
| oldKey | Optionally receives key (can be kNULL). |
| oldValue | Optionally receives value (can be kNULL). |
Removes an item from the map.
| map | Map object. |
| item | Map item. |
Adds or replaces a key-value pair.
| map | Map object. |
| key | Pointer to key. |
| value | Pointer to value. |
Ensures that capacity is reserved for at least the specified number of map items.
| map | Map object. |
| capacity | Map capacity, in items. |
Sets a custom key equality comparator.
| map | Map object. |
| function | Key equality function (or kNULL to unset). |
Sets a custom hash code generator.
Calling this method will cause the existing map keys to be rehashed using using the new hash function. If changing both the equals function and the hash function, change equals first, then hash.
| map | Map object. |
| function | Hash code function (or kNULL to unset). |
Sets the value associated with a map item.
| map | Map object. |
| item | Map item. |
| value | Pointer to value to be copied into the map item. |
Returns a pointer to the value associated with a map item.
| map | Map object. |
| item | Map item. |
Gets the memory allocator associated with this object.
Most objects are constructed with an allocator, which is used to allocate the memory required by the object. Objects retain a reference to this allocator to enable further allocations and to free memory when the object is destroyed.
| object | Object. |
Constructs a new object by copying an existing object, including any aggregated child elements.
If the source object is an object collection (e.g. kArrayList<kString>), any aggregated child objects are also cloned. In this case, the kObject_Dispose method can be used to free the cloned collection and its associated elements.
This method will fail if the source object (or an aggregated child element) does not support cloning.
| object | Receives the constructed object. |
| source | Source object. |
| allocator | Memory allocator (or kNULL for default). |
Destroys the object.
The kObject_Destroy method destroys the object itself and any resources that are owned by the object. See Object Destruction for more information.
When an object is destroyed (or disposed), its reference count is decremented. The object is only truly destroyed when the reference count reaches zero. See Reference Counting for more information.
| object | Object (or kNULL). |
Destroys the object and any aggregated child elements.
The kObject_Dispose method destroys the object itself, any resources that are owned by the object, and if the object represents a collection of objects, any child objects in the collection. See Object Destruction for more information.
When an object is destroyed (or disposed), its reference count is decremented. The object is only truly destroyed when the reference count reaches zero. See Reference Counting for more information.
| object | Object (or kNULL). |
Determines whether the object is equal to another object.
By default, objects are compared by reference; objects are considered equal if the given handles refer to the same object instance. However, some classes override the Equals method to provide a more meaningful comparison (e.g. kString).
| object | Object. |
| other | Object for comparison. |
Gets a hash code representing the state of this object.
By default, objects return a hash code based on the object handle value. However, some classes override the HashCode method to provide a more useful hash (e.g. kString).
| object | Object. |
Determines whether this object is an instance of the specified type.
This function compares the type of this object with the given type. An object is considered to be an instance of a given type if a) the type represents a class and this object inherits from (or instantiates) that class, or b) the type represents an interface and this object implements the interface.
| object | Object. |
| type | Type. |
Reports whether the object is currently shared (reference count greater than one).
Objects are initialized with a reference count of one. The kObject_Share method can be used to increment the reference count. The kObject_Destroy and kObject_Dispose methods decrease the reference count, and when the reference count reaches zero, the object is actually destroyed/disposed.
This method can be used to determine if the reference count of an object is currently greater than one.
This method is thread-safe.
| object | Object. |
|
inherited |
Sets the object pool associated with this object.
Object pools can be used to implement custom lifecycle management. If an object has an assigned pool, then the kObjectPool_Reclaim method will be called just prior to destruction, to provide an opportunity for the object to be reclaimed.
| object | Object. |
| pool | Pool object (or kNULL to clear the pool assignment). |
Increments the reference count associated with this object.
This method is thread-safe.
| object | Object. |
Estimates the memory consumed by this object, including any aggregated child elements.
This method can be optionally overridden by kObject-derived classes to report the amount of memory consumed by an object. The default implementation reports only the size of the class instance (additional allocations performed by the class are excluded).
| object | Object. |
Returns the type of the object.
Each object is an instance of a specific class type. The type handle returned by this function can be used to learn about the class.
| object | Object. |