TeoCCl library  0.1.7
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
array_list.h
Go to the documentation of this file.
1 /*
2  * The MIT License
3  *
4  * Copyright 2016 Kirill Scherba <kirill@scherba.ru>.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to deal
8  * in the Software without restriction, including without limitation the rights
9  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10  * copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22  * THE SOFTWARE.
23  */
24 
25 
36 #ifndef ARRAY_LIST_H
37 #define ARRAY_LIST_H
38 
39 #ifdef __cplusplus
40 extern "C" {
41 #endif
42 
43 #define ARRAY_LIST_DEFAULT_SIZE 32 // Default ArrayList size
44 
45 typedef void (array_list_free_fn) (void *data); // free-callback function
46 
50 typedef struct ccl_array_list {
51 
52  void **array;
53  size_t length;
54  size_t size;
56 
58 
66 
74 
82 void *cclArrayListGetIdx(ccl_array_list_t *tal, size_t i);
83 
92 int cclArrayListDelIdx(ccl_array_list_t *tal, size_t i, size_t count);
93 
101 int cclArrayListAdd(ccl_array_list_t *tal, void *data);
102 
110 
117 void cclArrayListSort(ccl_array_list_t *tal, int(*compar)(const void *, const void *));
118 
128 void *cclArrayListBSearch(ccl_array_list_t *tal, const void **key,
129  int(*compar)(const void *, const void *));
130 
131 #ifdef __cplusplus
132 }
133 #endif
134 
135 #endif
size_t size
Size of array.
Definition: array_list.h:54
void * cclArrayListBSearch(ccl_array_list_t *tal, const void **key, int(*compar)(const void *, const void *))
Binary search for array-list.
Definition: array_list.c:142
int cclArrayListDelIdx(ccl_array_list_t *tal, size_t i, size_t count)
Delete range of elements of Array-List since index.
Definition: array_list.c:100
int cclArrayListAdd(ccl_array_list_t *tal, void *data)
Add element to Array-List.
Definition: array_list.c:124
size_t length
Count of elements in array.
Definition: array_list.h:53
void ** array
Core array.
Definition: array_list.h:52
void cclArrayListSort(ccl_array_list_t *tal, int(*compar)(const void *, const void *))
Run Qsort for array-list.
Definition: array_list.c:136
struct ccl_array_list ccl_array_list_t
Array-List structure.
int cclArrayListFree(ccl_array_list_t *tal)
Free memory allocated for Array-List.
Definition: array_list.c:27
void( array_list_free_fn)(void *data)
Definition: array_list.h:45
size_t cclArrayListLength(ccl_array_list_t *tal)
Get count of elements in Array-List.
Definition: array_list.c:130
Array-List structure.
Definition: array_list.h:50
array_list_free_fn * free_fn
Pointer to free-callback function.
Definition: array_list.h:55
ccl_array_list_t * cclArrayListNew(array_list_free_fn *free_fn)
Create new Array-List.
Definition: array_list.c:13
void * cclArrayListGetIdx(ccl_array_list_t *tal, size_t i)
Get element of Array-List by index.
Definition: array_list.c:45