Zen API

- Home
- Topics
- Types
- Files

All Classes Files Functions Variables Typedefs Friends Macros Modules Pages
kMap.h
Go to the documentation of this file.
1
10 #ifndef K_API_MAP_H
11 #define K_API_MAP_H
12
13 #include <kApi/kApiDef.h>
14
184 //typedef kObject kMap; --forward-declared in kApiDef.x.h
185
191 typedef kPointer kMapItem;
192
193 #include <kApi/Data/kMap.x.h>
194
206 kFx(kStatus) kMap_Construct(kMap* map, kType keyType, kType valueType, kSize initialCapacity, kAlloc allocator);
207
220 kFx(kStatus) kMap_Allocate(kMap map, kType keyType, kType valueType, kSize initialCapacity);
221
233 kFx(kStatus) kMap_Assign(kMap map, kMap source);
234
243 kInlineFx(kStatus) kMap_SetEqualsFx(kMap map, kEqualsFx function)
244 {
245 kObj(kMap, map);
246
247 obj->equalsFx = function;
248
249 return kOK;
250 }
263 kInlineFx(kStatus) kMap_SetHashFx(kMap map, kHashFx function)
264 {
265 kObj(kMap, map);
266
267 obj->hashFx = function;
268
269 kCheck(xkMap_Rehash(map));
270
271 return kOK;
272 }
273
281 kInlineFx(kType) kMap_KeyType(kMap map)
282 {
283 kObj(kMap, map);
284
285 return obj->keyField.type;
286 }
287
295 kInlineFx(kType) kMap_ValueType(kMap map)
296 {
297 kObj(kMap, map);
298
299 return obj->valueField.type;
300 }
301
309 kInlineFx(kSize) kMap_Count(kMap map)
310 {
311 kObj(kMap, map);
312
313 return obj->count;
314 }
315
323 kInlineFx(kSize) kMap_Capacity(kMap map)
324 {
325 kObj(kMap, map);
326
327 return obj->capacity;
328 }
329
339 kFx(kStatus) kMap_Find(kMap map, const void* key, void* value);
340
353 #define kMap_FindT(kMap_map, KPtr_key, VPtr_value) \
354 xkMap_FindT(kMap_map, KPtr_key, VPtr_value, sizeof(*KPtr_key), sizeof(*VPtr_value))
355
364 kInlineFx(kBool) kMap_Has(kMap map, const void* key)
365 {
366 return kSuccess(kMap_Find(map, key, kNULL));
367 }
368
380 #define kMap_HasT(kMap_map, KPtr_key) \
381 xkMap_HasT(kMap_map, KPtr_key, sizeof(*KPtr_key))
382
392 kFx(kStatus) kMap_Add(kMap map, const void* key, const void* value);
393
406 #define kMap_AddT(kMap_map, KPtr_key, VPtr_value) \
407 xkMap_AddT(kMap_map, KPtr_key, VPtr_value, sizeof(*KPtr_key), sizeof(*VPtr_value))
408
422 kFx(kStatus) kMap_Replace(kMap map, const void* key, const void* value);
423
440 #define kMap_ReplaceT(kMap_map, KPtr_key, VPtr_value) \
441 xkMap_ReplaceT(kMap_map, KPtr_key, VPtr_value, sizeof(*KPtr_key), sizeof(*VPtr_value))
442
457 kFx(kStatus) kMap_Remove(kMap map, const void* key, void* oldKey, void* oldValue);
458
476 #define kMap_RemoveT(kMap_map, KPtr_key, KPtr_oldKey, VPtr_oldValue) \
477 xkMap_RemoveT(kMap_map, KPtr_key, KPtr_oldKey, VPtr_oldValue, sizeof(*KPtr_key), sizeof(*KPtr_oldKey), sizeof(*VPtr_oldValue))
478
490 kInlineFx(kStatus) kMap_Discard(kMap map, const void* key)
491 {
492 return kMap_Remove(map, key, kNULL, kNULL);
493 }
494
509 #define kMap_DiscardT(kMap_map, KPtr_key) \
510 xkMap_DiscardT(kMap_map, KPtr_key, sizeof(*KPtr_key))
511
520 kFx(kStatus) kMap_Reserve(kMap map, kSize capacity);
521
529 kFx(kStatus) kMap_Clear(kMap map);
530
538 kFx(kStatus) kMap_Purge(kMap map);
539
547 kFx(kMapItem) kMap_First(kMap map);
548
557 kFx(kMapItem) kMap_Next(kMap map, kMapItem item);
558
568 kFx(kStatus) kMap_FindItem(kMap map, const void* key, kMapItem* item);
569
582 #define kMap_FindItemT(kMap_map, KPtr_key, kMapItemPtr_item) \
583 xkMap_FindItemT(kMap_map, KPtr_key, kMapItemPtr_item, sizeof(*KPtr_key))
584
593 kFx(kStatus) kMap_RemoveItem(kMap map, kMapItem item);
594
603 kInlineFx(const void*) kMap_Key(kMap map, kMapItem item)
604 {
605 kObj(kMap, map);
606
607 return kPointer_ByteOffset(item, (kSSize)obj->keyField.offset);
608 }
609
622 #define kMap_KeyT(kMap_map, kMapItem_item, K) \
623 kCast(K*, xkMap_KeyT(kMap_map, kMapItem_item, sizeof(K)))
624
637 #define kMap_KeyAsT(kMap_map, kMapItem_item, K) \
638 kPointer_ReadAs(xkMap_KeyAsT(kMap_map, kMapItem_item, sizeof(K)), K)
639
648 kInlineFx(void*) kMap_Value(kMap map, kMapItem item)
649 {
650 kObj(kMap, map);
651
652 return kPointer_ByteOffset(item, (kSSize)obj->valueField.offset);
653 }
654
667 #define kMap_ValueT(kMap_map, kMapItem_item, V) \
668 kCast(V*, xkMap_ValueT(kMap_map, kMapItem_item, sizeof(V)))
669
679 kInlineFx(kStatus) kMap_SetValue(kMap map, kMapItem item, const void* value)
680 {
681 kObj(kMap, map);
682 void* valueSlot = kMap_Value(map, item);
683
684 kValue_Import(obj->valueField.type, valueSlot, value);
685
686 return kOK;
687 }
688
701 #define kMap_SetValueT(kMap_map, kMapItem_item, VPtr_value) \
702 xkMap_SetValueT(kMap_map, kMapItem_item, VPtr_value, sizeof(*VPtr_value))
703
717 #define kMap_SetValueAsT(kMap_map, kMapItem_item, V_value, V) \
718 (kPointer_WriteAs(xkMap_ValueAsT(kMap_map, kMapItem_item, sizeof(V)), V_value, V), (void)0)
719
732 #define kMap_ValueAsT(kMap_map, kMapItem_item, V) \
733 kPointer_ReadAs(xkMap_ValueAsT(kMap_map, kMapItem_item, sizeof(V)), V)
734
735 #endif
kMap::kMap_Purge
kStatus kMap_Purge(kMap map)
Disposes any elements in the map and sets the count of map items to zero.
kMap::kMap_Find
kStatus kMap_Find(kMap map, const void *key, void *value)
Finds the value associated with the given key.
kMap::kMap_Clear
kStatus kMap_Clear(kMap map)
Sets the count of map items to zero.
kSuccess
kBool kSuccess(kStatus status)
Returns kTRUE if the given expression value is kOK.
Definition: kApiDef.h:548
kMap::kMap_SetEqualsFx
kStatus kMap_SetEqualsFx(kMap map, kEqualsFx function)
Sets a custom key equality comparator.
Definition: kMap.h:243
kMap::kMap_First
kMapItem kMap_First(kMap map)
Gets a reference to the first map item (key-value pair).
kPointer
Represents a void pointer.
kMap::kMap_Discard
kStatus kMap_Discard(kMap map, const void *key)
Removes a key-value pair from the map.
Definition: kMap.h:490
kMap::kMap_Count
kSize kMap_Count(kMap map)
Returns the count of map elements.
Definition: kMap.h:309
kMap::kMap_Allocate
kStatus kMap_Allocate(kMap map, kType keyType, kType valueType, kSize initialCapacity)
Reallocates the map.
kMap::kMap_SetHashFx
kStatus kMap_SetHashFx(kMap map, kHashFx function)
Sets a custom hash code generator.
Definition: kMap.h:263
kSize
Represents an unsigned integer that can store a pointer address.
kAlloc
Abstract base class for memory allocator types.
kValue::kValue_Import
void kValue_Import(kType type, void *value, const void *source)
Imports the content of another value into this value.
Definition: kValue.h:108
kCheck
#define kCheck(EXPRESSION)
Executes a return statement if the given expression is not kOK.
Definition: kApiDef.h:561
kMap::kMap_Construct
kStatus kMap_Construct(kMap *map, kType keyType, kType valueType, kSize initialCapacity, kAlloc allocator)
Constructs a kMap object.
kMap::kMap_Reserve
kStatus kMap_Reserve(kMap map, kSize capacity)
Ensures that capacity is reserved for at least the specified number of map items. ...
kInlineFx
#define kInlineFx(TYPE)
Inline method declaration helper.
Definition: kApiDef.h:26
kMap::kMap_Key
const void * kMap_Key(kMap map, kMapItem item)
Returns a pointer to the key associated with a map item.
Definition: kMap.h:603
kMap::kMap_ValueType
kType kMap_ValueType(kMap map)
Returns the value type.
Definition: kMap.h:295
kHashFx
kSize(kCall * kHashFx)(const void *item)
Callback signature to determine hash code of an item.
Definition: kApiDef.h:1727
kSSize
Represents a signed integer that can store a pointer address.
kMap::kMap_Capacity
kSize kMap_Capacity(kMap map)
Returns the number of elements for which space has been allocated.
Definition: kMap.h:323
kMap::kMap_Add
kStatus kMap_Add(kMap map, const void *key, const void *value)
Adds a new key-value pair.
kEqualsFx
kBool(kCall * kEqualsFx)(const void *item1, const void *item2)
Callback signature to determine equality of two items.
Definition: kApiDef.h:1719
kObj
#define kObj(TypeName_T, T_object)
Declares a local "obj" (this-pointer) variable and initializes it from a type-checked object handle...
Definition: kApiDef.h:2923
kMap::kMapItem
kPointer kMapItem
Represents a key-value pair within a map.
kMap::kMap_Has
kBool kMap_Has(kMap map, const void *key)
Reports whether the specified key is present in the map.
Definition: kMap.h:364
kMap::kMap_FindItem
kStatus kMap_FindItem(kMap map, const void *key, kMapItem *item)
Finds the map item associated with the given key.
kMap::kMap_Assign
kStatus kMap_Assign(kMap map, kMap source)
Performs a shallow copy of the source map.
kApiDef.h
Core Zen type declarations.
kMap::kMap_KeyType
kType kMap_KeyType(kMap map)
Returns the key type.
Definition: kMap.h:281
kPointer::kPointer_ByteOffset
void * kPointer_ByteOffset(const void *pointer, kSSize offset)
Calculates a pointer address from a base address and a byte offset.
Definition: kApiDef.h:280
kMap::kMap_Next
kMapItem kMap_Next(kMap map, kMapItem item)
Given a map item, gets a reference to the next map item.
kMap::kMap_RemoveItem
kStatus kMap_RemoveItem(kMap map, kMapItem item)
Removes an item from the map.
kMap::kMap_Replace
kStatus kMap_Replace(kMap map, const void *key, const void *value)
Adds or replaces a key-value pair.
kMap::kMap_Remove
kStatus kMap_Remove(kMap map, const void *key, void *oldKey, void *oldValue)
Removes a key-value pair from the map, optionally returning the old key and/or value.
kMap::kMap_SetValue
kStatus kMap_SetValue(kMap map, kMapItem item, const void *value)
Sets the value associated with a map item.
Definition: kMap.h:679
kType
Represents metadata about a type (class, interface, or value).
kMap::kMap_Value
void * kMap_Value(kMap map, kMapItem item)
Returns a pointer to the value associated with a map item.
Definition: kMap.h:648
kStatus::kOK
#define kOK
Operation successful.
Definition: kApiDef.h:515
kStatus
Represents an error code.
kNULL
#define kNULL
Null pointer.
Definition: kApiDef.h:269
kBool
Represents a boolean value.
kMap
Represents a collection of key-value pairs stored in a hash table.