1 1.22 christos /* $NetBSD: search.h,v 1.22 2014/07/20 20:17:21 christos Exp $ */ 2 1.6 cgd 3 1.1 jtc /* 4 1.15 salo * Written by J.T. Conklin <jtc (at) NetBSD.org> 5 1.7 jtc * Public domain. 6 1.1 jtc */ 7 1.1 jtc 8 1.1 jtc #ifndef _SEARCH_H_ 9 1.1 jtc #define _SEARCH_H_ 10 1.11 kleink 11 1.2 jtc #include <sys/cdefs.h> 12 1.20 joerg #include <sys/featuretest.h> 13 1.2 jtc #include <machine/ansi.h> 14 1.1 jtc 15 1.5 cgd #ifdef _BSD_SIZE_T_ 16 1.5 cgd typedef _BSD_SIZE_T_ size_t; 17 1.5 cgd #undef _BSD_SIZE_T_ 18 1.2 jtc #endif 19 1.1 jtc 20 1.9 jtc typedef struct entry { 21 1.9 jtc char *key; 22 1.11 kleink void *data; 23 1.9 jtc } ENTRY; 24 1.9 jtc 25 1.19 christos #ifdef _NETBSD_SOURCE 26 1.19 christos struct _ENTRY; 27 1.19 christos struct hsearch_data { 28 1.19 christos struct _ENTRY *table; 29 1.19 christos size_t size; 30 1.19 christos size_t filled; 31 1.19 christos }; 32 1.19 christos #endif 33 1.19 christos 34 1.9 jtc typedef enum { 35 1.9 jtc FIND, ENTER 36 1.9 jtc } ACTION; 37 1.9 jtc 38 1.8 jtc typedef enum { 39 1.8 jtc preorder, 40 1.8 jtc postorder, 41 1.8 jtc endorder, 42 1.8 jtc leaf 43 1.8 jtc } VISIT; 44 1.12 christos 45 1.12 christos #ifdef _SEARCH_PRIVATE 46 1.12 christos typedef struct node { 47 1.12 christos char *key; 48 1.12 christos struct node *llink, *rlink; 49 1.12 christos } node_t; 50 1.12 christos #endif 51 1.8 jtc 52 1.1 jtc __BEGIN_DECLS 53 1.14 christos #ifndef __BSEARCH_DECLARED 54 1.14 christos #define __BSEARCH_DECLARED 55 1.14 christos /* also in stdlib.h */ 56 1.16 perry void *bsearch(const void *, const void *, size_t, size_t, 57 1.16 perry int (*)(const void *, const void *)); 58 1.14 christos #endif /* __BSEARCH_DECLARED */ 59 1.19 christos 60 1.16 perry int hcreate(size_t); 61 1.16 perry void hdestroy(void); 62 1.16 perry ENTRY *hsearch(ENTRY, ACTION); 63 1.16 perry 64 1.19 christos #ifdef _NETBSD_SOURCE 65 1.22 christos void hdestroy1(void (*)(void *), void (*)(void *)); 66 1.19 christos int hcreate_r(size_t, struct hsearch_data *); 67 1.19 christos void hdestroy_r(struct hsearch_data *); 68 1.22 christos void hdestroy1_r(struct hsearch_data *, void (*)(void *), void (*)(void *)); 69 1.19 christos int hsearch_r(ENTRY, ACTION, ENTRY **, struct hsearch_data *); 70 1.19 christos #endif /* _NETBSD_SOURCE */ 71 1.19 christos 72 1.16 perry void *lfind(const void *, const void *, size_t *, size_t, 73 1.16 perry int (*)(const void *, const void *)); 74 1.18 drochner void *lsearch(const void *, void *, size_t *, size_t, 75 1.16 perry int (*)(const void *, const void *)); 76 1.16 perry void insque(void *, void *); 77 1.16 perry void remque(void *); 78 1.16 perry 79 1.17 kleink void *tdelete(const void * __restrict, void ** __restrict, 80 1.16 perry int (*)(const void *, const void *)); 81 1.17 kleink void *tfind(const void *, void * const *, 82 1.16 perry int (*)(const void *, const void *)); 83 1.16 perry void *tsearch(const void *, void **, 84 1.16 perry int (*)(const void *, const void *)); 85 1.17 kleink void twalk(const void *, void (*)(const void *, VISIT, int)); 86 1.1 jtc __END_DECLS 87 1.1 jtc 88 1.11 kleink #endif /* !_SEARCH_H_ */ 89