Singly-Linked Lists

G-Golf Glib Singly-Linked Lists low level API.
Singly-Linked Lists — Linked lists that can be iterated over in one direction

Procedures

g-slist-data
g-slist-next
g-slist-append
g-slist-prepend
g-slist-free
g-slist-length
g-slist-nth-data

Description

The GSList structure and its associated functions provide a standard singly-linked list data structure.

Each element in the list contains a piece of data, together with a pointer which links to the next element in the list. Using this pointer it is possible to move through the list in one direction only (unlike the Doubly-Linked Lists, which allow movement in both directions).

Please read the Singly-Linked-Lists section from the Glib reference manual for a complete description.

Procedures

Procedure: g-slist-data g-slist

Returns a pointer.

Obtains and returns a pointer to the data in g-slist, or any integer value, in which case, it is the responsibility of the caller to apply the appropriate type conversion procedure.

Procedure: g-slist-next g-slist

Returns a pointer or #f.

Obtains and returns the next element in g-slist, or #f if there are no more elements.

Procedure: g-slist-append g-slist data

Returns a pointer.

Adds data - which is (must be) a pointer - to the end of g-slist and returns a pointer to the (possibly new) start of the list (so make sure you store the new value).

Note that g-slist-append has to traverse the entire list to find the end, which is inefficient when adding multiple elements. A common idiom to avoid the inefficiency is to prepend the elements and reverse the list when all elements have been added.

Procedure: g-slist-prepend g-slist data

Returns a pointer.

Adds data - which is (must be) a pointer - to the start of g-slist and returns a pointer to the (possibly new) start of the list (so make sure you store the new value).

Procedure: g-slist-free g-slist

Returns nothing.

Frees all of the memory used by g-slist.

Procedure: g-slist-length g-slist

Returns an integer.

Obtains and returns the number of elements in g-slist. This function iterates over the whole list to count its elements.

Procedure: g-slist-nth-data g-slist n

Returns a pointer or #f.

Obtains and returns a pointer to the data of the n-th element of g-slist. This iterates over the list until it reaches the n-th position. If n is off the end of g-slist, it returns #f.