dynamiC
0.1
|
Macros | |
#define | DYN_DICT_LEN(dyn) dyn->data.dict->value.data.list->length |
Return number of elements within a dictionary. | |
#define | DYN_DICT_GET_I_REF(dyn, i) &(dyn)->data.dict->value.data.list->container[i] |
Return a reference to the ith element stored within a dictionary. | |
#define | DYN_DICT_GET_I_KEY(dyn, i) (dyn)->data.dict->key[i] |
Return a reference to the ith key stored within a dictionary. | |
#define | DYN_DICT_SPACE(dyn) dyn->value.data.list->space |
Return the maximal usable number of elements of a dictionary. | |
#define | DYN_DICT_LENGTH(dyn) dyn->value.data.list->length |
Return the number of elements stored within a dictionary. | |
Functions | |
trilean | dyn_set_dict (dyn_c *dyn, const dyn_ushort length) |
Set dyn to a dictionary with a max. length of elements. More... | |
trilean | dyn_dict_change (dyn_c *dict, const dyn_ushort i, const dyn_c *value) |
Replace the ith element in a dictionary with a new value. | |
dyn_c * | dyn_dict_insert (dyn_c *dict, dyn_const_str key, dyn_c *value) |
Insert a new key-value pair into the dictionary. More... | |
trilean | dyn_dict_remove (dyn_c *dict, dyn_const_str key) |
Remove key-value pair from dictionary. More... | |
dyn_c * | dyn_dict_get (const dyn_c *dict, dyn_const_str key) |
Get the reference to value stored at key. More... | |
trilean | dyn_dict_resize (dyn_c *dict, const dyn_ushort size) |
Set the available space for elements. More... | |
dyn_c * | dyn_dict_get_i_ref (const dyn_c *dict, const dyn_ushort i) |
Get the reference to ith value in dict. More... | |
dyn_str | dyn_dict_get_i_key (const dyn_c *dict, const dyn_ushort i) |
Get the reference to ith key in dict. More... | |
dyn_ushort | dyn_dict_has_key (const dyn_c *dict, dyn_const_str key) |
Check if dict has key and return its position - 1 (returns 0 if not found) More... | |
void | dyn_dict_empty (dyn_c *dict) |
todo More... | |
void | dyn_dict_free (dyn_c *dict) |
Free all allocated memory. More... | |
trilean | dyn_dict_copy (const dyn_c *dict, dyn_c *copy) |
Copy the entire dict. | |
dyn_ushort | dyn_dict_string_len (const dyn_c *dict) |
Calculate the required string length. | |
void | dyn_dict_string_add (const dyn_c *dict, dyn_str string) |
Add the dict-string representation to string. | |
void dyn_dict_empty | ( | dyn_c * | dict | ) |
todo
dict | to be freed has to be of type DICT |
DYN_TRUE | if the key value pair was found and removed |
Definition at line 229 of file dynamic_dict.c.
Referenced by dyn_dict_free().
void dyn_dict_free | ( | dyn_c * | dict | ) |
Free all allocated memory.
dict | has to be of type DICT |
Definition at line 245 of file dynamic_dict.c.
Referenced by dyn_free().
dyn_c* dyn_dict_get | ( | const dyn_c * | dict, |
dyn_const_str | key | ||
) |
Get the reference to value stored at key.
Searches the dictionary for a certain key and removes the key value pair. The last element is moved to the freed position to spare space, such that there are no free positions within the linear dictionary representation.
dict | has to be of type DICT |
key | of the key-value pair to remove |
Definition at line 264 of file dynamic_dict.c.
dyn_str dyn_dict_get_i_key | ( | const dyn_c * | dict, |
const dyn_ushort | i | ||
) |
Get the reference to ith key in dict.
This function is only used to offer an interface, such that values of the library can also be accsessed externally. Internally it is recommended to use the macro DYN_DICT_GET_I_KEY
dyn | has to be of type DICT |
i | position of the key |
Definition at line 183 of file dynamic_dict.c.
dyn_c* dyn_dict_get_i_ref | ( | const dyn_c * | dict, |
const dyn_ushort | i | ||
) |
Get the reference to ith value in dict.
This function is only used to offer an interface, such that values of the library can also be accsessed externally. Internally it is recommended to use the macro DYN_DICT_GET_I_REF
dict | has to be of type DICT |
i | position of the dynamic value |
Definition at line 168 of file dynamic_dict.c.
dyn_ushort dyn_dict_has_key | ( | const dyn_c * | dict, |
dyn_const_str | key | ||
) |
Check if dict has key and return its position - 1 (returns 0 if not found)
Searches the dictionary for a certain key, if this key could be found, then its position plus 1 is returned, to indicate that the key was found, even if it is on position 0, otherwise 0 is returned. Thus, the returned value has to be decreased by one if it is larger than 0.
dict | to be searched has to be of type DICT |
key | C-string to search for |
0 | if the key was not found |
position+1 | otherwise |
Definition at line 145 of file dynamic_dict.c.
Referenced by dyn_dict_get(), dyn_dict_insert(), and dyn_dict_remove().
dyn_c* dyn_dict_insert | ( | dyn_c * | dict, |
dyn_const_str | key, | ||
dyn_c * | value | ||
) |
Insert a new key-value pair into the dictionary.
If the key is already contained within the dictionary, then the current value is overwritten, if not then the new value is added to the end of the list as well as a new key. If the maximal space is exceeded, then new memory is attached as defined in DICT_DEFAULT.
[in,out] | dict | has to be of type DICT |
[in] | key | |
[in] | value | to be coppied |
Definition at line 65 of file dynamic_dict.c.
Referenced by dyn_dict_copy().
trilean dyn_dict_remove | ( | dyn_c * | dict, |
dyn_const_str | key | ||
) |
Remove key-value pair from dictionary.
Searches the dictionary for a certain key and removes the key value pair. The last element is moved to the freed position to spare space, such that there are no free positions within the linear dictionary representation.
dict | has to be of type DICT |
key | of the key-value pair to remove |
DYN_TRUE | if the key value pair was found and removed |
DYN_FALSE | otherwise |
Definition at line 199 of file dynamic_dict.c.
trilean dyn_dict_resize | ( | dyn_c * | dict, |
dyn_ushort | size | ||
) |
Set the available space for elements.
Increase or decrease the size of the dictionary to a new size, removed elements have to be of type NONE.
[in,out] | dict | has to be of type DICT |
[in] | size | new |
DYN_TRUE | if operation could be performed |
DYN_FALSE | otherwise |
Definition at line 108 of file dynamic_dict.c.
Referenced by dyn_dict_insert().
trilean dyn_set_dict | ( | dyn_c * | dyn, |
dyn_ushort | length | ||
) |
Set dyn to a dictionary with a max. length of elements.
[in,out] | dyn | element which is initialized as a dictionary |
[in] | length | of preallocated memory |
DYN_TRUE | if memory for the DICT could be allocated |
DYN_FALSE | otherwise |
Definition at line 25 of file dynamic_dict.c.
Referenced by dyn_dict_copy().