-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharray.h
More file actions
54 lines (40 loc) · 1.37 KB
/
Copy patharray.h
File metadata and controls
54 lines (40 loc) · 1.37 KB
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
#ifndef __ARRAY__H
#define __ARRAY__H
#include "sglib.h"
#define IS_STR 0x1
#define IS_OBJ 0x2
typedef struct node_t {
/* Key, value - we allocate and free except for obj */
char *key;
char *value;
void *obj;
/* And with IS_ above to figure out what it is */
int bits:31;
/* Sglib stuff, don't touch */
char color_field:1;
struct node_t *left;
struct node_t *right;
} node;
/* SGLIB declarations - arrays here are actaully red-black trees */
SGLIB_DEFINE_RBTREE_PROTOTYPES( node, left, right, color_field, COMPARATOR );
struct array_t {
node * head;
struct sglib_node_iterator it;
};
struct array_t * array_new();
void array_add_str( struct array_t *arr, char *key, const char *value );
void array_free( struct array_t *arr );
node * array_get_node( struct array_t *arr, char *key );
char * array_get( struct array_t *arr, char *key );
char * array_get_macro( struct array_t *arr, char *key );
void * array_get_obj( struct array_t *arr, char *key );
void array_add_obj( struct array_t *arr, char *key, void *obj );
void * array_remove( struct array_t *arr, char *key );
int array_empty( struct array_t *arr );
/* Serialize to char **/
int array_serialize( struct array_t *arr, char **outs );
int array_deserialize( struct array_t *arr, char *input );
/* Iterator support */
node * array_first( struct array_t *arr );
node * array_next( struct array_t *arr );
#endif