-
Notifications
You must be signed in to change notification settings - Fork 0
/
array.h
53 lines (39 loc) · 1.22 KB
/
array.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
#ifndef _CPO_ARRAY_H
#define _CPO_ARRAY_H
#include <stdint.h>
#define ARR_VAL(p) *((uintptr_t*)p)
#define ARR_VAL2PTR(v) ((uintptr_t)(v))
typedef size_t asize_t;
typedef struct s_array {
asize_t num;
asize_t max;
void *v;
asize_t elem_size;
} cpo_array_t;
cpo_array_t *
cpo_array_create(asize_t size, asize_t elem_size);
void *
cpo_array_get_at(cpo_array_t *a, asize_t index);
void *
cpo_array_push(cpo_array_t *a);
void *
cpo_array_insert_at(cpo_array_t *a, asize_t index);
void *
cpo_array_remove(cpo_array_t *a, asize_t index);
void
cpo_array_qsort(cpo_array_t *a, int (*cmp_func)(const void *, const void *));
void *cpo_array_bsearch(cpo_array_t *ar, const void *key,
int (*compar)(const void *, const void *));
void
cpo_array_destroy(cpo_array_t *a);
/*stack impl */
void * stack_push(cpo_array_t *stack);
void * stack_pop(cpo_array_t *stack);
void * stack_pop_back(cpo_array_t *stack);
void * stack_push_back(cpo_array_t *stack);
void * stack_back(cpo_array_t *stack);
int array_cmp_int_asc(const void *a, const void *b);
int array_cmp_int_dsc(const void *a, const void *b);
int array_cmp_str_asc(const void *a, const void *b);
int array_cmp_str_dsc(const void *a, const void *b);
#endif