• Skip to content
  • Skip to link menu
csync API Reference
  • csync
  • Sitemap
  • Contact Us
 
lomoco

lomoco_list.h File Reference

lomoco_list_t -- a doubly-linked list. More...

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.


Data Structures

struct  lomoco_list_s
 Used for each element in a doubly-linked list. More...

Typedefs

typedef int(* lomoco_compare_func )(lomoco_const_pointer a, lomoco_const_pointer b)
typedef const void * lomoco_const_pointer
typedef struct lomoco_list_s lomoco_list_t
typedef void * lomoco_pointer

Functions

lomoco_list_t * lomoco_list_alloc (void)
lomoco_list_t * lomoco_list_append (lomoco_list_t *list, lomoco_pointer data)
lomoco_list_t * lomoco_list_find (lomoco_list_t *list, lomoco_pointer data)
lomoco_list_t * lomoco_list_find_custom (lomoco_list_t *list, lomoco_pointer data, lomoco_compare_func func)
lomoco_list_t * lomoco_list_first (lomoco_list_t *list)
void lomoco_list_free (lomoco_list_t *list)
lomoco_list_t * lomoco_list_insert (lomoco_list_t *list, lomoco_pointer data, long position)
lomoco_list_t * lomoco_list_insert_sorted (lomoco_list_t *list, lomoco_pointer data, lomoco_compare_func func)
lomoco_list_t * lomoco_list_last (lomoco_list_t *list)
unsigned long lomoco_list_length (lomoco_list_t *list)
lomoco_list_t * lomoco_list_merge (lomoco_list_t *list1, lomoco_list_t *list2, lomoco_compare_func func)
lomoco_list_t * lomoco_list_next (lomoco_list_t *list)
lomoco_list_t * lomoco_list_position (lomoco_list_t *list, long position)
lomoco_list_t * lomoco_list_prepend (lomoco_list_t *list, lomoco_pointer data)
lomoco_list_t * lomoco_list_previous (lomoco_list_t *list)
lomoco_list_t * lomoco_list_remove (lomoco_list_t *list, lomoco_pointer data)
lomoco_list_t * lomoco_list_sort (lomoco_list_t *list, lomoco_compare_func func)
lomoco_list_t * lomoco_list_split (lomoco_list_t *list)

Detailed Description

lomoco_list_t -- a doubly-linked list.

The lomoco_list_t structure and its associated functions provide a standard doubly-linked list data structure. Each node has two links: one points to the previous node, or points to a null value or empty list if it is the first node; and one points to the next, or points to a null value or empty list if it is the final node.

The data contained in each element can be simply pointers to any type of data. You are the owner of the data, this means you have to free the memory you have allocated for the data.

Definition in file lomoco_list.h.


Typedef Documentation

typedef int(* lomoco_compare_func)(lomoco_const_pointer a, lomoco_const_pointer b)

Specifies the type of a comparison function used to compare two values.

The value which should be returned depends on the context in which the lomoco_compare_func is used.

Parameters:
a First parameter to compare with.
b Second parameter to compare with.
Returns:
The function should return a number > 0 if the first parameter comes after the second parameter in the sort order.

Definition at line 72 of file lomoco_list.h.

typedef const void* lomoco_const_pointer

An untyped pointer to constant data.

The data pointed to should not be changed.

This is typically used in function prototypes to indicate that the data pointed to will not be altered by the function.

Definition at line 57 of file lomoco_list.h.

typedef struct lomoco_list_s lomoco_list_t

Used for each element in a doubly-linked list.

The data field holds the element's data, which can be a pointer to any kind of data. The next and prev pointers are the links to the next and previous elements in the list.

typedef void* lomoco_pointer

An untyped pointer.

Definition at line 48 of file lomoco_list.h.


Function Documentation

lomoco_list_t* lomoco_list_alloc ( void   ) 

Allocates space for one lomoco_list_t element.

Returns:
A pointer to the newly-allocated element.

lomoco_list_t* lomoco_list_append ( lomoco_list_t *  list,
lomoco_pointer  data 
)

Adds a new element on to the end of the list.

Parameters:
list A pointer to lomoco_list.
data The data for the new element.
Returns:
New start of the list, which may have changed, so make sure you store the new value.

lomoco_list_t* lomoco_list_find ( lomoco_list_t *  list,
lomoco_pointer  data 
)

Finds the element in a lomoco_list_t which contains the given data.

Parameters:
list A pointer to lomoco_list.
data The data of the element to remove.
Returns:
The found element or NULL if it is not found.

lomoco_list_t* lomoco_list_find_custom ( lomoco_list_t *  list,
lomoco_pointer  data,
lomoco_compare_func  func 
)

Finds an element, using a supplied function to find the desired element.

