blob: 1443a7b81e7f7393ceaba6892d82d4063215a2ca [file] [log] [blame]
vlmfa67ddc2004-06-03 03:38:44 +00001/*-
2 * Copyright (c) 2003, 2004 Lev Walkin <vlm@lionet.info>. All rights reserved.
3 * Redistribution and modifications are permitted subject to BSD license.
4 */
5#ifndef ASN_SET_OF_H
6#define ASN_SET_OF_H
7
8#define A_SET_OF(type) \
9 struct { \
10 type **array; \
11 int count; /* Meaningful size */ \
12 int size; /* Allocated size */ \
13 void (*free)(type *); \
14 }
15
16#define ASN_SET_ADD(headptr, ptr) \
17 asn_set_add((headptr), (ptr))
18
19/*******************************************
20 * Implementation of the SET OF structure.
21 */
22
23/*
24 * Add another structure into the set by its pointer.
25 * RETURN VALUES:
26 * 0 for success and -1/errno for failure.
27 */
28int asn_set_add(void *asn_set_of_x, void *ptr);
29
30/*
31 * Delete the element from the set by its number (base 0).
32 * This is a constant-time operation. The order of elements before the
33 * deleted ones is guaranteed, the order of elements after the deleted
34 * one is NOT guaranteed.
35 * If _do_free is given AND the (*free) is initialized, the element
36 * will be freed using the custom (*free) function as well.
37 */
38void asn_set_del(void *asn_set_of_x, int number, int _do_free);
39
40/*
41 * Empty the contents of the set. Will free the elements, if (*free) is given.
42 * Will NOT free the set itself.
43 */
44void asn_set_empty(void *asn_set_of_x);
45
46#endif /* ASN_SET_OF_H */