dynamiC
0.1
|
All list related functions. More...
Macros | |
#define | DYN_SET_LIST(dyn) dyn_set_list_len(dyn, LIST_DEFAULT) |
Initialize dyn as list with default length. | |
#define | DYN_LIST_LEN(dyn) (dyn)->data.list->length |
Return list length. | |
#define | DYN_LIST_GET_REF(dyn, i) &(dyn)->data.list->container[i] |
Return the reference to the ith element within a dynamic list. | |
#define | DYN_LIST_GET_END(dyn) &(dyn)->data.list->container[DYN_LIST_LEN(dyn)-1] |
Return the reference to the last element within a list. | |
#define | DYN_LIST_GET_REF_END(dyn, i) &(dyn)->data.list->container[DYN_LIST_LEN(dyn)-i] |
Return the reference to the ith element starting from the last. | |
Functions | |
trilean | dyn_set_list_len (dyn_c *dyn, dyn_ushort len) |
Set dynamic element to list with maximal length. More... | |
dyn_c * | dyn_list_push (dyn_c *list, const dyn_c *element) |
Push new element to the end of a list. More... | |
dyn_c * | dyn_list_push_none (dyn_c *list) |
Push NONE element to the end of a list. More... | |
trilean | dyn_list_pop (dyn_c *list, dyn_c *element) |
Pop the last element from the list and move it to param element. More... | |
trilean | dyn_list_get (const dyn_c *list, dyn_c *element, const dyn_short i) |
Copy the ith element of a list to param element. More... | |
dyn_c * | dyn_list_get_ref (const dyn_c *list, const dyn_short i) |
Return a reference to the ith element within list, negative values are allowed. More... | |
trilean | dyn_list_popi (dyn_c *list, const dyn_short i) |
Pop i elements from the end of a list. More... | |
void | dyn_list_free (dyn_c *list) |
Free the allocated memory of the entire list and set it to NONE. More... | |
trilean | dyn_list_copy (const dyn_c *list, dyn_c *copy) |
Make a deep copy of the entire list. More... | |
trilean | dyn_list_remove (dyn_c *list, dyn_ushort i) |
Delete the ith element from a list. More... | |
trilean | dyn_list_insert (dyn_c *list, dyn_c *element, const dyn_ushort i) |
Insert a new element at the ith position into a list. More... | |
trilean | dyn_list_resize (dyn_c *list, const dyn_ushort size) |
Change the maximal space of a list. More... | |
dyn_ushort | dyn_list_string_len (const dyn_c *list) |
Return the length of the string representation of a list. More... | |
void | dyn_list_string_add (const dyn_c *list, dyn_str str) |
Add string representation of a list to str. More... | |
All list related functions.
Make a deep copy of the entire list.
[in] | list | original |
[in,out] | copy | new list |
DYN_TRUE | if the element was found and coppied |
DYN_FALSE | otherwise |
Definition at line 308 of file dynamic_list.c.
Referenced by dyn_get_bool().
void dyn_list_free | ( | dyn_c * | dyn | ) |
Free the allocated memory of the entire list and set it to NONE.
[in,out] | list | input put has to be a list |
Definition at line 67 of file dynamic_list.c.
Referenced by dyn_free().
Copy the ith element of a list to param element.
Copies the i value in the list to element
. If the i value is negative, then the i value is relative to the last value (-1). If only the reference to the value in the list is required, use dyn_list_get_ref
[in] | list | input has to be of type LIST |
[in,out] | element | to copy to |
[in] | i | position in list |
DYN_TRUE | if the element was found and coppied |
DYN_FALSE | otherwise |
Definition at line 264 of file dynamic_list.c.
Return a reference to the ith element within list, negative values are allowed.
Returns the reference of the i value in list, if a negative position value is used, then the position is calculated from the end. And if the i position exceeds the length of the list, NULL is returned.
list | input has to be of type LIST |
i | position in list |
Definition at line 289 of file dynamic_list.c.
Referenced by dyn_dict_get_i_ref(), and dyn_list_get().
trilean dyn_list_insert | ( | dyn_c * | list, |
dyn_c * | element, | ||
const dyn_ushort | i | ||
) |
Insert a new element at the ith position into a list.
Insert a new element at position i to a list, all other elements with pos>i are shifted "to the left" befor the element gets inserted (moved).
[in,out] | list | input has to be of type LIST |
[in] | element | to be inserted |
[in] | i | position |
DYN_TRUE | if the required memory could be allocated |
Definition at line 199 of file dynamic_list.c.
Pop the last element from the list and move it to param element.
Pops the last element from the list and moves its content to parameter element. The length of the list decreases by one.
[in,out] | list | input has to be of type LIST |
[in,out] | element | where last dynamic value is moved to |
DYN_TRUE | if worked properly |
Definition at line 225 of file dynamic_list.c.
Pop i elements from the end of a list.
[in,out] | list | input has to be of type LIST |
[in] | i | number of elements to be popped |
Definition at line 242 of file dynamic_list.c.
Referenced by dyn_list_remove().
Push new element to the end of a list.
Pushes (copies) an additional element to the end of a list and increases the length value by one. If the maximal available space is reached, then new memory is allocated and the maximal space value gets increased, this additional size value is defined in LIST_DEFAULT.
[in,out] | list | input has to be of type LIST |
[in] | element | to be pushed |
Definition at line 124 of file dynamic_list.c.
Referenced by dyn_list_copy(), and dyn_set_insert().
Push NONE element to the end of a list.
Increses the length value of the list by one and returns a reference to the last NONE element of the list. This reference can be used to move a larger element to the end of a list, without copying.
[in,out] | list | input has to be of type LIST |
Definition at line 146 of file dynamic_list.c.
Referenced by dyn_list_insert().
trilean dyn_list_remove | ( | dyn_c * | list, |
dyn_ushort | i | ||
) |
Delete the ith element from a list.
Delete an element from the list at position i, successive elements are moved to close this gap. This function can be interpeted as the opposite to dyp_list_insert
[in,out] | list | input has to be of type LIST |
[in] | i | position to remove |
DYN_TRUE | if the required memory could be allocated |
DYN_FALSE | otherwise |
Definition at line 172 of file dynamic_list.c.
trilean dyn_list_resize | ( | dyn_c * | list, |
dyn_ushort | size | ||
) |
Change the maximal space of a list.
Resize the maximal usable space, if the size decreases then the removed elements have to be removed previously.
[in,out] | list | input put has to be a list |
[in] | size | new maximal available space |
DYN_TRUE | if the required memory could be allocated |
DYN_FALSE | otherwise |
Definition at line 91 of file dynamic_list.c.
Referenced by dyn_dict_resize(), dyn_list_push(), and dyn_list_push_none().
Add string representation of a list to str.
Generates a string representation of the list and all included element, segregated by commas, and attaches it to the end of the string.
[in] | list | input has to be of type LIST |
[in,out] | str | with added list representation |
Definition at line 351 of file dynamic_list.c.
Referenced by dyn_get_bool().
dyn_ushort dyn_list_string_len | ( | const dyn_c * | list | ) |
Return the length of the string representation of a list.
The length of the list string representation is calculated by the length of all included elemens plus 2 brackets and the number of commas.
list | input has to be of type LIST |
Definition at line 333 of file dynamic_list.c.
Referenced by dyn_get_bool().
trilean dyn_set_list_len | ( | dyn_c * | dyn, |
dyn_ushort | len | ||
) |
Set dynamic element to list with maximal length.
Takes in any kind of dynamic paramter, frees all allocated memory and allocates a new array of dynamic elemens with a length defined in paramter len. The len paramter us used to denote the max space available space, initially the lenght of a list is marked as empty. Every application of of dyn_list_push increases the internal counter of dyn->data.list->len, until the max value dyn->data.list->space is reached, if so, new memory is allocated automatically. Every popped value by applying dyn_list_pop decreases the internal counter.
[in,out] | dyn | input any, output LIST |
[in] | len |
DYN_TRUE | if the required memory could be allocated |
DYN_FALSE | otherwise |
Definition at line 37 of file dynamic_list.c.
Referenced by dyn_list_copy(), dyn_set_dict(), and dyn_set_set_len().