2023-02-08 13:17:09 +01:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2002-12-13 21:15:29 +01:00
|
|
|
/*
|
|
|
|
* Generic vector interface header.
|
|
|
|
* Copyright (C) 1997, 98 Kunihiro Ishiguro
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _ZEBRA_VECTOR_H
|
|
|
|
#define _ZEBRA_VECTOR_H
|
|
|
|
|
2015-05-29 05:48:31 +02:00
|
|
|
#include "memory.h"
|
|
|
|
|
2019-02-07 23:10:31 +01:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
/* struct for vector */
|
|
|
|
struct _vector {
|
2024-07-21 03:28:53 +02:00
|
|
|
/* active: index of last non-NULL item (+1)
|
|
|
|
* count: number of non-NULL items (+1)
|
|
|
|
*
|
|
|
|
* the two will be different if a slot is set to NULL (without pulling
|
|
|
|
* up later items in the array). Whether this happens depends on
|
|
|
|
* which vector functions are used. If no empty slots are used, the
|
|
|
|
* two fields will be identical.
|
|
|
|
*
|
|
|
|
* alloced: size of array pointed to by index. If this is 0, index
|
|
|
|
* points at a global variable rather than a malloc'd bit of memory.
|
|
|
|
* The vector code will convert to malloc'd memory if necessary to
|
|
|
|
* perform updates.
|
|
|
|
*/
|
|
|
|
unsigned int active;
|
|
|
|
unsigned int alloced;
|
2021-10-18 15:29:17 +02:00
|
|
|
unsigned int count;
|
2024-07-21 03:28:53 +02:00
|
|
|
|
|
|
|
/* whether struct _vector itself is dynamically allocated */
|
|
|
|
bool dynamic;
|
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
void **index; /* index to data */
|
|
|
|
};
|
|
|
|
typedef struct _vector *vector;
|
|
|
|
|
|
|
|
#define VECTOR_MIN_SIZE 1
|
|
|
|
|
|
|
|
/* (Sometimes) usefull macros. This macro convert index expression to
|
|
|
|
array expression. */
|
2005-03-14 21:19:01 +01:00
|
|
|
/* Reference slot at given index, caller must ensure slot is active */
|
2002-12-13 21:15:29 +01:00
|
|
|
#define vector_slot(V,I) ((V)->index[(I)])
|
2005-03-14 21:19:01 +01:00
|
|
|
/* Number of active slots.
|
|
|
|
* Note that this differs from vector_count() as it the count returned
|
|
|
|
* will include any empty slots
|
|
|
|
*/
|
|
|
|
#define vector_active(V) ((V)->active)
|
2002-12-13 21:15:29 +01:00
|
|
|
|
|
|
|
/* Prototypes. */
|
2005-05-06 Paul Jakma <paul@dishone.st>
* (general) extern and static'ification of functions in code and
header.
Cleanup any definitions with unspecified arguments.
Add casts for callback assignments where the callback is defined,
typically, as passing void *, but the function being assigned has
some other pointer type defined as its argument, as gcc complains
about casts from void * to X* via function arguments.
Fix some old K&R style function argument definitions.
Add noreturn gcc attribute to some functions, as appropriate.
Add unused gcc attribute to some functions (eg ones meant to help
while debugging)
Add guard defines to headers which were missing them.
* command.c: (install_node) add const qualifier, still doesnt shut
up the warning though, because of the double pointer.
(cmp_node) ditto
* keychain.c: (key_str2time) Add GET_LONG_RANGE() macro, derived
fromn vty.h ones to fix some of the (long) < 0 warnings.
* thread.c: (various) use thread_empty
(cpu_record_hash_key) should cast to uintptr_t, a stdint.h type
* vty.h: Add VTY_GET_IPV4_ADDRESS and VTY_GET_IPV4_PREFIX so they
removed from ospfd/ospf_vty.h
* zebra.h: Move definition of ZEBRA_PORT to here, to remove
dependence of lib on zebra/zserv.h
2005-05-06 23:25:49 +02:00
|
|
|
extern vector vector_init(unsigned int size);
|
|
|
|
extern void vector_ensure(vector v, unsigned int num);
|
|
|
|
extern int vector_empty_slot(vector v);
|
|
|
|
extern int vector_set(vector v, void *val);
|
|
|
|
extern int vector_set_index(vector v, unsigned int i, void *val);
|
|
|
|
extern void vector_unset(vector v, unsigned int i);
|
2017-01-25 04:13:02 +01:00
|
|
|
extern void vector_unset_value(vector v, void *val);
|
2018-05-26 00:49:53 +02:00
|
|
|
extern void vector_remove(vector v, unsigned int ix);
|
2018-05-29 23:38:18 +02:00
|
|
|
extern void vector_compact(vector v);
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2021-10-18 15:29:17 +02:00
|
|
|
static inline unsigned int vector_count(vector v)
|
|
|
|
{
|
|
|
|
return v->count;
|
|
|
|
}
|
|
|
|
|
2005-05-06 Paul Jakma <paul@dishone.st>
* (general) extern and static'ification of functions in code and
header.
Cleanup any definitions with unspecified arguments.
Add casts for callback assignments where the callback is defined,
typically, as passing void *, but the function being assigned has
some other pointer type defined as its argument, as gcc complains
about casts from void * to X* via function arguments.
Fix some old K&R style function argument definitions.
Add noreturn gcc attribute to some functions, as appropriate.
Add unused gcc attribute to some functions (eg ones meant to help
while debugging)
Add guard defines to headers which were missing them.
* command.c: (install_node) add const qualifier, still doesnt shut
up the warning though, because of the double pointer.
(cmp_node) ditto
* keychain.c: (key_str2time) Add GET_LONG_RANGE() macro, derived
fromn vty.h ones to fix some of the (long) < 0 warnings.
* thread.c: (various) use thread_empty
(cpu_record_hash_key) should cast to uintptr_t, a stdint.h type
* vty.h: Add VTY_GET_IPV4_ADDRESS and VTY_GET_IPV4_PREFIX so they
removed from ospfd/ospf_vty.h
* zebra.h: Move definition of ZEBRA_PORT to here, to remove
dependence of lib on zebra/zserv.h
2005-05-06 23:25:49 +02:00
|
|
|
extern void vector_free(vector v);
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2005-05-06 Paul Jakma <paul@dishone.st>
* (general) extern and static'ification of functions in code and
header.
Cleanup any definitions with unspecified arguments.
Add casts for callback assignments where the callback is defined,
typically, as passing void *, but the function being assigned has
some other pointer type defined as its argument, as gcc complains
about casts from void * to X* via function arguments.
Fix some old K&R style function argument definitions.
Add noreturn gcc attribute to some functions, as appropriate.
Add unused gcc attribute to some functions (eg ones meant to help
while debugging)
Add guard defines to headers which were missing them.
* command.c: (install_node) add const qualifier, still doesnt shut
up the warning though, because of the double pointer.
(cmp_node) ditto
* keychain.c: (key_str2time) Add GET_LONG_RANGE() macro, derived
fromn vty.h ones to fix some of the (long) < 0 warnings.
* thread.c: (various) use thread_empty
(cpu_record_hash_key) should cast to uintptr_t, a stdint.h type
* vty.h: Add VTY_GET_IPV4_ADDRESS and VTY_GET_IPV4_PREFIX so they
removed from ospfd/ospf_vty.h
* zebra.h: Move definition of ZEBRA_PORT to here, to remove
dependence of lib on zebra/zserv.h
2005-05-06 23:25:49 +02:00
|
|
|
extern void *vector_lookup(vector, unsigned int);
|
|
|
|
extern void *vector_lookup_ensure(vector, unsigned int);
|
2018-05-11 21:32:06 +02:00
|
|
|
extern void vector_to_array(vector v, void ***dest, int *argc);
|
|
|
|
extern vector array_to_vector(void **src, int argc);
|
2019-02-07 23:10:31 +01:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
#endif /* _ZEBRA_VECTOR_H */
|