]>
Commit | Line | Data |
---|---|---|
acddc0ed | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
718e3744 | 2 | /* |
3 | * Generic vector interface header. | |
4 | * Copyright (C) 1997, 98 Kunihiro Ishiguro | |
718e3744 | 5 | */ |
6 | ||
7 | #ifndef _ZEBRA_VECTOR_H | |
8 | #define _ZEBRA_VECTOR_H | |
9 | ||
4a1ab8e4 | 10 | #include "memory.h" |
4a1ab8e4 | 11 | |
5e244469 RW |
12 | #ifdef __cplusplus |
13 | extern "C" { | |
14 | #endif | |
15 | ||
718e3744 | 16 | /* struct for vector */ |
d62a17ae | 17 | struct _vector { |
18 | unsigned int active; /* number of active slots */ | |
19 | unsigned int alloced; /* number of allocated slot */ | |
14c39974 | 20 | unsigned int count; |
d62a17ae | 21 | void **index; /* index to data */ |
718e3744 | 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. */ | |
55468c86 | 29 | /* Reference slot at given index, caller must ensure slot is active */ |
718e3744 | 30 | #define vector_slot(V,I) ((V)->index[(I)]) |
d62a17ae | 31 | /* Number of active slots. |
55468c86 | 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) | |
718e3744 | 36 | |
37 | /* Prototypes. */ | |
d62a17ae | 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); | |
62bece44 | 45 | extern void vector_remove(vector v, unsigned int ix); |
f428cb8a | 46 | extern void vector_compact(vector v); |
d62a17ae | 47 | |
14c39974 DL |
48 | static inline unsigned int vector_count(vector v) |
49 | { | |
50 | return v->count; | |
51 | } | |
52 | ||
d62a17ae | 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); | |
fe011935 QY |
58 | extern void vector_to_array(vector v, void ***dest, int *argc); |
59 | extern vector array_to_vector(void **src, int argc); | |
5e244469 RW |
60 | |
61 | #ifdef __cplusplus | |
62 | } | |
63 | #endif | |
64 | ||
718e3744 | 65 | #endif /* _ZEBRA_VECTOR_H */ |