cdcontainers  0.1.1
Library of data containers and collections for C programming language.
Data Structures | Macros | Functions
list.h File Reference

The cdc_list is a struct and functions that provide a doubly linked list. More...

#include <cdcontainers/common.h>
#include <cdcontainers/status.h>
#include <assert.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stdlib.h>

Go to the source code of this file.

Data Structures

struct  cdc_list_node
 The cdc_list_node is service struct. More...
 
struct  cdc_list
 The cdc_lisе is service struct. More...
 
struct  cdc_list_iter
 The cdc_list_iterator is service struct. More...
 
struct  cdc_list_riter
 The cdc_list_riter is service struct. More...
 

Macros

#define CDC_LIST_FOR_EACH(item, list)   for (cdc_list_node * (item) = (list->head); (item); (item) = (item)->next)
 For-each macro. More...
 

Functions

enum cdc_stat cdc_list_ctor (struct cdc_list **l, struct cdc_data_info *info)
 Constructs an empty list. More...
 
enum cdc_stat cdc_list_ctorl (struct cdc_list **l, struct cdc_data_info *info,...)
 Constructs a list, initialized by an variable number of pointers. The last pointer must be CDC_END. More...
 
enum cdc_stat cdc_list_ctorv (struct cdc_list **l, struct cdc_data_info *info, va_list args)
 Constructs a list, initialized by args. The last pointer must be CDC_END. More...
 
void cdc_list_dtor (struct cdc_list *l)
 Destroys the list. More...
 
void * cdc_list_get (struct cdc_list *l, size_t index)
 Returns an element at index position index in the list. More...
 
enum cdc_stat cdc_list_at (struct cdc_list *l, size_t index, void **elem)
 Writes to pointer an element from specified position in the list. Bounds checking is performed. More...
 
static void * cdc_list_front (struct cdc_list *l)
 Returns a first element in the list. More...
 
static void * cdc_list_back (struct cdc_list *l)
 Returns a last element in the list. More...
 
static size_t cdc_list_size (struct cdc_list *l)
 Returns the number of elements in the list. More...
 
static bool cdc_list_empty (struct cdc_list *l)
 Checks if the list has no elements. More...
 
void cdc_list_set (struct cdc_list *l, size_t index, void *value)
 Sets an element at index position to the value. The function is not called to free memory. More...
 
enum cdc_stat cdc_list_push_back (struct cdc_list *l, void *value)
 Inserts an element at the end of the list. More...
 
void cdc_list_pop_back (struct cdc_list *l)
 Removes a last element in the list. More...
 
enum cdc_stat cdc_list_push_front (struct cdc_list *l, void *value)
 Inserts an element at the beginning of the list. More...
 
void cdc_list_pop_front (struct cdc_list *l)
 Removes a first element in the list. More...
 
enum cdc_stat cdc_list_insert (struct cdc_list *l, size_t index, void *value)
 Inserts an element at |index| position in the list. If index is 0, the value is prepended to the list. If index is cdc_list_size(), the value is appended to the list. More...
 
enum cdc_stat cdc_list_iinsert (struct cdc_list_iter *before, void *value)
 Inserts an element in front of the item pointed to by the iterator before. More...
 
void cdc_list_erase (struct cdc_list *l, size_t index)
 Removes an element at index position in the circular arrray. More...
 
void cdc_list_ierase (struct cdc_list_iter *pos)
 Removes an element associated with the iterator pos from the list. More...
 
void cdc_list_clear (struct cdc_list *l)
 Removes all the elements from the list. More...
 
void cdc_list_swap (struct cdc_list *a, struct cdc_list *b)
 Swaps lists a and b. This operation is very fast and never fails. More...
 
void cdc_list_splice (struct cdc_list_iter *position, struct cdc_list_iter *first, struct cdc_list_iter *last)
 Transfers elements from one container, iterators (first, last] to another container at position before iterator position. More...
 
void cdc_list_ssplice (struct cdc_list_iter *position, struct cdc_list_iter *first)
 Transfers elements from one container, iterators (first, end] to another container at position before iterator position. More...
 
void cdc_list_lsplice (struct cdc_list_iter *position, struct cdc_list *other)
 Transfers all elements from container other to another container at position before iterator position. More...
 
void cdc_list_merge (struct cdc_list *l, struct cdc_list *other)
 Merges two sorted lists into one. The lists should be sorted into ascending order. More...
 
