Main Page | Modules | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals | Related Pages

list.c File Reference


Detailed Description

Handling of lists on a slightly higher lever than GList.

The purpose of this list functions is providing efficient appending, prepending of items to a list structure, fast lookup of the list length, fast access to the list head and tail. Additionally, some basic checks prevent modification of the list whilst traversing it.

Author:
Christian Biere
Date:
2006

#include "common.h"
#include "list.h"
#include "misc.h"
#include "glib-missing.h"
#include "walloc.h"
#include "override.h"

Data Structures

struct  list
struct  list_iter

Defines

#define equiv(p, q)   (!(p) == !(q))
#define list_regression(list)

Enumerations

enum  list_magic_t { LIST_MAGIC = 0x134747a9U }
enum  list_iter_magic_t { LIST_ITER_MAGIC = 0x3fae3587U }

Functions

void list_check (const list_t *list)
void list_iter_check (const list_iter_t *iter)
list_tlist_new (void)
 Create a new list.
void list_free (list_t **list_ptr)
 Dispose of the data structure.
void list_append (list_t *list, gpointer key)
 Append `key' to the list.
void list_prepend (list_t *list, gpointer key)
 Prepend `key' to the list.
void list_insert_sorted (list_t *list, gpointer key, GCompareFunc func)
 Insert `key' into the list.
gboolean list_remove (list_t *list, gpointer key)
 Remove `key' from the list.
gpointer list_tail (const list_t *list)
gpointer list_head (const list_t *list)
gboolean list_moveto_head (list_t *list, gpointer key)
 Move entry to the head of the list.
gboolean list_moveto_tail (list_t *list, gpointer key)
 Move entry to the tail of the list.
guint list_length (const list_t *list)
list_iter_tlist_iter_before_head (list_t *list)
 Get an iterator on the list, positioned before first item.
list_iter_tlist_iter_after_tail (list_t *list)
 Get an iterator on the list, positioned after tail item.
gpointer list_iter_next (list_iter_t *iter)
 Moves the iterator to the next element and returns its key.
gboolean list_iter_has_next (const list_iter_t *iter)
 Checks whether there is a next item to be iterated over.
gpointer list_iter_previous (list_iter_t *iter)
 Moves the iterator to the previous element and returns its key.
gpointer list_iter_current (list_iter_t *iter)
gboolean list_iter_has_previous (const list_iter_t *iter)
 Checks whether there is a previous item in the iterator.
void list_iter_free (list_iter_t **iter_ptr)
 Release the iterator once we're done with it.
gboolean list_contains (list_t *list, gconstpointer key, GEqualFunc func, gpointer *orig_key)
 Check whether list contains the `key' whereas equality is determined using `func'.
void list_foreach (const list_t *list, GFunc func, gpointer user_data)
 Apply `func' to all the items in the structure.


Define Documentation

#define equiv p,
 )     (!(p) == !(q))
 

#define list_regression list   ) 
 


Enumeration Type Documentation

enum list_iter_magic_t
 

Enumeration values:
LIST_ITER_MAGIC 

enum list_magic_t
 

Enumeration values:
LIST_MAGIC 


Function Documentation

void list_append list_t list,
gpointer  key
 

Append `key' to the list.

void list_check const list_t list  )  [inline, static]
 

gboolean list_contains list_t list,
gconstpointer  key,
GEqualFunc  func,
gpointer *  orig_key
 

Check whether list contains the `key' whereas equality is determined using `func'.

void list_foreach const list_t list,
GFunc  func,
gpointer  user_data
 

Apply `func' to all the items in the structure.

void list_free list_t **  list_ptr  ) 
 

Dispose of the data structure.

gpointer list_head const list_t list  ) 
 

Returns:
the first item of the list, or NULL if none.

void list_insert_sorted list_t list,
gpointer  key,
GCompareFunc  func
 

Insert `key' into the list.

list_iter_t* list_iter_after_tail list_t list  ) 
 

Get an iterator on the list, positioned after tail item.

Get items with list_previous().

list_iter_t* list_iter_before_head list_t list  ) 
 

Get an iterator on the list, positioned before first item.

Get items with list_next().

void list_iter_check const list_iter_t iter  )  [inline, static]
 

gpointer list_iter_current list_iter_t iter  ) 
 

void list_iter_free list_iter_t **  iter_ptr  ) 
 

Release the iterator once we're done with it.

gboolean list_iter_has_next const list_iter_t iter  ) 
 

Checks whether there is a next item to be iterated over.

gboolean list_iter_has_previous const list_iter_t iter  ) 
 

Checks whether there is a previous item in the iterator.

gpointer list_iter_next list_iter_t iter  ) 
 

Moves the iterator to the next element and returns its key.

If there is no next element, NULL is returned.

gpointer list_iter_previous list_iter_t iter  ) 
 

Moves the iterator to the previous element and returns its key.

If there is no previous element, NULL is returned.

guint list_length const list_t list  ) 
 

Returns:
the length of the list.

gboolean list_moveto_head list_t list,
gpointer  key
 

Move entry to the head of the list.

gboolean list_moveto_tail list_t list,
gpointer  key
 

Move entry to the tail of the list.

list_t* list_new void   ) 
 

Create a new list.

void list_prepend list_t list,
gpointer  key
 

Prepend `key' to the list.

gboolean list_remove list_t list,
gpointer  key
 

Remove `key' from the list.

Returns:
whether we found the item in the list and deleted it.

gpointer list_tail const list_t list  ) 
 

Returns:
The data associated with the tail item, or NULL if none.


Generated on Sat Jun 30 17:53:28 2007 for gtk-gnutella by  doxygen 1.3.9.1