1 #ifndef SRC_SORTED_ARRAY_H_ 2 #define SRC_SORTED_ARRAY_H_ 3 4 #include <stdbool.h> 5 #include <stddef.h> 6 7 /* 8 * This implementation is not a generic sorted array; It's intended to store RFC 9 * 3779 resources, which requires the elements to be sorted. 10 * So you can only add elements to the tail of the array. The implementation 11 * will validate this and prevent collisions too. 12 */ 13 14 struct sorted_array; 15 16 enum sarray_comparison { 17 SACMP_EQUAL, 18 SACMP_CHILD, 19 SACMP_PARENT, 20 SACMP_LEFT, 21 SACMP_RIGHT, 22 SACMP_ADJACENT_LEFT, 23 SACMP_ADJACENT_RIGHT, 24 SACMP_INTERSECTION, 25 }; 26 27 typedef enum sarray_comparison (*sarray_cmp)(void *, void *); 28 29 struct sorted_array *sarray_create(size_t, sarray_cmp); 30 void sarray_get(struct sorted_array *); 31 void sarray_put(struct sorted_array *); 32 33 #define EEQUAL 7894 34 #define ECHILD2 7895 35 #define EPARENT 7896 36 #define ELEFT 7897 37 #define EADJLEFT 7898 38 #define EADJRIGHT 7899 39 #define EINTERSECTION 7900 40 41 int sarray_add(struct sorted_array *, void *); 42 bool sarray_empty(struct sorted_array *); 43 bool sarray_contains(struct sorted_array *, void *); 44 45 typedef int (*sarray_foreach_cb)(void *, void *); 46 int sarray_foreach(struct sorted_array *, sarray_foreach_cb, void *); 47 48 char const *sarray_err2str(int); 49 50 #endif /* SRC_SORTED_ARRAY_H_ */ 51