P_Group group_create()

- create a group-structure

void delete_group(g, elem_free)

- delete a group-structure P_Group g; func elem_free;

All these functions work on a group-structure. group_create() creates a new group-structure with one element in it. This element is the null-element. The datastructure is a cyclic double linked list. The function group_delete() deletes the group. All elements in the group are deleted by using the function elem_free.

void group_insert(g, elem)

- add an element to the group P_Group g; void *elem;

void group_add(g, elem)

- add an element to the group P_Group g; void *elem;

Bool group_add_unique(group, elem, equal)

- add unique element P_Group group; void *elem; IntFunction equal;

To add elements to a group, group_add() is used. The element is added at the end of the list. group_insert() adds the element at the beginning of the list. To add only unique elements to the group, group_add_unique() is used. When elem is already in the group, it is not added and FALSE is returned, otherwise elem is added. The function equal defines the comparison of two elements in a group. The group can be used for integers but also for strings, structures, etc.

P_Iterator group_iterator(g)

- return an iterator to a group P_Group g;

void* iter_next(it)

- return the next element in the group P_Iterator *it;

void* iter_previous(it)

- return the previous element in the group P_Iterator *it;

void* iterator_elem(it)

- return the current element P_Iterator it;

To visit every element in the double linked list, an iterator is used. To create an iterator for a specific group group_iterator() is called. There can be different iterators for the same group at the same time. When calling iter_next() (iter_previous()) with as parameter the iterator, the next (previous) element in the group is returned. The iterator is set to the next (previous) group-element. To retrieve the element of the group-element indicated by it, iterator_elem() is used, the iterator is not changed.

void group_delete(tmp, elem_free)

- delete a link-element. P_Iterator tmp; func elem_free;

void group_del_next(g, iter, elem_free)

- delete the element, go to the next P_Group g; P_Iterator *iter; func elem_free;

void group_del_previous(g, iter, elem_free)

- delete the element, go to the previous P_Group g; P_Iterator *iter; func elem_free;

To delete a specific element in the group, group_del_previous() and group_del_next() are used. The difference between them is the position of the iterator after deletion. group_del_previous() (group_del_next()) sets iter on the previous (next) element in the group. If the group consist only of the null-element, i.e. the group is empty, no action is taken. The element is deleted using elem_free.

Both functions use group_delete() to do the deletion. tmp indicates the element to be deleted.

void group_print(file, g)

- print a group on file FILE *file; P_Group g;

The content of the group is printed on file. The elements of the group must represents strings. This procedure is used for debugging purposes and for error reports.

group.c group.h