Kaa client C SDK
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
kaa_list.h
Go to the documentation of this file.
1 /*
2  * Copyright 2014-2016 CyberVision, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef KAA_LIST_H_
18 #define KAA_LIST_H_
19 
20 #ifdef __cplusplus
21 extern "C" {
22 #endif
23 
24 #include <stdbool.h>
25 #include <stddef.h>
26 
27 #include "kaa_error.h"
28 
30 typedef struct kaa_list_t kaa_list_t;
31 
35 typedef bool (*match_predicate)(void *data, void *context);
36 
40 typedef void (*deallocate_list_data)(void *);
41 
45 typedef uint64_t list_node_hash(void * item);
46 
50 typedef void (*process_data)(void *data, void *context);
51 
57 
61 void kaa_list_destroy(kaa_list_t *list, deallocate_list_data deallocator);
62 
66 void kaa_list_clear(kaa_list_t *list, deallocate_list_data deallocator);
67 
73 size_t kaa_list_get_size(kaa_list_t *list);
74 
81 
88 
95 
102 
109 
116 
123 
127 void kaa_list_set_data_at(kaa_list_node_t *it, void *data, deallocate_list_data deallocator);
128 
134 
140 kaa_list_t *kaa_lists_merge(kaa_list_t *destination, kaa_list_t *source);
141 
147 
152 kaa_error_t kaa_list_remove_first(kaa_list_t *list, match_predicate pred, void *context, deallocate_list_data deallocator);
153 
157 void kaa_list_for_each(kaa_list_node_t *first, kaa_list_node_t *last, process_data process, void *context);
158 
164 void kaa_list_sort(kaa_list_t *list, match_predicate pred);
165 
171 int32_t kaa_list_hash(kaa_list_t *list, list_node_hash pred);
172 
173 #ifdef __cplusplus
174 } // extern "C"
175 #endif
176 #endif /* KAA_LIST_H_ */
kaa_list_node_t * kaa_list_prev(kaa_list_node_t *it)
Gets iterator to the previous element.
kaa_list_node_t * kaa_list_next(kaa_list_node_t *it)
Gets iterator to the next element.
kaa_error_t
Definition: kaa_error.h:31
void kaa_list_sort(kaa_list_t *list, match_predicate pred)
Sorts list according to predicate condition.
struct kaa_list_t kaa_list_t
Definition: kaa_list.h:30
bool(* match_predicate)(void *data, void *context)
Return false if data doesn't match search criteria.
Definition: kaa_list.h:35
Kaa error codes.
void kaa_list_destroy(kaa_list_t *list, deallocate_list_data deallocator)
Destroys list and all elements.
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.
kaa_list_t * kaa_list_create(void)
Creates empty list.
void(* process_data)(void *data, void *context)
Use to process element data.
Definition: kaa_list.h:50
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].
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 respect...
size_t kaa_list_get_size(kaa_list_t *list)
Returns the number of elements in the list.
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.
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.
kaa_list_node_t * kaa_list_back(kaa_list_t *list)
Returns an iterator pointing to the last element in the list.
struct kaa_list_node_t kaa_list_node_t
Definition: kaa_list.h:29
int32_t kaa_list_hash(kaa_list_t *list, list_node_hash pred)
Estimate hash from sorted array.
void * kaa_list_get_data(kaa_list_node_t *it)
Gets data from the iterator.
uint64_t list_node_hash(void *item)
Returns list node hash.
Definition: kaa_list.h:45
void(* deallocate_list_data)(void *)
Use to deallocate list node data.
Definition: kaa_list.h:40
void kaa_list_set_data_at(kaa_list_node_t *it, void *data, deallocate_list_data deallocator)
Sets new data to the element.
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_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.
kaa_list_node_t * kaa_list_begin(kaa_list_t *list)
Returns an iterator pointing to the first element in the list.
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...