girara
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros
Data Structures | Functions
datastructures.c File Reference
#include <stdlib.h>
#include <glib.h>
#include "datastructures.h"
#include "utils.h"

Go to the source code of this file.

Data Structures

struct  girara_tree_node_t
struct  girara_tree_node_data_t
struct  girara_list_t
struct  girara_list_iterator_t

Functions

girara_list_t * girara_list_new (void)
girara_list_t * girara_list_new2 (girara_free_function_t gfree)
girara_list_t * girara_sorted_list_new (girara_compare_function_t cmp)
girara_list_t * girara_sorted_list_new2 (girara_compare_function_t cmp, girara_free_function_t gfree)
void girara_list_set_free_function (girara_list_t *list, girara_free_function_t gfree)
void girara_list_clear (girara_list_t *list)
void girara_list_free (girara_list_t *list)
void girara_list_append (girara_list_t *list, void *data)
void girara_list_prepend (girara_list_t *list, void *data)
void girara_list_remove (girara_list_t *list, void *data)
void * girara_list_nth (girara_list_t *list, size_t n)
bool girara_list_contains (girara_list_t *list, void *data)
void * girara_list_find (girara_list_t *list, girara_compare_function_t compare, const void *data)
girara_list_iterator_t * girara_list_iterator (girara_list_t *list)
girara_list_iterator_t * girara_list_iterator_copy (girara_list_iterator_t *iter)
girara_list_iterator_t * girara_list_iterator_next (girara_list_iterator_t *iter)
bool girara_list_iterator_has_next (girara_list_iterator_t *iter)
girara_list_iterator_t * girara_list_iterator_previous (girara_list_iterator_t *iter)
bool girara_list_iterator_has_previous (girara_list_iterator_t *iter)
void girara_list_iterator_remove (girara_list_iterator_t *iter)
bool girara_list_iterator_is_valid (girara_list_iterator_t *iter)
void * girara_list_iterator_data (girara_list_iterator_t *iter)
void girara_list_iterator_set (girara_list_iterator_t *iter, void *data)
void girara_list_iterator_free (girara_list_iterator_t *iter)
size_t girara_list_size (girara_list_t *list)
ssize_t girara_list_position (girara_list_t *list, void *data)
void girara_list_sort (girara_list_t *list, girara_compare_function_t compare)
void girara_list_foreach (girara_list_t *list, girara_list_callback_t callback, void *data)
girara_list_t * girara_list_merge (girara_list_t *list, girara_list_t *other)
girara_tree_node_t * girara_node_new (void *data)
void girara_node_set_free_function (girara_tree_node_t *node, girara_free_function_t gfree)
void girara_node_free (girara_tree_node_t *node)
void girara_node_append (girara_tree_node_t *parent, girara_tree_node_t *child)
girara_tree_node_t * girara_node_append_data (girara_tree_node_t *parent, void *data)
girara_tree_node_t * girara_node_get_parent (girara_tree_node_t *node)
girara_tree_node_t * girara_node_get_root (girara_tree_node_t *node)
girara_list_t * girara_node_get_children (girara_tree_node_t *node)
size_t girara_node_get_num_children (girara_tree_node_t *node)
void * girara_node_get_data (girara_tree_node_t *node)
void girara_node_set_data (girara_tree_node_t *node, void *data)

Function Documentation

void girara_list_append ( girara_list_t *  list,
void *  data 
)

Append an element to the list.

Parameters
listThe girara list object
dataThe element

Definition at line 110 of file datastructures.c.

void girara_list_clear ( girara_list_t *  list)

Remove all elements from a list.

Parameters
listThe girara list object

Definition at line 84 of file datastructures.c.

bool girara_list_contains ( girara_list_t *  list,
void *  data 
)

Checks if the list contains the given element

Parameters
listThe girara list object
dataThe element
Returns
true if the list contains the element

Definition at line 165 of file datastructures.c.

void* girara_list_find ( girara_list_t *  list,
girara_compare_function_t  compare,
const void *  data 
)

Find an element

Parameters
listThe list
comparecompare function
datadata passed as the second argument to the compare function
Returns
the element if found or NULL

Definition at line 182 of file datastructures.c.

