]>
Commit | Line | Data |
---|---|---|
1 | // SPDX-License-Identifier: GPL-2.0-or-later | |
2 | /* | |
3 | * Generic vector interface header. | |
4 | * Copyright (C) 1997, 98 Kunihiro Ishiguro | |
5 | */ | |
6 | ||
7 | #ifndef _ZEBRA_VECTOR_H | |
8 | #define _ZEBRA_VECTOR_H | |
9 | ||
10 | #include "memory.h" | |
11 | ||
12 | #ifdef __cplusplus | |
13 | extern "C" { | |
14 | #endif | |
15 | ||
16 | /* struct for vector */ | |
17 | struct _vector { | |
18 | unsigned int active; /* number of active slots */ | |
19 | unsigned int alloced; /* number of allocated slot */ | |
20 | unsigned int count; | |
21 | void **index; /* index to data */ | |
22 | }; | |
23 | typedef struct _vector *vector; | |
24 | ||
25 | #define VECTOR_MIN_SIZE 1 | |
26 | ||
27 | /* (Sometimes) usefull macros. This macro convert index expression to | |
28 | array expression. */ | |
29 | /* Reference slot at given index, caller must ensure slot is active */ | |
30 | #define vector_slot(V,I) ((V)->index[(I)]) | |
31 | /* Number of active slots. | |
32 | * Note that this differs from vector_count() as it the count returned | |
33 | * will include any empty slots | |
34 | */ | |
35 | #define vector_active(V) ((V)->active) | |
36 | ||
37 | /* Prototypes. */ | |
38 | extern vector vector_init(unsigned int size); | |
39 | extern void vector_ensure(vector v, unsigned int num); | |
40 | extern int vector_empty_slot(vector v); | |
41 | extern int vector_set(vector v, void *val); | |
42 | extern int vector_set_index(vector v, unsigned int i, void *val); | |
43 | extern void vector_unset(vector v, unsigned int i); | |
44 | extern void vector_unset_value(vector v, void *val); | |
45 | extern void vector_remove(vector v, unsigned int ix); | |
46 | extern void vector_compact(vector v); | |
47 | ||
48 | static inline unsigned int vector_count(vector v) | |
49 | { | |
50 | return v->count; | |
51 | } | |
52 | ||
53 | extern void vector_free(vector v); | |
54 | extern vector vector_copy(vector v); | |
55 | ||
56 | extern void *vector_lookup(vector, unsigned int); | |
57 | extern void *vector_lookup_ensure(vector, unsigned int); | |
58 | extern void vector_to_array(vector v, void ***dest, int *argc); | |
59 | extern vector array_to_vector(void **src, int argc); | |
60 | ||
61 | #ifdef __cplusplus | |
62 | } | |
63 | #endif | |
64 | ||
65 | #endif /* _ZEBRA_VECTOR_H */ |