]> git.proxmox.com Git - mirror_frr.git/blame_incremental - lib/vector.h
*: auto-convert to SPDX License IDs
[mirror_frr.git] / lib / vector.h
... / ...
CommitLineData
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
13extern "C" {
14#endif
15
16/* struct for vector */
17struct _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};
23typedef 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. */
38extern vector vector_init(unsigned int size);
39extern void vector_ensure(vector v, unsigned int num);
40extern int vector_empty_slot(vector v);
41extern int vector_set(vector v, void *val);
42extern int vector_set_index(vector v, unsigned int i, void *val);
43extern void vector_unset(vector v, unsigned int i);
44extern void vector_unset_value(vector v, void *val);
45extern void vector_remove(vector v, unsigned int ix);
46extern void vector_compact(vector v);
47
48static inline unsigned int vector_count(vector v)
49{
50 return v->count;
51}
52
53extern void vector_free(vector v);
54extern vector vector_copy(vector v);
55
56extern void *vector_lookup(vector, unsigned int);
57extern void *vector_lookup_ensure(vector, unsigned int);
58extern void vector_to_array(vector v, void ***dest, int *argc);
59extern vector array_to_vector(void **src, int argc);
60
61#ifdef __cplusplus
62}
63#endif
64
65#endif /* _ZEBRA_VECTOR_H */