void girara_list_foreach ( girara_list_t *  list,
girara_list_callback_t  callback,
void *  data 
)

Call function for each element in the list.

Parameters
listThe list
callbackThe function to call.
dataPassed to the callback as second argument.

Definition at line 371 of file datastructures.c.

void girara_list_free ( girara_list_t *  list)

Destroy list.

Parameters
listThe girara list object

Definition at line 99 of file datastructures.c.

girara_list_iterator_t* girara_list_iterator ( girara_list_t *  list)

Create an iterator pointing at the start of list.

Parameters
listThe girara list object
Returns
The list iterator or NULL if an error occured

Definition at line 199 of file datastructures.c.

girara_list_iterator_t* girara_list_iterator_copy ( girara_list_iterator_t *  iter)

Create an iterator pointing to the same element as iter.

Parameters
iterThe girara list iterator to be copied
Returns
The list iterator or NULL if an error occured

Definition at line 219 of file datastructures.c.

void* girara_list_iterator_data ( girara_list_iterator_t *  iter)

Get data from the element pointed to by the iterator.

Parameters
iterThe list iterator
Returns
The data of the current element

Definition at line 297 of file datastructures.c.

void girara_list_iterator_free ( girara_list_iterator_t *  iter)

Destroy the iterator.

Parameters
iterThe list iterator

Definition at line 317 of file datastructures.c.

bool girara_list_iterator_has_next ( girara_list_iterator_t *  iter)

Check if iterator has next element.

Parameters
iterThe list iterator
Returns
true if iterator has a next element, false otherwise

Definition at line 250 of file datastructures.c.

bool girara_list_iterator_has_previous ( girara_list_iterator_t *  iter)

Check if iterator has previous element.

Parameters
iterThe list iterator
Returns
true if iterator has a previous element, false otherwise

Definition at line 272 of file datastructures.c.

bool girara_list_iterator_is_valid ( girara_list_iterator_t *  iter)

Check if iterator is valid

Parameters
iterThe list iterator
Returns
true if iterator is valid, false otherwise

Definition at line 291 of file datastructures.c.

girara_list_iterator_t* girara_list_iterator_next ( girara_list_iterator_t *  iter)

Move iterator to next element.

Parameters
iterThe list iterator
Returns
The moved iterator or NULL if an error occured

Definition at line 234 of file datastructures.c.

girara_list_iterator_t* girara_list_iterator_previous ( girara_list_iterator_t *  iter)

Move iterator to previous element.

Parameters
iterThe list iterator
Returns
The moved iterator or NULL if an error occured

Definition at line 256 of file datastructures.c.

void girara_list_iterator_remove ( girara_list_iterator_t *  iter)

Remove element pointed by the iterator, and updates the iterator to the next element

Parameters
iterThe list iterator

Definition at line 278 of file datastructures.c.

void girara_list_iterator_set ( girara_list_iterator_t *  iter,
void *  data 
)

Set data from the element pointed to by the iterator.

Parameters
iterThe list iterator
dataSets the list iterator to a specific element

Definition at line 305 of file datastructures.c.

girara_list_t* girara_list_merge ( girara_list_t *  list,
girara_list_t *  other 
)

Merge a list into another one. Both lists need to have the same free function. If other has a source free function set it will be set to NULL as the elements then belong to list.

Parameters
listthe target list
otherthe source list
Returns
list with the elements from other.

Definition at line 379 of file datastructures.c.

girara_list_t* girara_list_new ( void  )

Create a new list.

Returns
The girara list object or NULL if an error occured

Definition at line 35 of file datastructures.c.

girara_list_t* girara_list_new2 ( girara_free_function_t  gfree)

Create a new list.

Parameters
gfreePointer to the free function
Returns
The girara list object or NULL if an error occured.

Definition at line 41 of file datastructures.c.

void* girara_list_nth ( girara_list_t *  list,
size_t  n 
)

Returns nth entry

Parameters
listThe girara list object
nIndex of the entry
Returns
The nth element or NULL if an error occured

Definition at line 153 of file datastructures.c.

ssize_t girara_list_position ( girara_list_t *  list,
void *  data 
)

Returns the position of the element in the list

