-
Notifications
You must be signed in to change notification settings - Fork 21
/
varray.h
110 lines (82 loc) · 2.11 KB
/
varray.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/* varnam-array.h
*
* Copyright (C) Navaneeth.K.N
*
* This is part of libvarnam. See LICENSE.txt for the license
*/
#ifndef VARNAM_ARRAY_H_INCLUDED_0924
#define VARNAM_ARRAY_H_INCLUDED_0924
#include "util.h"
#include "vtypes.h"
/**
* Array to hold pointers. This expands automatically.
*
**/
typedef struct varray_t
{
void **memory;
size_t allocated;
size_t used;
int index;
} varray;
typedef struct vpool_t
{
varray *array;
int next_slot;
varray *free_pool;
} vpool;
VARNAM_EXPORT extern varray*
varray_init();
VARNAM_EXPORT extern void
varray_push(varray *array, void *data);
VARNAM_EXPORT extern void
varray_copy(varray *source, varray *destination);
VARNAM_EXPORT extern void
varray_remove_at(varray *array, int index);
VARNAM_EXPORT extern int
varray_length(varray *array);
VARNAM_EXPORT extern bool
varray_is_empty (varray *array);
VARNAM_EXPORT extern bool
varray_exists (varray *array, void *item, bool (*equals)(void *left, void *right));
VARNAM_EXPORT extern void
varray_clear(varray *array);
VARNAM_EXPORT extern void*
varray_get(varray *array, int index);
VARNAM_EXPORT extern void*
varray_get_last_item(varray *array);
VARNAM_EXPORT extern void*
varray_pop_last_item(varray *array);
VARNAM_EXPORT extern void
varray_insert(varray *array, int index, void *data);
VARNAM_EXPORT extern void
varray_free(varray *array, void (*destructor)(void*));
VARNAM_EXPORT extern vpool*
vpool_init();
/**
* Returns next item from the pool. NULL otherwise
**/
VARNAM_EXPORT extern void*
vpool_get(vpool *pool);
VARNAM_EXPORT extern void
vpool_add(vpool *pool, void *item);
/**
* Returns the element back to the pool
*/
VARNAM_EXPORT extern void
vpool_return(vpool *pool, void *item);
VARNAM_EXPORT extern void
vpool_reset(vpool *pool);
/**
* Free the items contained in the pool and finally the pool itself
*
**/
VARNAM_EXPORT extern void
vpool_free(vpool *pool, void (*destructor)(void*));
VARNAM_EXPORT extern varray*
get_pooled_array (varnam *handle);
VARNAM_EXPORT extern void
return_array_to_pool (varnam *handle, varray *array);
VARNAM_EXPORT extern void
reset_pool(varnam *handle);
#endif