|
ucx
UAP Common Extensions
|
Linked list implementation with key/value-lookup. More...
Go to the source code of this file.
Macros | |
| #define | cxKvListSetKey(list, index, key) |
| Sets or updates the key of a list item. | |
| #define | cxKvListInsert(list, index, key, value) |
| Inserts an item into the list at the specified index and associates it with the specified key. | |
| #define | cxKvListAdd(list, key, value) |
| Adds an item into the list and associates it with the specified key. | |
Functions | |
| CxList * | cxKvListCreate (const CxAllocator *allocator, size_t elem_size) |
Allocates a linked list with a lookup-map for storing elements with elem_size bytes each. | |
| CxMap * | cxKvListCreateAsMap (const CxAllocator *allocator, size_t elem_size) |
Allocates a linked list with a lookup-map for storing elements with elem_size bytes each. | |
| CxList * | cxKvListAsList (CxMap *map) |
| Converts a map pointer belonging to a key-value-List back to the original list pointer. | |
| CxMap * | cxKvListAsMap (CxList *list) |
| Converts a map pointer belonging to a key-value-List back to the original list pointer. | |
| int | cx_kv_list_set_key (CxList *list, size_t index, CxHashKey key) |
| Sets or updates the key of a list item. | |
| int | cx_kv_list_insert (CxList *list, size_t index, CxHashKey key, void *value) |
| Inserts an item into the list at the specified index and associates it with the specified key. | |
| int | cxKvListRemoveKey (CxList *list, size_t index) |
| Removes the key of a list item. | |
| const CxHashKey * | cxKvListGetKey (CxList *list, size_t index) |
| Returns the key of a list item. | |
Linked list implementation with key/value-lookup.
| #define cxKvListAdd | ( | list, | |
| key, | |||
| value ) |
Adds an item into the list and associates it with the specified key.
| list | (CxList*) the list |
| key | (CxHashKey, char*, cxstring, or cxmutstr) the key |
| value | (void*) the value |
| zero | success |
| non-zero | memory allocation failure |
| #define cxKvListInsert | ( | list, | |
| index, | |||
| key, | |||
| value ) |
Inserts an item into the list at the specified index and associates it with the specified key.
| list | (CxList*) the list |
| index | (size_t) the index the inserted element shall have |
| key | (any supported key type) the key |
| value | (void*) the value |
| zero | success |
| non-zero | memory allocation failure or the index is out of bounds |
| #define cxKvListSetKey | ( | list, | |
| index, | |||
| key ) |
Sets or updates the key of a list item.
This is, for example, useful when you have inserted an element using the CxList interface, and now you want to associate this element with a key.
| list | (CxList*) the list |
| index | (size_t) the index of the element in the list |
| key | (any supported key type) the key |
| zero | success |
| non-zero | memory allocation failure or the index is out of bounds |
Inserts an item into the list at the specified index and associates it with the specified key.
| list | the list |
| index | the index the inserted element shall have |
| key | the key |
| value | the value |
| zero | success |
| non-zero | memory allocation failure or the index is out of bounds |
Sets or updates the key of a list item.
This is, for example, useful when you have inserted an element using the CxList interface, and now you want to associate this element with a key.
| list | the list |
| index | the index of the element in the list |
| key | the key |
| zero | success |
| non-zero | memory allocation failure or the index is out of bounds |
Converts a map pointer belonging to a key-value-List back to the original list pointer.
| map | a map pointer that was returned by a call to cxKvListAsMap() |
Converts a map pointer belonging to a key-value-List back to the original list pointer.
| list | a list created by cxKvListCreate() |
| CxList * cxKvListCreate | ( | const CxAllocator * | allocator, |
| size_t | elem_size ) |
Allocates a linked list with a lookup-map for storing elements with elem_size bytes each.
If elem_size is CX_STORE_POINTERS, the created list stores pointers instead of copies of the added elements, and the compare function will be automatically set to cx_cmp_ptr().
After creating the list, it can also be used as a map after converting the pointer to a CxMap pointer with cxKvListAsMap(). When you want to use the list interface again, you can also convert the map pointer back with cxKvListAsList().
| allocator | the allocator for allocating the list nodes (if NULL, the cxDefaultAllocator will be used) |
| elem_size | the size of each element in bytes |
| CxMap * cxKvListCreateAsMap | ( | const CxAllocator * | allocator, |
| size_t | elem_size ) |
Allocates a linked list with a lookup-map for storing elements with elem_size bytes each.
If elem_size is CX_STORE_POINTERS, the created list stores pointers instead of copies of the added elements, and the compare function will be automatically set to cx_cmp_ptr().
This function creates the list with cxKvListCreate() and immediately applies cxKvListAsMap(). If you want to use the returned object as a list, you can call cxKvListAsList() later.
| allocator | the allocator for allocating the list nodes (if NULL, the cxDefaultAllocator will be used) |
| elem_size | the size of each element in bytes |
Returns the key of a list item.
| list | the list |
| index | the index of the element in the list |
NULL when the index is out of bounds or the item does not have a key | int cxKvListRemoveKey | ( | CxList * | list, |
| size_t | index ) |
Removes the key of a list item.
This can be useful if you want to explicitly remove an item from the lookup map.
If no key is associated with the item, nothing happens, and this function returns zero.
| list | the list |
| index | the index of the element in the list |
| zero | success |
| non-zero | the index is out of bounds |