Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1 | /*- |
| 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 | */ |
| 28 | int 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 | */ |
| 38 | void 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 | */ |
| 44 | void asn_set_empty(void *asn_set_of_x); |
| 45 | |
| 46 | #endif /* ASN_SET_OF_H */ |