The header file of NodeList class. More...
#include <NodeList.h>
Related Functions | |
(Note that these are not member functions.) | |
void | NodeList_append (NodeList_ptr self, node_ptr elem) |
Appends a new node at the end of the list. | |
boolean | NodeList_belongs_to (const NodeList_ptr self, node_ptr elem) |
Returns true if given element belongs to self. | |
void | NodeList_concat (NodeList_ptr self, const NodeList_ptr src) |
Append all the elements in src to self. | |
void | NodeList_concat_unique (NodeList_ptr self, const NodeList_ptr src) |
Append all the elements in src to self, but only if each element does not occur in self already. | |
NodeList_ptr | NodeList_copy (NodeList_ptr self) |
Copies self and returns a new independent instance. | |
int | NodeList_count_elem (const NodeList_ptr self, node_ptr elem) |
Returns the number of occurrences of the given element. | |
NodeList_ptr | NodeList_create (void) |
Creates a new list. | |
NodeList_ptr | NodeList_create_from_element (node_ptr node) |
Creates a singleton nodelist. | |
NodeList_ptr | NodeList_create_from_list (node_ptr list) |
Constructor that creates a new NodeList that is a wrapper of the given list. | |
void | NodeList_destroy (NodeList_ptr self) |
Class destroyer. | |
NodeList_ptr | NodeList_filter (const NodeList_ptr self, BPFN foo) |
Returns a new list that contains all elements of self for which function foo returned true. | |
int | NodeList_foreach (NodeList_ptr self, NODE_LIST_FOREACH_FUN_P foo, void *user_data) |
Walks through the list, calling given funtion for each element. | |
node_ptr | NodeList_get_elem_at (const NodeList_ptr self, const ListIter_ptr iter) |
Returns the element at the position pointed by iter. | |
ListIter_ptr | NodeList_get_first_iter (const NodeList_ptr self) |
Returns the iterator pointing to the first element. | |
int | NodeList_get_length (const NodeList_ptr self) |
Returns the number of elements in the list. | |
void | NodeList_insert_after (NodeList_ptr self, ListIter_ptr iter, node_ptr elem) |
Inserts the given element after the node pointed by the given iterator. | |
void | NodeList_insert_before (NodeList_ptr self, ListIter_ptr iter, node_ptr elem) |
Inserts the given element before the node pointed by the given iterator. | |
boolean | NodeList_is_empty (const NodeList_ptr self) |
Returns true iff the size of the list is 0. | |
NodeList_ptr | NodeList_map (const NodeList_ptr self, NPFN foo) |
Returns a new list that contains all elements of self, after applying function foo to each element. | |
void | NodeList_prepend (NodeList_ptr self, node_ptr elem) |
Prepends a new node at the beginning of the list. | |
void | NodeList_print_nodes (const NodeList_ptr self, MasterPrinter_ptr printer, FILE *out) |
Prints the nodes in the list, separated by spaces. | |
node_ptr | NodeList_remove_elem_at (NodeList_ptr self, ListIter_ptr iter) |
Removes the element pointed by the given iterator. | |
int | NodeList_remove_elems (NodeList_ptr self, const NodeList_ptr other, NodeListPred disposer, void *disposer_arg) |
Removes the elements that are found in other list. | |
void | NodeList_reverse (NodeList_ptr self) |
Reverses the list. | |
ListIter_ptr | NodeList_search (const NodeList_ptr self, NodeListPred pred, void *arg) |
Searches for an element in a list such that 'pred'(element, 'arg') returns true. | |
void | NodeList_sort (NodeList_ptr self, int(*cmp)(const void *el1, const void *el2)) |
Sorts self, using a support array. |
The header file of NodeList class.
A list based on (and compatible with) node_ptr lists
void NodeList_append | ( | NodeList_ptr | self, | |
node_ptr | elem | |||
) | [related] |
Appends a new node at the end of the list.
Constant time
boolean NodeList_belongs_to | ( | const NodeList_ptr | self, | |
node_ptr | elem | |||
) | [related] |
Returns true if given element belongs to self.
Constant time (cost may depend on the internal hash status)
void NodeList_concat | ( | NodeList_ptr | self, | |
const NodeList_ptr | src | |||
) | [related] |
Append all the elements in src to self.
Cost is linear in the size of src
Content of self will change is src is not empty
void NodeList_concat_unique | ( | NodeList_ptr | self, | |
const NodeList_ptr | src | |||
) | [related] |
Append all the elements in src to self, but only if each element does not occur in self already.
Cost is linear in the size of src
Content of self may change is src is not empty
NodeList_ptr NodeList_copy | ( | NodeList_ptr | self | ) | [related] |
Copies self and returns a new independent instance.
Linear time
int NodeList_count_elem | ( | const NodeList_ptr | self, | |
node_ptr | elem | |||
) | [related] |
Returns the number of occurrences of the given element.
Constant time (cost may depend on the internal hash status)
NodeList_ptr NodeList_create | ( | void | ) | [related] |
Creates a new list.
NodeList_ptr NodeList_create_from_element | ( | node_ptr | node | ) | [related] |
Creates a singleton nodelist.
Must be freed by the caller
NodeList_ptr NodeList_create_from_list | ( | node_ptr | list | ) | [related] |
Constructor that creates a new NodeList that is a wrapper of the given list.
self becomes a user of the given list, meaning that when self will be destroyed, it will not free the given list. It is a caller responsability of freeing the passed list when possible.
void NodeList_destroy | ( | NodeList_ptr | self | ) | [related] |
Class destroyer.
NodeList_ptr NodeList_filter | ( | const NodeList_ptr | self, | |
BPFN | foo | |||
) | [related] |
Returns a new list that contains all elements of self for which function foo returned true.
Elements are not copied. Returned list must be freed by the caller
int NodeList_foreach | ( | NodeList_ptr | self, | |
NODE_LIST_FOREACH_FUN_P | foo, | |||
void * | user_data | |||
) | [related] |
Walks through the list, calling given funtion for each element.
Returns the number of visited nodes, which can be less than the total number of elements since foo can decide to interrupt the walking
node_ptr NodeList_get_elem_at | ( | const NodeList_ptr | self, | |
const ListIter_ptr | iter | |||
) | [related] |
Returns the element at the position pointed by iter.
ListIter_ptr NodeList_get_first_iter | ( | const NodeList_ptr | self | ) | [related] |
Returns the iterator pointing to the first element.
int NodeList_get_length | ( | const NodeList_ptr | self | ) | [related] |
Returns the number of elements in the list.
Constant time
void NodeList_insert_after | ( | NodeList_ptr | self, | |
ListIter_ptr | iter, | |||
node_ptr | elem | |||
) | [related] |
Inserts the given element after the node pointed by the given iterator.
Constant time. iter must be a valid iterator, and cannot point at the end of the list
void NodeList_insert_before | ( | NodeList_ptr | self, | |
ListIter_ptr | iter, | |||
node_ptr | elem | |||
) | [related] |
Inserts the given element before the node pointed by the given iterator.
Constant time
boolean NodeList_is_empty | ( | const NodeList_ptr | self | ) | [related] |
Returns true iff the size of the list is 0.
NodeList_ptr NodeList_map | ( | const NodeList_ptr | self, | |
NPFN | foo | |||
) | [related] |
Returns a new list that contains all elements of self, after applying function foo to each element.
Elements are not copied. Returned list must be freed by the caller
void NodeList_prepend | ( | NodeList_ptr | self, | |
node_ptr | elem | |||
) | [related] |
Prepends a new node at the beginning of the list.
Constant time
void NodeList_print_nodes | ( | const NodeList_ptr | self, | |
MasterPrinter_ptr | printer, | |||
FILE * | out | |||
) | [related] |
Prints the nodes in the list, separated by spaces.
The list must be a list of actual node_ptr
node_ptr NodeList_remove_elem_at | ( | NodeList_ptr | self, | |
ListIter_ptr | iter | |||
) | [related] |
Removes the element pointed by the given iterator.
The removed element is returned. The given iterator won't be usable anymore. Constant time.
int NodeList_remove_elems | ( | NodeList_ptr | self, | |
const NodeList_ptr | other, | |||
NodeListPred | disposer, | |||
void * | disposer_arg | |||
) | [related] |
Removes the elements that are found in other list.
Linear time on the size of self. No iteration is done if other is empty. If not NULL, disposer is called on the removed element, passing disposer_arg. If the disposer returns true, the removal continues, otherwise it aborts and returns with the list as it is at that time. Returns the number of removed elements
void NodeList_reverse | ( | NodeList_ptr | self | ) | [related] |
Reverses the list.
Linear time
ListIter_ptr NodeList_search | ( | const NodeList_ptr | self, | |
NodeListPred | pred, | |||
void * | arg | |||
) | [related] |
Searches for an element in a list such that 'pred'(element, 'arg') returns true.
Linear time search is used to find an element 'elem' such that function pred(elem, arg) returns true. An iterator pointing to the found element is returned. If the element is not found then ListIter_is_end will be true on the returned iterator.
If pred is NULL then a search for an element equal to arg will be done (as if pred was a pointer-equality predicate). If pred is NULL and the searched element does not occur in the list, the function returns in constant time.
void NodeList_sort | ( | NodeList_ptr | self, | |
int(*)(const void *el1, const void *el2) | cmp | |||
) | [related] |
Sorts self, using a support array.
qsort is used