1 /* 2 * Copyright 2008-2012 Haiku, Inc. All Rights Reserved. 3 * Distributed under the terms of the MIT License. 4 */ 5 #ifndef _SEARCH_H_ 6 #define _SEARCH_H_ 7 8 9 #include <sys/types.h> 10 11 12 typedef enum { 13 FIND, 14 ENTER 15 } ACTION; 16 17 typedef struct entry { 18 char *key; 19 void *data; 20 } ENTRY; 21 22 typedef enum { 23 preorder, 24 postorder, 25 endorder, 26 leaf 27 } VISIT; 28 29 30 #ifdef __cplusplus 31 extern "C" { 32 #endif 33 34 extern int hcreate(size_t elementCount); 35 extern void hdestroy(void); 36 extern ENTRY *hsearch(ENTRY iteam, ACTION action); 37 extern void insque(void *element, void *insertAfter); 38 extern void *lfind(const void *key, const void *base, size_t *_elementCount, 39 size_t width, int (*compareFunction)(const void *, const void *)); 40 extern void *lsearch(const void *key, void *base, size_t *_elementCount, 41 size_t width, int (*compareFunction)(const void *, const void *)); 42 extern void remque(void *element); 43 extern void *tdelete(const void *key, void **_root, 44 int (*compare)(const void *, const void *)); 45 extern void *tfind(const void *key, void *const *root, 46 int (*compare)(const void *, const void *)); 47 extern void *tsearch(const void *key, void **_root, 48 int (*compare)(const void *, const void *)); 49 extern void twalk(const void *root, 50 void (*action)(const void *, VISIT, int )); 51 52 #ifdef _GNU_SOURCE 53 extern void tdestroy(void *root, void (*free_key)(void *)); 54 #endif 55 56 #ifdef __cplusplus 57 } 58 #endif 59 60 #endif /* _SEARCH_H_ */ 61