![]() |
ucx
UAP Common Extensions
|
Interface for map implementations. More...
Go to the source code of this file.
Data Structures | |
| struct | cx_map_s |
| Structure for the UCX map. More... | |
| struct | cx_map_entry_s |
| A map entry. More... | |
| struct | cx_map_iterator_s |
| Internal iterator struct - use CxMapIterator. More... | |
| struct | cx_map_class_s |
| The class definition for arbitrary maps. More... | |
Macros | |
| #define | cxMapPut(map, key, value) |
| Puts a key/value-pair into the map. | |
| #define | cxMapEmplace(map, key) |
| Allocates memory for a value in the map associated with the specified key. | |
| #define | cxMapGet(map, key) |
| Retrieves a value by using a key. | |
| #define | cxMapContains(map, key) |
| Checks if a map contains a specific key. | |
| #define | cxMapRemove(map, key) |
| Removes a key/value-pair from the map by using the key. | |
| #define | cxMapRemoveAndGet(map, key, targetbuf) |
| Removes a key/value-pair from the map by using the key. | |
Typedefs | |
| typedef struct cx_map_s | CxMap |
| Type for the UCX map. | |
| typedef struct cx_map_entry_s | CxMapEntry |
| Type for a map entry. | |
| typedef struct cx_map_iterator_s | CxMapIterator |
| Type for a map iterator. | |
| typedef struct cx_map_class_s | cx_map_class |
| Type for map class definitions. | |
Enumerations | |
| enum | cx_map_iterator_type { CX_MAP_ITERATOR_PAIRS , CX_MAP_ITERATOR_KEYS , CX_MAP_ITERATOR_VALUES } |
| The type of iterator for a map. More... | |
Functions | |
| void | cxMapFree (CxMap *map) |
| Deallocates the memory of the specified map. | |
| void | cxMapClear (CxMap *map) |
| Clears a map by removing all elements. | |
| size_t | cxMapSize (const CxMap *map) |
| Returns the number of elements in this map. | |
| CxMapIterator | cxMapIteratorValues (const CxMap *map) |
| Creates a value iterator for a map. | |
| CxMapIterator | cxMapIteratorKeys (const CxMap *map) |
| Creates a key iterator for a map. | |
| CxMapIterator | cxMapIterator (const CxMap *map) |
| Creates an iterator for a map. | |
| int | cx_map_put (CxMap *map, CxHashKey key, void *value) |
| Puts a key/value-pair into the map. | |
| void * | cx_map_emplace (CxMap *map, CxHashKey key) |
| Allocates memory for a value in the map associated with the specified key. | |
| void * | cx_map_get (const CxMap *map, CxHashKey key) |
| Retrieves a value by using a key. | |
| int | cx_map_remove (CxMap *map, CxHashKey key, void *targetbuf) |
| Removes a key/value-pair from the map by using the key. | |
| int | cxMapClone (CxMap *dst, const CxMap *src, cx_clone_func clone_func, const CxAllocator *clone_allocator, void *data) |
| Performs a deep clone of one map into another. | |
| int | cxMapDifference (CxMap *dst, const CxMap *minuend, const CxMap *subtrahend, cx_clone_func clone_func, const CxAllocator *clone_allocator, void *data) |
| Clones entries of a map if their key is not present in another map. | |
| int | cxMapListDifference (CxMap *dst, const CxMap *src, const CxList *keys, cx_clone_func clone_func, const CxAllocator *clone_allocator, void *data) |
| Clones entries of a map if their key is not present in a list. | |
| int | cxMapIntersection (CxMap *dst, const CxMap *src, const CxMap *other, cx_clone_func clone_func, const CxAllocator *clone_allocator, void *data) |
| Clones entries of a map only if their key is present in another map. | |
| int | cxMapListIntersection (CxMap *dst, const CxMap *src, const CxList *keys, cx_clone_func clone_func, const CxAllocator *clone_allocator, void *data) |
| Clones entries of a map only if their key is present in a list. | |
| int | cxMapUnion (CxMap *dst, const CxMap *src, cx_clone_func clone_func, const CxAllocator *clone_allocator, void *data) |
| Clones entries into a map if their key does not exist yet. | |
| int | cxMapCloneSimple (CxMap *dst, const CxMap *src) |
| Performs a shallow clone of one map into another. | |
| int | cxMapDifferenceSimple (CxMap *dst, const CxMap *minuend, const CxMap *subtrahend) |
| Clones entries of a map if their key is not present in another map. | |
| int | cxMapListDifferenceSimple (CxMap *dst, const CxMap *src, const CxList *keys) |
| Clones entries of a map if their key is not present in a list. | |
| int | cxMapIntersectionSimple (CxMap *dst, const CxMap *src, const CxMap *other) |
| Clones entries of a map only if their key is present in another map. | |
| int | cxMapListIntersectionSimple (CxMap *dst, const CxMap *src, const CxList *keys) |
| Clones entries of a map only if their key is present in a list. | |
| int | cxMapUnionSimple (CxMap *dst, const CxMap *src) |
| Clones entries into a map if their key does not exist yet. | |
Variables | |
| CxMap *const | cxEmptyMap |
| A shared instance of an empty map. | |
Interface for map implementations.
| #define cxMapContains | ( | map, | |
| key ) |
Checks if a map contains a specific key.
| map | (CxMap*) the map |
| key | (any supported key type) the key |
| true | if the key exists in the map |
| false | if the key does not exist in the map |
| #define cxMapEmplace | ( | map, | |
| key ) |
Allocates memory for a value in the map associated with the specified key.
A possible existing value will be overwritten. If destructor functions are specified, they are called for the overwritten element.
If the map is storing pointers, this function returns a void** pointer, meaning a pointer to that pointer.
The key is always copied.
| map | (CxMap*) the map |
| key | (any supported key type) the key |
NULL if allocation fails | zero | success |
| non-zero | value on memory allocation failure |
| #define cxMapGet | ( | map, | |
| key ) |
Retrieves a value by using a key.
If this map is storing pointers, the stored pointer is returned. Otherwise, a pointer to the element within the map's memory is returned (which is valid as long as the element stays in the map).
| map | (CxMap*) the map |
| key | (any supported key type) the key |
void*) the value or NULL when no value with that key exists | #define cxMapPut | ( | map, | |
| key, | |||
| value ) |
Puts a key/value-pair into the map.
A possible existing value will be overwritten. If destructor functions are specified, they are called for the overwritten element.
If this map is storing pointers, the value pointer is written to the map. Otherwise, the memory is copied from value with memcpy().
The key is always copied.
| map | (CxMap*) the map |
| key | (any supported key type) the key |
| value | (void*) the value |
| zero | success |
| non-zero | value on memory allocation failure |
| #define cxMapRemove | ( | map, | |
| key ) |
Removes a key/value-pair from the map by using the key.
Always invokes the destructor functions, if any, on the removed element.
| map | (CxMap*) the map |
| key | (any supported key type) the key |
| zero | success |
| non-zero | the key was not found |
| #define cxMapRemoveAndGet | ( | map, | |
| key, | |||
| targetbuf ) |
Removes a key/value-pair from the map by using the key.
This function will copy the contents of the removed element to the target buffer, which must be guaranteed to be large enough to hold the element (the map's element size). The destructor functions, if any, will not be called.
If this map is storing pointers, the element is the pointer itself and not the object it points to.
| map | (CxMap*) the map |
| key | (any supported key type) the key |
| targetbuf | (void*) the buffer where the element shall be copied to |
| zero | success |
| non-zero | the key was not found |
| enum cx_map_iterator_type |
Allocates memory for a value in the map associated with the specified key.
A possible existing value will be overwritten. If destructor functions are specified, they are called for the overwritten element.
If the map is storing pointers, this function returns a void** pointer, meaning a pointer to that pointer.
The key is always copied.
| map | the map |
| key | the key |
NULL if allocation fails | zero | success |
| non-zero | value on memory allocation failure |
Retrieves a value by using a key.
If this map is storing pointers, the stored pointer is returned. Otherwise, a pointer to the element within the map's memory is returned (which is valid as long as the element stays in the map).
| map | the map |
| key | the key |
Puts a key/value-pair into the map.
A possible existing value will be overwritten. If destructor functions are specified, they are called for the overwritten element.
If this map is storing pointers, the value pointer is written to the map. Otherwise, the memory is copied from value with memcpy().
The key is always copied.
| map | the map |
| key | the key |
| value | the value |
| zero | success |
| non-zero | value on memory allocation failure |
Removes a key/value-pair from the map by using the key.
Invokes the destructor functions, if any, on the removed element if and only if the targetbuf is NULL.
| map | the map |
| key | the key |
| targetbuf | the optional buffer where the removed element shall be copied to |
| zero | success |
| non-zero | the key was not found |
| void cxMapClear | ( | CxMap * | map | ) |
Clears a map by removing all elements.
Also calls the content destructor functions for each element, if specified.
| map | the map to be cleared |
| int cxMapClone | ( | CxMap * | dst, |
| const CxMap * | src, | ||
| cx_clone_func | clone_func, | ||
| const CxAllocator * | clone_allocator, | ||
| void * | data ) |
Performs a deep clone of one map into another.
If the destination map already contains entries, the cloned entries are added to that map, possibly overwriting existing elements when the keys already exist.
When elements in the destination map need to be replaced, any destructor function is called on the replaced elements before replacing them.
| dst | the destination map |
| src | the source map |
| clone_func | the clone function for the values |
| clone_allocator | the allocator that is passed to the clone function |
| data | optional additional data that is passed to the clone function |
| zero | when all elements were successfully cloned |
| non-zero | when an allocation error occurred |
Performs a shallow clone of one map into another.
This function uses the default allocator, if needed, and performs shallow clones with memcpy().
If the destination map already contains entries, the cloned entries are added to that map, possibly overwriting existing elements when the keys already exist.
When elements in the destination map need to be replaced, any destructor function is called on the replaced elements before replacing them.
| dst | the destination map |
| src | the source map |
| zero | when all elements were successfully cloned |
| non-zero | when an allocation error occurred |
| int cxMapDifference | ( | CxMap * | dst, |
| const CxMap * | minuend, | ||
| const CxMap * | subtrahend, | ||
| cx_clone_func | clone_func, | ||
| const CxAllocator * | clone_allocator, | ||
| void * | data ) |
Clones entries of a map if their key is not present in another map.
| dst | the destination map |
| minuend | the map to subtract the entries from |
| subtrahend | the map containing the elements to be subtracted |
| clone_func | the clone function for the values |
| clone_allocator | the allocator that is passed to the clone function |
| data | optional additional data that is passed to the clone function |
| zero | when the elements were successfully cloned |
| non-zero | when an allocation error occurred |
Clones entries of a map if their key is not present in another map.
This function uses the default allocator, if needed, and performs shallow clones with memcpy().
| dst | the destination map |
| minuend | the map to subtract the entries from |
| subtrahend | the map containing the elements to be subtracted |
| zero | when the elements were successfully cloned |
| non-zero | when an allocation error occurred |
| void cxMapFree | ( | CxMap * | map | ) |
Deallocates the memory of the specified map.
Also calls the content destructor functions for each element, if specified.
| map | the map to be freed |
| int cxMapIntersection | ( | CxMap * | dst, |
| const CxMap * | src, | ||
| const CxMap * | other, | ||
| cx_clone_func | clone_func, | ||
| const CxAllocator * | clone_allocator, | ||
| void * | data ) |
Clones entries of a map only if their key is present in another map.
| dst | the destination map |
| src | the map to clone the entries from |
| other | the map to check for existence of the keys |
| clone_func | the clone function for the values |
| clone_allocator | the allocator that is passed to the clone function |
| data | optional additional data that is passed to the clone function |
| zero | when the elements were successfully cloned |
| non-zero | when an allocation error occurred |
Clones entries of a map only if their key is present in another map.
This function uses the default allocator, if needed, and performs shallow clones with memcpy().
| dst | the destination map |
| src | the map to clone the entries from |
| other | the map to check for existence of the keys |
| zero | when the elements were successfully cloned |
| non-zero | when an allocation error occurred |
| CxMapIterator cxMapIterator | ( | const CxMap * | map | ) |
Creates an iterator for a map.
The elements of the iterator are key/value pairs of type CxMapEntry, and the pointer returned during iterator shall be treated as const CxMapEntry* .
| map | the map to create the iterator for (can be NULL) |
| CxMapIterator cxMapIteratorKeys | ( | const CxMap * | map | ) |
Creates a key iterator for a map.
The elements of the iterator are keys of type CxHashKey, and the pointer returned during iterator shall be treated as const CxHashKey* .
| map | the map to create the iterator for (can be NULL) |
| CxMapIterator cxMapIteratorValues | ( | const CxMap * | map | ) |
Creates a value iterator for a map.
When the map is storing pointers, those pointers are returned. Otherwise, the iterator iterates over pointers to the memory within the map where the respective elements are stored.
| map | the map to create the iterator for (can be NULL) |
| int cxMapListDifference | ( | CxMap * | dst, |
| const CxMap * | src, | ||
| const CxList * | keys, | ||
| cx_clone_func | clone_func, | ||
| const CxAllocator * | clone_allocator, | ||
| void * | data ) |
Clones entries of a map if their key is not present in a list.
Note that the list must contain keys of type CxKey (or pointers to such keys) and must use cx_hash_key_cmp as the compare function. Generic key types cannot be processed in this case.
| dst | the destination map |
| src | the source map |
| keys | the list of CxKey items |
| clone_func | the clone function for the values |
| clone_allocator | the allocator that is passed to the clone function |
| data | optional additional data that is passed to the clone function |
| zero | when the elements were successfully cloned |
| non-zero | when an allocation error occurred |
Clones entries of a map if their key is not present in a list.
This function uses the default allocator, if needed, and performs shallow clones with memcpy().
Note that the list must contain keys of type CxKey (or pointers to such keys) and must use cx_hash_key_cmp as the compare function. Generic key types cannot be processed in this case.
| dst | the destination map |
| src | the source map |
| keys | the list of CxKey items |
| zero | when the elements were successfully cloned |
| non-zero | when an allocation error occurred |
| int cxMapListIntersection | ( | CxMap * | dst, |
| const CxMap * | src, | ||
| const CxList * | keys, | ||
| cx_clone_func | clone_func, | ||
| const CxAllocator * | clone_allocator, | ||
| void * | data ) |
Clones entries of a map only if their key is present in a list.
Note that the list must contain keys of type CxKey (or pointers to such keys) and must use cx_hash_key_cmp as the compare function. Generic key types cannot be processed in this case.
| dst | the destination map |
| src | the source map |
| keys | the list of CxKey items |
| clone_func | the clone function for the values |
| clone_allocator | the allocator that is passed to the clone function |
| data | optional additional data that is passed to the clone function |
| zero | when the elements were successfully cloned |
| non-zero | when an allocation error occurred |
Clones entries of a map only if their key is present in a list.
This function uses the default allocator, if needed, and performs shallow clones with memcpy().
Note that the list must contain keys of type CxKey (or pointers to such keys) and must use cx_hash_key_cmp as the compare function. Generic key types cannot be processed in this case.
| dst | the destination map |
| src | the source map |
| keys | the list of CxKey items |
| zero | when the elements were successfully cloned |
| non-zero | when an allocation error occurred |
| size_t cxMapSize | ( | const CxMap * | map | ) |
Returns the number of elements in this map.
| map | the map |
| int cxMapUnion | ( | CxMap * | dst, |
| const CxMap * | src, | ||
| cx_clone_func | clone_func, | ||
| const CxAllocator * | clone_allocator, | ||
| void * | data ) |
Clones entries into a map if their key does not exist yet.
If you want to calculate the union of two maps into a fresh new map, you can proceed as follows:
| dst | the destination map |
| src | the map to clone the entries from |
| clone_func | the clone function for the values |
| clone_allocator | the allocator that is passed to the clone function |
| data | optional additional data that is passed to the clone function |
| zero | when the elements were successfully cloned |
| non-zero | when an allocation error occurred |
Clones entries into a map if their key does not exist yet.
This function uses the default allocator, if needed, and performs shallow clones with memcpy().
If you want to calculate the union of two maps into a fresh new map, you can proceed as follows:
| dst | the destination map |
| src | the map to clone the entries from |
| zero | when the elements were successfully cloned |
| non-zero | when an allocation error occurred |