1 #ifndef _SEARCH_H 2 #define _SEARCH_H 3 4 #ifdef __cplusplus 5 extern "C" { 6 #endif 7 8 #include <features.h> 9 10 #define __NEED_size_t 11 #include <bits/alltypes.h> 12 13 typedef enum { FIND, ENTER } ACTION; 14 typedef enum { preorder, postorder, endorder, leaf } VISIT; 15 16 typedef struct entry { 17 char *key; 18 void *data; 19 } ENTRY; 20 21 int hcreate(size_t); 22 void hdestroy(void); 23 ENTRY *hsearch(ENTRY, ACTION); 24 25 #ifdef _GNU_SOURCE 26 struct hsearch_data { 27 struct __tab *__tab; 28 unsigned int __unused1; 29 unsigned int __unused2; 30 }; 31 32 int hcreate_r(size_t, struct hsearch_data *); 33 void hdestroy_r(struct hsearch_data *); 34 int hsearch_r(ENTRY, ACTION, ENTRY **, struct hsearch_data *); 35 #endif 36 37 void insque(void *, void *); 38 void remque(void *); 39 40 void *lsearch(const void *, void *, size_t *, size_t, 41 int (*)(const void *, const void *)); 42 void *lfind(const void *, const void *, size_t *, size_t, 43 int (*)(const void *, const void *)); 44 45 void *tdelete(const void *__restrict, void **__restrict, int(*)(const void *, const void *)); 46 void *tfind(const void *, void *const *, int(*)(const void *, const void *)); 47 void *tsearch(const void *, void **, int (*)(const void *, const void *)); 48 void twalk(const void *, void (*)(const void *, VISIT, int)); 49 50 #ifdef _GNU_SOURCE 51 struct qelem { 52 struct qelem *q_forw, *q_back; 53 char q_data[1]; 54 }; 55 56 void tdestroy(void *, void (*)(void *)); 57 #endif 58 59 #ifdef __cplusplus 60 } 61 #endif 62 63 #endif 64