Simple data structures / objects in plain C Snapshot
Classes | Defines | Typedefs | Functions
slist.h File Reference
#include <cutils/base.h>

Go to the source code of this file.

Classes

struct  tagSLIST_entry
struct  SLIST

Defines

#define SLIST_FOREACH(loopvarname, list)
 Macro for iterate over all elements of a list, the list is traversed in forward direction from first element to the last element.
#define SLIST_FOREACH_SAVE(loopvarname, loopvarnamenext, list)
 Macro for iterate over all elements of a list, the list is traversed in forward direction from first element to the last element.

Typedefs

typedef struct tagSLIST_entry SLIST_entry
typedef void(* SLIST_VISITOR_V )(SLIST *list, SLIST_entry *entry, void *context)
typedef int32_t(* SLIST_VISITOR )(SLIST *list, SLIST_entry *entry, void *context)
typedef int32_t(* SLIST_COMPARE )(SLIST_entry *, SLIST_entry *)

Functions

M_INLINE void SLIST_init (SLIST *head)
 initialises an empty list head
M_INLINE int SLIST_isempty (SLIST *head)
 checks if argument list is empty
M_INLINE void SLIST_insert_after (SLIST *list, SLIST_entry *pos, SLIST_entry *newentry)
 insert new entry after a given entry.
M_INLINE SLIST_entrySLIST_unlink_after (SLIST *list, SLIST_entry *link)
 delete an element from a list.
M_INLINE void SLIST_push_back (SLIST *list, SLIST_entry *newentry)
 insert element as last in list.
M_INLINE void SLIST_push_front (SLIST *list, SLIST_entry *newentry)
 insert element as first in list (used to maintain queue)
M_INLINE void SLIST_append (SLIST *dest, SLIST *src)
 append contents of one list onto the other
M_INLINE SLIST_entrySLIST_pop_front (SLIST *list)
 remove the first element from list (used to maintain queue)
M_INLINE SLIST_entrySLIST_get_first (SLIST *list)
M_INLINE SLIST_entrySLIST_get_last (SLIST *list)
M_INLINE SLIST_entrySLIST_get_next (SLIST_entry *cur)
M_INLINE size_t SLIST_size (SLIST *list)
 : return number of elements in list if we don't have element count in list (SLIST_NO_ELMCOUNT defined), then the whole list structure is traversed.
M_INLINE SLIST_entrySLIST_get_nth (SLIST *list, size_t nth)
M_INLINE SLIST_entrySLIST_get_nth_reverse (SLIST *list, size_t nth)
 get the nth element of a list as counted from the end of the list.
M_INLINE void SLIST_foreach (SLIST *lst, SLIST_VISITOR_V eval, void *context)
 iterate over all elements of a list, callback is invoked for either element of the list.
M_INLINE SLIST_entrySLIST_findif (SLIST *lst, SLIST_VISITOR eval, void *context, int32_t *retval)
 find an element within the linked list. callback is invoked for each element of the list, in forward direction from first element to last element; when the callback returns non zero value the iteration stops as we have found what we searched for.
M_INLINE void SLIST_insert_sorted (SLIST *list, SLIST_COMPARE compare, SLIST_entry *newentry)
 insert new element into sorted list; Maintains ordering relationship between elements of linked list (sort by ascending order) A sorting algorithm based on this function is not very efficient; it is of complexity O(n^2); nevertheless usefull if a list is modified and has to be always maintained in sorted order.
M_INLINE void SLIST_deleteif (SLIST *list, SLIST_VISITOR check_if, void *context, int offset_of_link)
 iterate over all entries of the list and delete entries that match predicate from the list, and frees the memory (optionally)
M_INLINE void SLIST_deleteall (SLIST *list, SLIST_VISITOR_V on_delete, void *context, int offset_of_link)
 iterate over all entries of the list and delete them.
M_INLINE void SLIST_reverse (SLIST *lst)
 Reverse a list This function turns the first element into the last element, the second element into the one before the last, and so on and on.
M_INLINE int SLIST_check (SLIST *header)
 check consistency of list This function checks for loops in the list, and if count of elements in list is the same as counter of elements in list header.