Kaa client C SDK
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Typedefs | Functions
kaa_list.h File Reference
#include <stdbool.h>
#include <stddef.h>
#include "kaa_error.h"

Go to the source code of this file.

Typedefs

typedef struct kaa_list_node_t kaa_list_node_t
 
typedef struct kaa_list_t kaa_list_t
 
typedef bool(* match_predicate )(void *data, void *context)
 Return false if data doesn't match search criteria. More...
 
typedef void(* deallocate_list_data )(void *)
 Use to deallocate list node data. More...
 
typedef uint64_t list_node_hash (void *item)
 Returns list node hash. More...
 
typedef void(* process_data )(void *data, void *context)
 Use to process element data. More...
 

Functions

kaa_list_tkaa_list_create (void)
 Creates empty list. More...
 
void kaa_list_destroy (kaa_list_t *list, deallocate_list_data deallocator)
 Destroys list and all elements. More...
 
void kaa_list_clear (kaa_list_t *list, deallocate_list_data deallocator)
 Removes all elements from the list (which are destroyed), and leaving the list with a size of 0. More...
 
size_t kaa_list_get_size (kaa_list_t *list)
 Returns the number of elements in the list. More...
 
kaa_list_node_tkaa_list_push_front (kaa_list_t *list, void *data)
 Inserts a new element at the beginning of the list, right before its current first element. More...
 
kaa_list_node_tkaa_list_push_back (kaa_list_t *list, void *data)
 Inserts a new element at the end of the list, after its current last element. More...
 
kaa_list_node_tkaa_list_begin (kaa_list_t *list)
 Returns an iterator pointing to the first element in the list. More...
 
kaa_list_node_tkaa_list_back (kaa_list_t *list)
 Returns an iterator pointing to the last element in the list. More...
 
kaa_list_node_tkaa_list_next (kaa_list_node_t *it)
 Gets iterator to the next element. More...
 
kaa_list_node_tkaa_list_prev (kaa_list_node_t *it)
 Gets iterator to the previous element. More...
 
void * kaa_list_get_data (kaa_list_node_t *it)
 Gets data from the iterator. More...
 
void kaa_list_set_data_at (kaa_list_node_t *it, void *data, deallocate_list_data deallocator)
 Sets new data to the element. More...
 
kaa_list_node_tkaa_list_find_next (kaa_list_node_t *from, match_predicate pred, void *context)
 Returns an iterator to the first element in the list that matches by the predicate. More...
 
kaa_list_tkaa_lists_merge (kaa_list_t *destination, kaa_list_t *source)
 Merges the source list into the destination list by transferring all of its elements at their respective ordered positions at the end of the source list. More...
 
kaa_list_node_tkaa_list_remove_at (kaa_list_t *list, kaa_list_node_t *it, deallocate_list_data deallocator)
 Removes from the list a single element. More...
 
kaa_error_t kaa_list_remove_first (kaa_list_t *list, match_predicate pred, void *context, deallocate_list_data deallocator)
 Removes from the list the first element for which the predicate returns true. More...
 
void kaa_list_for_each (kaa_list_node_t *first, kaa_list_node_t *last, process_data process, void *context)
 Applies the function process to each of the elements in the range [first,last]. More...
 
void kaa_list_sort (kaa_list_t *list, match_predicate pred)
 Sorts list according to predicate condition. More...
 
int32_t kaa_list_hash (kaa_list_t *list, list_node_hash pred)
 Estimate hash from sorted array. More...
 

Typedef Documentation

typedef void(* deallocate_list_data)(void *)

Use to deallocate list node data.

typedef struct kaa_list_t kaa_list_t
typedef uint64_t list_node_hash(void *item)

Returns list node hash.

typedef bool(* match_predicate)(void *data, void *context)

Return false if data doesn't match search criteria.

typedef void(* process_data)(void *data, void *context)

Use to process element data.

Function Documentation

kaa_list_node_t* kaa_list_back ( kaa_list_t list)

Returns an iterator pointing to the last element in the list.

Returns
An iterator
Return values
NULLthe list is NULL
kaa_list_node_t* kaa_list_begin ( kaa_list_t list)

Returns an iterator pointing to the first element in the list.

Returns
An iterator
Return values
NULLthe list is NULL
void kaa_list_clear ( kaa_list_t list,
deallocate_list_data  deallocator 
)

Removes all elements from the list (which are destroyed), and leaving the list with a size of 0.

kaa_list_t* kaa_list_create ( void  )

Creates empty list.

Returns
The list object.
void kaa_list_destroy ( kaa_list_t list,
deallocate_list_data  deallocator 
)

Destroys list and all elements.

kaa_list_node_t* kaa_list_find_next ( kaa_list_node_t from,
match_predicate  pred,
void *  context 
)

Returns an iterator to the first element in the list that matches by the predicate.

Return values
NULLno such element is found
void kaa_list_for_each ( kaa_list_node_t first,
kaa_list_node_t last,
process_data  process,
void *  context 
)

Applies the function process to each of the elements in the range [first,last].

void* kaa_list_get_data ( kaa_list_node_t it)

Gets data from the iterator.

Returns
Data
Return values
NULLthe iterator is NULL
size_t kaa_list_get_size ( kaa_list_t list)

Returns the number of elements in the list.

Returns
The number of elements.
Return values
NULLthe list is NULL
int32_t kaa_list_hash ( kaa_list_t list,
list_node_hash  pred 
)

Estimate hash from sorted array.

Parameters
listList to calculate hash from.
predPredicate that is used to get list node's hash, id or other unique uint64_t value.
kaa_list_node_t* kaa_list_next ( kaa_list_node_t it)

Gets iterator to the next element.

Returns
An iterator
Return values
NULLthe provided iterator is NULL
kaa_list_node_t* kaa_list_prev ( kaa_list_node_t it)

Gets iterator to the previous element.

Returns
An iterator
Return values
NULLthe provided iterator is NULL
kaa_list_node_t* kaa_list_push_back ( kaa_list_t list,
void *  data 
)

Inserts a new element at the end of the list, after its current last element.

Returns
An iterator to the inserted element
Return values
NULLthe list or data are NULL
kaa_list_node_t* kaa_list_push_front ( kaa_list_t list,
void *  data 
)

Inserts a new element at the beginning of the list, right before its current first element.

Returns
An iterator to the inserted element.
Return values
NULLthe list or data are NULL
kaa_list_node_t* kaa_list_remove_at ( kaa_list_t list,
kaa_list_node_t it,
deallocate_list_data  deallocator 
)

Removes from the list a single element.

Returns
An iterator pointing to the element that followed the last element erased by the function call or NULL.
kaa_error_t kaa_list_remove_first ( kaa_list_t list,
match_predicate  pred,
void *  context,
deallocate_list_data  deallocator 
)

Removes from the list the first element for which the predicate returns true.

Return values
KAA_ERR_NONEelement was found
void kaa_list_set_data_at ( kaa_list_node_t it,
void *  data,
deallocate_list_data  deallocator 
)

Sets new data to the element.

Old data will be destroyed.

void kaa_list_sort ( kaa_list_t list,
match_predicate  pred 
)

Sorts list according to predicate condition.

Parameters
listList to sort.
predPredicate that is used to sort list.
kaa_list_t* kaa_lists_merge ( kaa_list_t destination,
kaa_list_t source 
)

Merges the source list into the destination list by transferring all of its elements at their respective ordered positions at the end of the source list.

Returns
The result list which contains all merged elements.