Parameters:
list A pointer to lomoco_list.
data The data of the element to remove.
func The function to call for each element. It should return 0 when the desired element is found.
Returns:
The found element or NULL if it is not found.

lomoco_list_t* lomoco_list_first ( lomoco_list_t *  list  ) 

Gets the first element in a lomoco_list.

Parameters:
list A pointer to lomoco_list.
Returns:
New start of the list, which may have changed, so make sure you store the new value.

void lomoco_list_free ( lomoco_list_t *  list  ) 

Frees all elements from a lomoco_list.

Parameters:
list A pointer to lomoco_list.

lomoco_list_t* lomoco_list_insert ( lomoco_list_t *  list,
lomoco_pointer  data,
long  position 
)

Inserts a new element into the list at the given position.

If the position is lesser than 0, the new element gets appended to the list, if the position is 0, we prepend the element and if the given position is greater than the length of the list, the element gets appended too.

Parameters:
list A pointer to lomoco_list.
data The data for the new element.
position The position to insert the element.
Returns:
New start of the list, which may have changed, so make sure you store the new value.

lomoco_list_t* lomoco_list_insert_sorted ( lomoco_list_t *  list,
lomoco_pointer  data,
lomoco_compare_func  func 
)

Inserts a new element into the list, using the given comparison function to determine its position.

Parameters:
list A pointer to lomoco_list.
data The data for the new element.
func The function to compare elements in the list. It should return a number > 0 if the first parameter comes after the second parameter in the sort order.
Returns:
New start of the list, which may have changed, so make sure you store the new value.

lomoco_list_t* lomoco_list_last ( lomoco_list_t *  list  ) 

Gets the last element in a lomoco_list.

Parameters:
list A pointer to lomoco_list.
Returns:
New start of the list, which may have changed, so make sure you store the new value.

unsigned long lomoco_list_length ( lomoco_list_t *  list  ) 

Gets the number of elements in a lomoco_list.

Parameters:
list A pointer to lomoco_list.
Returns:
The number of elements

lomoco_list_t* lomoco_list_merge ( lomoco_list_t *  list1,
lomoco_list_t *  list2,
lomoco_compare_func  func 
)

Internal used function to merge 2 lists using a compare function.

Parameters:
list1 A pointer to lomoco_list.
list2 A pointer to lomoco_list.
Returns:
New start of the list, which may have changed, so make sure you store the new value.

lomoco_list_t* lomoco_list_next ( lomoco_list_t *  list  ) 

Gets the next element in a lomoco_list.

Parameters:
An element in a lomoco_list.
Returns:
The next element, or NULL if there are no more elements.

lomoco_list_t* lomoco_list_position ( lomoco_list_t *  list,
long  position 
)

Gets the element at the given positon in a lomoco_list.

Parameters:
list A pointer to lomoco_list.
position The position of the element, counting from 0.
Returns:
New start of the list, which may have changed, so make sure you store the new value.

lomoco_list_t* lomoco_list_prepend ( lomoco_list_t *  list,
lomoco_pointer  data 
)

Adds a new element on at the beginning of the list.

Parameters:
list A pointer to lomoco_list.
data The data for the new element.
Returns:
New start of the list, which may have changed, so make sure you store the new value.

lomoco_list_t* lomoco_list_previous ( lomoco_list_t *  list  ) 

Gets the previous element in a lomoco_list.

Parameters:
An element in a lomoco_list.
Returns:
The previous element, or NULL if there are no more elements.

lomoco_list_t* lomoco_list_remove ( lomoco_list_t *  list,
lomoco_pointer  data 
)

Removes an element from a lomoco_list.

If two elements contain the same data, only the first is removed.

Parameters:
list A pointer to lomoco_list.
data The data of the element to remove.

lomoco_list_t* lomoco_list_sort ( lomoco_list_t *  list,
lomoco_compare_func  func 
)

Sorts the elements of a lomoco_list.

The algorithm used is Mergesort, because that works really well on linked lists, without requiring the O(N) extra space it needs when you do it on arrays.

Parameters:
list A pointer to lomoco_list.
func The comparison function used to sort the lomoco_list. This function is passed 2 elements of the GList and should return 0 if they are equal, a negative value if the first element comes before the second, or a positive value if the first element comes after the second.
Returns:
New start of the list, which may have changed, so make sure you store the new value.

lomoco_list_t* lomoco_list_split ( lomoco_list_t *  list  ) 

Internally used function to split 2 lists.

Parameters:
list A pointer to lomoco_list.
Returns:
New start of the list, which may have changed, so make sure you store the new value.

lomoco

Skip menu "lomoco"

API Documentation

Skip menu "@topname@"
Generated with Doxygen