| libdatatypes 0.3.2
    Abstract datatypes for C. | 
Generic associative array. More...
#include <stdio.h>#include <stdlib.h>#include <stddef.h>#include <assert.h>#include <string.h>#include <limits.h>#include "assocarray.h"Go to the source code of this file.
Generic associative array.
Definition in file assocarray.c.
| #define _GNU_SOURCE | 
Definition at line 22 of file assocarray.c.
| 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.