Parameters
listThe girara list object
dataThe element
Returns
The position or -1 if the data is not found

Definition at line 339 of file datastructures.c.

void girara_list_prepend ( girara_list_t *  list,
void *  data 
)

Prepend an element to the list.

Parameters
listThe girara list object
dataThe element

Definition at line 122 of file datastructures.c.

void girara_list_remove ( girara_list_t *  list,
void *  data 
)

Remove an element of the list

Parameters
listThe girara list object
dataThe element

Definition at line 134 of file datastructures.c.

void girara_list_set_free_function ( girara_list_t *  list,
girara_free_function_t  gfree 
)

Set the function which should be called if the stored data should be freed.

Parameters
listThe girara list object
gfreePointer to the free function

Definition at line 77 of file datastructures.c.

size_t girara_list_size ( girara_list_t *  list)

Get size of the list.

Parameters
listThe girara list object
Returns
The size of the list

Definition at line 327 of file datastructures.c.

void girara_list_sort ( girara_list_t *  list,
girara_compare_function_t  compare 
)

Sort a list

Parameters
listThe list to sort
comparecompare function

Definition at line 360 of file datastructures.c.

void girara_node_append ( girara_tree_node_t *  parent,
girara_tree_node_t *  child 
)

Append a node to another node.

Parameters
parentThe parent node
childThe child node

Definition at line 462 of file datastructures.c.

girara_tree_node_t* girara_node_append_data ( girara_tree_node_t *  parent,
void *  data 
)

Append data as new node to another node.

Parameters
parentThe parent node
dataThe data of the node
Returns
The node object or NULL if an error occured

Definition at line 469 of file datastructures.c.

void girara_node_free ( girara_tree_node_t *  node)

Free a node. This will remove the node from its' parent and will destroy all its' children.

Parameters
nodeThe girara node object

Definition at line 434 of file datastructures.c.

girara_list_t* girara_node_get_children ( girara_tree_node_t *  node)

Get list of children.

Parameters
nodeThe girara node object
Returns
List object containing all child nodes or NULL if an error occured

Definition at line 513 of file datastructures.c.

void* girara_node_get_data ( girara_tree_node_t *  node)

Get data.

Parameters
nodeThe girara node object
Returns
The data of the node

Definition at line 538 of file datastructures.c.

size_t girara_node_get_num_children ( girara_tree_node_t *  node)

Get number of children.

Parameters
nodeThe girara node object
Returns
The number of child nodes

Definition at line 530 of file datastructures.c.

girara_tree_node_t* girara_node_get_parent ( girara_tree_node_t *  node)

Get parent node.

Parameters
nodeThe girara node object
Returns
The parent node or NULL if an error occured or no parent exists

Definition at line 481 of file datastructures.c.

girara_tree_node_t* girara_node_get_root ( girara_tree_node_t *  node)

Get root node.

Parameters
nodeThe girara node object
Returns
The root node or NULL if an error occured

Definition at line 496 of file datastructures.c.

girara_tree_node_t* girara_node_new ( void *  data)

Create a new node.

Parameters
dataData of the new node
Returns
A girara node object or NULL if an error occured

Definition at line 400 of file datastructures.c.

void girara_node_set_data ( girara_tree_node_t *  node,
void *  data 
)

Set data.

Parameters
nodeThe girara node object
dataThe new data of the object

Definition at line 548 of file datastructures.c.

void girara_node_set_free_function ( girara_tree_node_t *  node,
girara_free_function_t  gfree 
)

Set the function which should be called if the stored data should be freed.

Parameters
nodeThe girara node object
gfreePointer to the free function

Definition at line 427 of file datastructures.c.

girara_list_t* girara_sorted_list_new ( girara_compare_function_t  cmp)

Create a new (sorted) list.

Parameters
cmpPointer to the compare function.
Returns
The girara list object or NULL if an error occured.

Definition at line 53 of file datastructures.c.

girara_list_t* girara_sorted_list_new2 ( girara_compare_function_t  cmp,
girara_free_function_t  gfree 
)

Create a new (sorted) list.

Parameters
cmpPointer to the compare function.
gfreePointer to the free function
Returns
The girara list object or NULL if an error occured.

Definition at line 65 of file datastructures.c.