34_assoc_array_binary_search(
CompareFunc compare, 
void **keys, 
size_t len, 
const void *key, ssize_t *index)
 
   38    assert(compare != NULL);
 
   42    assert(index != NULL);
 
   47        result = compare(key, *keys);
 
   52        ssize_t end = len - 1;
 
   56            *index = (begin + end) / 2;
 
   58            result = compare(key, keys[*index]);
 
   81    assert(compare_keys != NULL);
 
 
   99    assert(array != NULL);
 
  100    assert(compare_keys != NULL);
 
  110    array->
keys = (
void **)calloc(array->
size, 
sizeof(
void *));
 
  118    array->
values = (
void **)calloc(array->
size, 
sizeof(
void *));
 
 
  130    assert(array != NULL);
 
 
  139    assert(array != NULL);
 
  143        for(
size_t i = 0; i < array->
count; ++i)
 
  161    assert(array != NULL);
 
  163    _assoc_array_free_memory(array);
 
 
  172    assert(array != NULL);
 
  174    _assoc_array_free_memory(array);
 
 
  179_assoc_array_insert_first(
AssocArray *array, 
void *key, 
void *value)
 
  181    assert(array != NULL);
 
  190_assoc_array_replace(
AssocArray *array, 
void *key, 
void *value, ssize_t offset, 
bool overwrite_key)
 
  192    assert(array != NULL);
 
  194    assert(offset >= 0 && array->
count > (
size_t)offset);
 
  203        array->
keys[offset] = key;
 
  211    array->
values[offset] = value;
 
  215_assoc_array_resize_if_necessary(
AssocArray *array)
 
  217    assert(array != NULL);
 
  223            fprintf(stderr, 
"%s(): array exceeds size limit.\n", __func__);
 
  236        array->
keys = (
void **)realloc(array->
keys, array->
size * 
sizeof(
void *));
 
  244        array->
values = (
void **)realloc(array->
values, array->
size * 
sizeof(
void *));
 
  255_assoc_array_insert_before_offset(
AssocArray *array, 
void *key, 
void *value, ssize_t offset)
 
  257    assert(array != NULL);
 
  259    assert(offset >= 0 && array->
count > (
size_t)offset);
 
  261    memmove(&array->
keys[offset + 1], &array->
keys[offset], (array->
count - offset) * 
sizeof(
void *));
 
  262    memmove(&array->
values[offset + 1], &array->
values[offset], (array->
count - offset) * 
sizeof(
void *));
 
  264    array->
keys[offset] = key;
 
  265    array->
values[offset] = value;
 
  269_assoc_array_insert_after_offset(
AssocArray *array, 
void *key, 
void *value, ssize_t offset)
 
  271    assert(array != NULL);
 
  273    assert(offset >= 0 && array->
count > (
size_t)offset);
 
  277    if((
size_t)offset < array->count)
 
  279        memmove(&array->
keys[offset + 1], &array->
keys[offset], (array->
count - offset) * 
sizeof(
void *));
 
  280        memmove(&array->
values[offset + 1], &array->
values[offset], (array->
count - offset) * 
sizeof(
void *));
 
  283    array->
keys[offset] = key;
 
  284    array->
values[offset] = value;
 
  292    assert(array != NULL);
 
  304            _assoc_array_resize_if_necessary(array);
 
  308                _assoc_array_insert_before_offset(array, key, value, offset);
 
  312                _assoc_array_insert_after_offset(array, key, value, offset);
 
  321            _assoc_array_replace(array, key, value, offset, overwrite_key);
 
  328        _assoc_array_insert_first(array, key, value);
 
 
  337    assert(array != NULL);
 
  356            if((
size_t)offset < array->count - 1)
 
  358                memmove(&array->
keys[offset], &array->
keys[offset + 1], (array->
count - 1 - offset) * 
sizeof(
void *));
 
  359                memmove(&array->
values[offset], &array->
values[offset + 1], (array->
count - 1 - offset) * 
sizeof(
void *));
 
 
  370    assert(array != NULL);
 
 
  391    assert(pair != NULL);
 
  392    assert(pair->array != NULL);
 
  394    return pair->array->keys[pair->offset];
 
 
  400    assert(pair != NULL);
 
  401    assert(pair->array != NULL);
 
  403    return pair->array->values[pair->offset];
 
 
  409    assert(pair != NULL);
 
  410    assert(pair->array != NULL);
 
  412    if(pair->array->free_value && pair->array->values[pair->offset])
 
  414        pair->array->free_value(pair->array->values[pair->offset]);
 
  417    pair->array->values[pair->offset] = value;
 
 
  423    assert(array != NULL);
 
 
  439    assert(array != NULL);
 
 
  447    assert(array != NULL);
 
 
  455    assert(array != NULL);
 
  456    assert(iter != NULL);
 
 
  465    assert(iter != NULL);
 
  469    return (
size_t)iter->offset < iter->array->count;
 
 
  475    assert(iter != NULL);
 
  477    return iter->array->keys[iter->offset];
 
 
  483    assert(iter != NULL);
 
  485    return iter->array->values[iter->offset];
 
 
void assoc_array_iter_init(const AssocArray *array, AssocArrayIter *iter)
void assoc_array_init(AssocArray *array, CompareFunc compare_keys, FreeFunc free_key, FreeFunc free_value)
void assoc_array_pair_set_value(AssocArrayPair *pair, void *value)
void * assoc_array_iter_get_value(const AssocArrayIter *iter)
AssocArray * assoc_array_new(CompareFunc compare_keys, FreeFunc free_key, FreeFunc free_value)
void * assoc_array_iter_get_key(const AssocArrayIter *iter)
AssocArrayPair * assoc_array_lookup(AssocArray *array, const void *key)
void * assoc_array_pair_get_value(const AssocArrayPair *pair)
bool assoc_array_iter_next(AssocArrayIter *iter)
void assoc_array_remove(AssocArray *array, const void *key)
bool assoc_array_key_exists(const AssocArray *array, const void *key)
void assoc_array_clear(AssocArray *array)
size_t assoc_array_size(const AssocArray *array)
void assoc_array_free(AssocArray *array)
size_t assoc_array_count(const AssocArray *array)
AssocArrayInsertResult assoc_array_set(AssocArray *array, void *key, void *value, bool overwrite_key)
void assoc_array_destroy(AssocArray *array)
void * assoc_array_pair_get_key(const AssocArrayPair *pair)
Generic associative array.
#define ASSOC_ARRAY_MAX_SIZE
AssocArrayInsertResult
result of assoc_array_set() method.
@ ASSOCARRAY_INSERT_RESULT_NEW
@ ASSOCARRAY_INSERT_RESULT_REPLACED
@ ASSOCARRAY_INSERT_RESULT_FAILED
struct AssocArray::_AssocArrayPair pair
Last found key-value pair.
struct _AssocArrayPair AssocArrayIter
struct _AssocArrayPair AssocArrayPair
const struct _AssocArray * array
Array containing associations between keys and values.
int32_t(* CompareFunc)(const void *a, const void *b)
void(* FreeFunc)(void *p)