void cdc_list_cmerge (struct cdc_list *l, struct cdc_list *other, cdc_binary_pred_fn_t compare)
 Merges two sorted lists into one. The lists should be sorted. More...
 
void cdc_list_erase_if (struct cdc_list *l, cdc_unary_pred_fn_t pred)
 Removes from the container all elements for which predicate pred returns true. More...
 
void cdc_list_reverse (struct cdc_list *l)
 Reverses the order of elements in the container. More...
 
void cdc_list_unique (struct cdc_list *l)
 Removes all consecutive duplicate elements from the container. Only the first element in each group of equal elements is left. More...
 
void cdc_list_punique (struct cdc_list *l, cdc_binary_pred_fn_t pred)
 Removes all consecutive duplicate elements from the container. Only the first element in each group of equal elements is left. More...
 
void cdc_list_sort (struct cdc_list *l)
 Sorts elements in ascending order. More...
 
void cdc_list_csort (struct cdc_list *l, cdc_binary_pred_fn_t compare)
 Sorts elements in ascending order. More...
 
void cdc_list_foreach (struct cdc_list *l, void(*cb)(void *))
 A function |cb| is applied to each item of the list. More...
 
static void cdc_list_begin (struct cdc_list *l, struct cdc_list_iter *it)
 Initializes the iterator to the beginning. More...
 
static void cdc_list_end (struct cdc_list *l, struct cdc_list_iter *it)
 Initializes the iterator to the end. More...
 
static void cdc_list_rbegin (struct cdc_list *l, struct cdc_list_riter *it)
 Initializes the reverse iterator to the beginning. More...
 
static void cdc_list_rend (struct cdc_list *l, struct cdc_list_riter *it)
 Initializes the reverse iterator to the end. More...
 
static void cdc_list_iter_next (struct cdc_list_iter *it)
 Advances the iterator to the next element in the list. More...
 
static void cdc_list_iter_prev (struct cdc_list_iter *it)
 Advances the iterator to the previous element in the list. More...
 
static bool cdc_list_iter_has_next (struct cdc_list_iter *it)
 Returns true if there is at least one element ahead of the iterator, i.e. the iterator is not at the back of the container; otherwise returns false. More...
 
static bool cdc_list_iter_has_prev (struct cdc_list_iter *it)
 Returns true if there is at least one element behind the iterator, i.e. the iterator is not at the front of the container; otherwise returns false. More...
 
static void * cdc_list_iter_data (struct cdc_list_iter *it)
 Returns a current element. More...
 
static void cdc_list_iter_from (struct cdc_list_riter *rit, struct cdc_list_iter *it)
 Сasts reverse iterator to iterator. More...
 
static bool cdc_list_iter_is_eq (struct cdc_list_iter *it1, struct cdc_list_iter *it2)
 Returns false if the iterator |it1| equal to the iterator |it2|, otherwise returns false. More...
 
static void cdc_list_riter_next (struct cdc_list_riter *it)
 Advances the reverse iterator to the next element in the list. More...
 
static void cdc_list_riter_prev (struct cdc_list_riter *it)
 Advances the reverse iterator to the previous element in the list. More...
 
static bool cdc_list_riter_has_next (struct cdc_list_riter *it)
 Returns true if there is at least one item ahead of the reverse iterator, i.e. the reverse iterator is not at the back of the container. otherwise returns false. More...
 
static bool cdc_list_riter_has_prev (struct cdc_list_riter *it)
 Returns true if there is at least one item behind the reverse iterator, i.e. the reverse iterator is not at the front of the container; otherwise returns false. More...
 
static void * cdc_list_riter_data (struct cdc_list_riter *it)
 Returns a current element. More...
 
static void cdc_list_riter_from (struct cdc_list_iter *it, struct cdc_list_riter *rit)
 Сasts iterator to reverse iterator. More...
 
static bool cdc_list_riter_is_eq (struct cdc_list_riter *rit1, struct cdc_list_riter *rit2)
 Returns false if the reverse iterator |rit1| equal to the reverse iterator |rit2|, otherwise returns false. More...
 

Detailed Description

The cdc_list is a struct and functions that provide a doubly linked list.

Author
Maksim Andrianov maksi.nosp@m.mand.nosp@m.riano.nosp@m.v1@y.nosp@m.andex.nosp@m..ru