| libdatatypes 0.3.2
    Abstract datatypes for C. | 
Generic associative array. More...
Go to the source code of this file.
| Data Structures | |
| struct | AssocArray | 
| Array containing associations between keys and values.  More... | |
| struct | AssocArray::_AssocArrayPair | 
| A key-value pair.  More... | |
| Macros | |
| #define | ASSOC_ARRAY_MAX_SIZE (SSIZE_MAX / sizeof(void *)) | 
| #define | assoc_array_pair_key(p) p->array->keys[p->offset] | 
| #define | assoc_array_pair_value(p) p->array->values[p->offset] | 
| #define | assoc_array_iter_key(iter) iter.array->keys[iter.offset] | 
| #define | assoc_array_iter_value(iter) iter.array->values[iter.offset] | 
| Typedefs | |
| typedef struct _AssocArrayPair | AssocArrayPair | 
| typedef struct _AssocArrayPair | AssocArrayIter | 
| Enumerations | |
| enum | AssocArrayInsertResult { ASSOCARRAY_INSERT_RESULT_NEW , ASSOCARRAY_INSERT_RESULT_REPLACED , ASSOCARRAY_INSERT_RESULT_FAILED } | 
| result of assoc_array_set() method.  More... | |
Generic associative array.
Definition in file assocarray.h.
| struct AssocArray | 
Array containing associations between keys and values.
Definition at line 37 of file assocarray.h.
| Data Fields | ||
|---|---|---|
| CompareFunc | compare_keys | Function to compare two keys. | 
| size_t | count | Number of inserted values. | 
| FreeFunc | free_key | Function to free keys. | 
| FreeFunc | free_value | Function to free values. | 
| void ** | keys | Sorted array containing keys. | 
| struct _AssocArrayPair | pair | Last found key-value pair. | 
| size_t | size | Size of the array. | 
| void ** | values | Array containing values. | 
| struct AssocArray::_AssocArrayPair | 
A key-value pair.
Definition at line 60 of file assocarray.h.
| Data Fields | ||
|---|---|---|
| const struct _AssocArray * | array | Reference to the array. | 
| ssize_t | offset | Index of the found key-value pair. | 
| #define assoc_array_iter_key | ( | iter | ) | iter.array->keys[iter.offset] | 
Accesses the key of the current element directly.
Definition at line 240 of file assocarray.h.
| #define assoc_array_iter_value | ( | iter | ) | iter.array->values[iter.offset] | 
Accesses the value of the current element directly.
Definition at line 251 of file assocarray.h.
| #define ASSOC_ARRAY_MAX_SIZE (SSIZE_MAX / sizeof(void *)) | 
Supported maximum size.
Definition at line 31 of file assocarray.h.
| #define assoc_array_pair_key | ( | p | ) | p->array->keys[p->offset] | 
Accesses the key of a key-value pair directly.
Definition at line 168 of file assocarray.h.
| #define assoc_array_pair_value | ( | p | ) | p->array->values[p->offset] | 
Accesses the value of a key-value pair directly.
Definition at line 179 of file assocarray.h.
| typedef struct _AssocArrayPair AssocArrayIter | 
A structure to iterate over the elements of an AssocArray.
Definition at line 73 of file assocarray.h.
| typedef struct _AssocArrayPair AssocArrayPair | 
A found key-value pair.
Definition at line 70 of file assocarray.h.
result of assoc_array_set() method.
| Enumerator | |
|---|---|
| ASSOCARRAY_INSERT_RESULT_NEW | Item has been inserted. | 
| ASSOCARRAY_INSERT_RESULT_REPLACED | Item has been replaced. | 
| ASSOCARRAY_INSERT_RESULT_FAILED | Item insertion failed. | 
Definition at line 79 of file assocarray.h.
| void assoc_array_clear | ( | AssocArray * | array | ) | 
| array | an AssocArray | 
Removes all elements from the AssocArray.
Definition at line 170 of file assocarray.c.
| size_t assoc_array_count | ( | const AssocArray * | array | ) | 
| array | an AssocArray | 
Gets the number of stored elements.
Definition at line 437 of file assocarray.c.
| void assoc_array_destroy | ( | AssocArray * | array | ) | 
| array | an AssocArray | 
Frees all keys, values and the array pointer.
Definition at line 128 of file assocarray.c.
| void assoc_array_free | ( | AssocArray * | array | ) | 
| array | an AssocArray | 
Frees all keys and values without freeing the array pointer.
Definition at line 159 of file assocarray.c.
| void assoc_array_init | ( | AssocArray * | array, | 
| CompareFunc | compare_keys, | ||
| FreeFunc | free_key, | ||
| FreeFunc | free_value | ||
| ) | 
| array | an AssocArray | 
| compare_keys | function to compare two keys | 
| free_key | function to free keys or NULL | 
| free_value | function to free values or NULL | 
Initializes an AssocArray.
Definition at line 97 of file assocarray.c.
| void * assoc_array_iter_get_key | ( | const AssocArrayIter * | iter | ) | 
| iter | an AssocArrayIter | 
Retrieves the key of the current element.
Definition at line 473 of file assocarray.c.
| void * assoc_array_iter_get_value | ( | const AssocArrayIter * | iter | ) | 
| iter | an AssocArrayIter | 
Retrieves the value of the current element.
Definition at line 481 of file assocarray.c.
| void assoc_array_iter_init | ( | const AssocArray * | array, | 
| AssocArrayIter * | iter | ||
| ) | 
| array | an AssocArray | 
| iter | an uninitialized AssocArrayIter | 
Initializes a key/value pair iterator and associates it with the array. Modifying the array while using the iterator might lead to undefined behaviour.
Definition at line 453 of file assocarray.c.
| bool assoc_array_iter_next | ( | AssocArrayIter * | iter | ) | 
| iter | an AssocArrayIter | 
Goes to next element of an AssocArray.
Definition at line 463 of file assocarray.c.
| bool assoc_array_key_exists | ( | const AssocArray * | array, | 
| const void * | key | ||
| ) | 
| array | an AssocArray | 
| key | key to test | 
Checks if a key does exist.
Definition at line 421 of file assocarray.c.
| AssocArrayPair * assoc_array_lookup | ( | AssocArray * | array, | 
| const void * | key | ||
| ) | 
| array | an AssocArray | 
| key | key to lookup | 
Looks up a key-value pair in the AssocArray.
Definition at line 368 of file assocarray.c.
| AssocArray * assoc_array_new | ( | CompareFunc | compare_keys, | 
| FreeFunc | free_key, | ||
| FreeFunc | free_value | ||
| ) | 
| compare_keys | function to compare two keys | 
| free_key | function to free keys or NULL | 
| free_value | function to free values or NULL | 
Creates a new AssocArray.
Definition at line 79 of file assocarray.c.
| void * assoc_array_pair_get_key | ( | const AssocArrayPair * | pair | ) | 
| pair | a key-value pair | 
Retrieves the key of a key-value pair.
Definition at line 389 of file assocarray.c.
| void * assoc_array_pair_get_value | ( | const AssocArrayPair * | pair | ) | 
| pair | a key-value pair | 
Retrieves the value of a key-value pair.
Definition at line 398 of file assocarray.c.
| void assoc_array_pair_set_value | ( | AssocArrayPair * | pair, | 
| void * | value | ||
| ) | 
| pair | a AssocArrayPair | 
| value | new value to set | 
Overwrites the value of a key-value pair.
Definition at line 407 of file assocarray.c.
| void assoc_array_remove | ( | AssocArray * | array, | 
| const void * | key | ||
| ) | 
| array | an AssocArray | 
| key | key of the element to remove | 
Removes an element from the AssocArray.
Definition at line 335 of file assocarray.c.
| AssocArrayInsertResult assoc_array_set | ( | AssocArray * | array, | 
| void * | key, | ||
| void * | value, | ||
| bool | overwrite_key | ||
| ) | 
| array | an AssocArray | 
| key | key to insert | 
| value | the value to associate with the key | 
| overwrite_key | true to overwrite already exisiting keys | 
Inserts a new key and value in the AssocArray. If overwrite_key is set an existing key is freed using the specified free_key function before it gets replaced.
Definition at line 288 of file assocarray.c.
| size_t assoc_array_size | ( | const AssocArray * | array | ) | 
| array | an AssocArray | 
Gets the size of the array.
Definition at line 445 of file assocarray.c.