Public interface for a Olist class. More...
#include <Olist.h>
Related Functions | |
(Note that these are not member functions.) | |
void | Olist_append (Olist_ptr self, void *element) |
Adds at the end of a list a new element. | |
void | Olist_clean (Olist_ptr self) |
Removes all the elements of the list, i.e. makes the list empty. | |
void | Olist_concat (Olist_ptr self, Olist_ptr other) |
Adds all the elements of 'other' ath the end of 'self'. | |
boolean | Olist_contains (const Olist_ptr self, const void *element) |
Returns true iff the list contains the given element. | |
Olist_ptr | Olist_copy (Olist_ptr self) |
Creates a copy of a given list. | |
Olist_ptr | Olist_copy_reversed (Olist_ptr self) |
Creates a copy of a given list with the order of elements reversed. | |
Olist_ptr | Olist_copy_without_element (Olist_ptr self, void *element) |
Creates a copy of a given list with all its elements except the provided one. | |
Olist_ptr | Olist_create (void) |
Creates an instance of a One-directional List. | |
Oiter | Olist_delete (Olist_ptr self, Oiter iter, void **element) |
Removes an element pointed by an iterator from a list. | |
void * | Olist_delete_first (Olist_ptr self) |
Removes a first element of a list. | |
void | Olist_destroy (Olist_ptr self) |
Destroys a list instance. | |
Oiter | Olist_end (Olist_ptr self) |
Returns an iterator pointing past the last element of the list. | |
Oiter | Olist_first (Olist_ptr self) |
Returns an iterator pointing to a first element of a list. | |
int | Olist_get_size (const Olist_ptr self) |
Returns the size of a list. | |
Oiter | Olist_insert_after (Olist_ptr self, Oiter iter, void *element) |
Insert a new element into the list "self" directly after an element pointed by "iter". | |
Oiter | Olist_insert_before (Olist_ptr self, Oiter iter, void *element) |
Insert a new element into the list "self" directly before an element pointed by "iter". | |
boolean | Olist_is_empty (Olist_ptr self) |
Returns true iff the list is empty. | |
boolean | Olist_iter_is_first (Olist_ptr self, Oiter iter) |
Returns true if iter corresponds to the first iter. | |
boolean | Olist_iter_is_last (Olist_ptr self, Oiter iter) |
Returns true if iter corresponds to the last element. | |
Oiter | Olist_last (Olist_ptr self) |
Returns an iterator pointing the last element of the list. | |
void | Olist_map (Olist_ptr self, void(*func)(void *elem)) |
Functional programming map. | |
void | Olist_move (Olist_ptr self, Olist_ptr to_list, Oiter iter_to) |
Moves the content from one list to another. | |
void | Olist_move_all (Olist_ptr self, Olist_ptr to_list) |
Moves the content from one list to another. | |
void | Olist_prepend (Olist_ptr self, void *element) |
Adds at the beginning of a list a new element. | |
void | Olist_print_node (Olist_ptr self, MasterPrinter_ptr printer, FILE *output) |
Prints the elements of the list using print_node and putting string ", " between elements. | |
boolean | Olist_remove (Olist_ptr self, const void *element) |
Tries to remove all the occurrences of the specified element from the list, returns true if an element was removed, false otherwise. | |
void | Olist_reverse (Olist_ptr self) |
Reverse the order of elements in the list. | |
void | Olist_sort (Olist_ptr self, int(*cmp)(void *el1, void *el2, void *extra), void *extra) |
Sorts the list in place. |
Public interface for a Olist class.
Implementation of Olist class
void Olist_append | ( | Olist_ptr | self, | |
void * | element | |||
) | [related] |
Adds at the end of a list a new element.
void Olist_clean | ( | Olist_ptr | self | ) | [related] |
Removes all the elements of the list, i.e. makes the list empty.
After this function call, Olist_is_empty(self) always returns true.
Note: all existing iterators pointing to the elements of the list becomes invalid.
Adds all the elements of 'other' ath the end of 'self'.
Linear in the size of 'other'
Returns true iff the list contains the given element.
Creates a copy of a given list with the order of elements reversed.
Note: input list does not change
Creates a copy of a given list with all its elements except the provided one.
Note: input list does not change
Olist_ptr Olist_create | ( | void | ) | [related] |
Creates an instance of a One-directional List.
Removes an element pointed by an iterator from a list.
Precondition: iter must point to elements of list "self" and NOT the past the last element of the list.
The element being removed is returned in argument *element (only if element != NULL).
Returns an iterator pointing to the element after removed one.
NOTE: all iterators already pointing to the next element will become invalid. Any operations on them are prohibited. ADVICE: do not use several iterators over the same list if deletion operation is possible.
NOTE: if the deletion is used inside an OLIST_FOREACH macro cycle it must be considered that the next element will not be the one after the current deleted element, but the next of it.
void * Olist_delete_first | ( | Olist_ptr | self | ) | [related] |
Removes a first element of a list.
The removed element is returned. Precondition: the list must not be empty.
NOTE: all iterators already pointing to the element next to the first one will become invalid. Any operations on them are prohibited. ADVICE: do not use several iterators over the same list if deletion operation is possible.
void Olist_destroy | ( | Olist_ptr | self | ) | [related] |
Destroys a list instance.
The memory used by the list will be freed. Note: memory occupied by the elements is not freed! It is the user responsibility.
Returns an iterator pointing past the last element of the list.
Function Oiter_is_end will always return true on the result of this function. NOTE: there is no need to free the iterator after using it. NOTE: it is allowed to assign one iterator to another one. NOTE: deletion the elements of the list may make the iterator invalid (see corresponding delete functions).
Returns an iterator pointing to a first element of a list.
If the list is empty the iterator will point past the last element of a list (i.e. past the list). This means function Oiter_is_end will return true in this case. NOTE: there is no need to free the iterator after using it. NOTE: it is allowed to assign one iterator to another one. NOTE: deletion the elements of the list may make the iterator invalid (see corresponding delete functions).
int Olist_get_size | ( | const Olist_ptr | self | ) | [related] |
Returns the size of a list.
Insert a new element into the list "self" directly after an element pointed by "iter".
Precondition: iter must point to elements of list "self" and NOT past the last element of the list. If iter is not an iterator of list self there will be problems with memory which are usually very difficult to debug.
NOTE: after the function call iterators pointing to the element after iter will now point to the newly inserted element. All other existing iterators (including iter) will point to the same element as before.
Returns an iterator pointing to the newly inserted element.
Insert a new element into the list "self" directly before an element pointed by "iter".
Precondition: iter must point to elements of list "self" or past the last element of the list.
If the iterator points past the last element of a list then this function is equivalent to calling Olist_append(self, element).
NOTE: All existing iterators equal to "iter" (and iter itself) after insertion will point to the newly created element. All other iterators remain intact.
Returns an iterator pointing to the newly inserted element.
Returns true if iter corresponds to the first iter.
Returns true if iter corresponds to the last element.
Returns an iterator pointing the last element of the list.
Function Oiter_is_end will always return true on the result of this function. NOTE: there is no need to free the iterator after using it. NOTE: it is allowed to assign one iterator to another one. NOTE: deletion the elements of the list may make the iterator invalid (see corresponding delete functions).
void Olist_map | ( | Olist_ptr | self, | |
void(*)(void *elem) | func | |||
) | [related] |
Functional programming map.
Call func over each element of the list. Very useful for example for freeing the elements
Moves the content from one list to another.
The content is moved from "self" to "to_list" and placed before iterator iter_to.
Note: all existing iterators pointing to the elements of the lists may become invalid.
Precondition: iter_to has to be an iterator of list 'to_list' or Oiter_is_end(iter_to) has to be return true.
Moves the content from one list to another.
This function is similar to Olist_move with iter_to set up to point past the last element. Note: all existing iterators pointing to the elements of the list may become invalid.
void Olist_prepend | ( | Olist_ptr | self, | |
void * | element | |||
) | [related] |
Adds at the beginning of a list a new element.
void Olist_print_node | ( | Olist_ptr | self, | |
MasterPrinter_ptr | printer, | |||
FILE * | output | |||
) | [related] |
Prints the elements of the list using print_node and putting string ", " between elements.
Precondition: all elements of the list have to be node_ptr.
Tries to remove all the occurrences of the specified element from the list, returns true if an element was removed, false otherwise.
void Olist_reverse | ( | Olist_ptr | self | ) | [related] |
Reverse the order of elements in the list.
Note: all existing iterators pointing to the elements of the list may become invalid.
void Olist_sort | ( | Olist_ptr | self, | |
int(*)(void *el1, void *el2, void *extra) | cmp, | |||
void * | extra | |||
) | [related] |
Sorts the list in place.
mergesort is used to sort the list. worst case complexisty O(N log2(N)).
cmp is comparison function returning value v, v < 0, v == 0 or v > 0, extra is a user parameter that is passed to every invocation of cmp