1 /* A GNU-like <search.h>.
3 Copyright (C) 2007-2010 Free Software Foundation, Inc.
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
21 @PRAGMA_SYSTEM_HEADER@
24 /* The include_next requires a split double-inclusion guard. */
26 # @INCLUDE_NEXT@ @NEXT_SEARCH_H@
33 /* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
35 /* The definition of _GL_ARG_NONNULL is copied here. */
37 /* The definition of _GL_WARN_ON_USE is copied here. */
41 # if @REPLACE_TSEARCH@
42 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
43 # define tsearch rpl_tsearch
44 # define tfind rpl_tfind
45 # define tdelete rpl_tdelete
46 # define twalk rpl_twalk
50 /* See <http://www.opengroup.org/susv3xbd/search.h.html>,
51 <http://www.opengroup.org/susv3xsh/tsearch.html>
68 typedef int (*_gl_search_compar_fn) (const void *, const void *);
69 typedef void (*_gl_search_action_fn) (const void *, VISIT, int);
74 /* Searches an element in the tree *VROOTP that compares equal to KEY.
75 If one is found, it is returned. Otherwise, a new element equal to KEY
76 is inserted in the tree and is returned. */
77 # if @REPLACE_TSEARCH@
78 _GL_FUNCDECL_RPL (tsearch, void *,
79 (const void *key, void **vrootp,
80 _gl_search_compar_fn compar)
81 _GL_ARG_NONNULL ((1, 2, 3)));
82 _GL_CXXALIAS_RPL (tsearch, void *,
83 (const void *key, void **vrootp,
84 _gl_search_compar_fn compar));
87 _GL_FUNCDECL_SYS (tsearch, void *,
88 (const void *key, void **vrootp,
89 _gl_search_compar_fn compar)
90 _GL_ARG_NONNULL ((1, 2, 3)));
92 _GL_CXXALIAS_SYS (tsearch, void *,
93 (const void *key, void **vrootp,
94 _gl_search_compar_fn compar));
96 _GL_CXXALIASWARN (tsearch);
98 /* Searches an element in the tree *VROOTP that compares equal to KEY.
99 If one is found, it is returned. Otherwise, NULL is returned. */
100 # if @REPLACE_TSEARCH@
101 _GL_FUNCDECL_RPL (tfind, void *,
102 (const void *key, void *const *vrootp,
103 _gl_search_compar_fn compar)
104 _GL_ARG_NONNULL ((1, 2, 3)));
105 _GL_CXXALIAS_RPL (tfind, void *,
106 (const void *key, void *const *vrootp,
107 _gl_search_compar_fn compar));
110 _GL_FUNCDECL_SYS (tfind, void *,
111 (const void *key, void *const *vrootp,
112 _gl_search_compar_fn compar)
113 _GL_ARG_NONNULL ((1, 2, 3)));
115 /* Need to cast, because on Cygwin 1.5.x systems, the second parameter is
117 _GL_CXXALIAS_SYS_CAST (tfind, void *,
118 (const void *key, void *const *vrootp,
119 _gl_search_compar_fn compar));
121 _GL_CXXALIASWARN (tfind);
123 /* Searches an element in the tree *VROOTP that compares equal to KEY.
124 If one is found, it is removed from the tree, and its parent node is
125 returned. Otherwise, NULL is returned. */
126 # if @REPLACE_TSEARCH@
127 _GL_FUNCDECL_RPL (tdelete, void *,
128 (const void *key, void **vrootp,
129 _gl_search_compar_fn compar)
130 _GL_ARG_NONNULL ((1, 2, 3)));
131 _GL_CXXALIAS_RPL (tdelete, void *,
132 (const void *key, void **vrootp,
133 _gl_search_compar_fn compar));
136 _GL_FUNCDECL_SYS (tdelete, void *,
137 (const void *key, void **vrootp,
138 _gl_search_compar_fn compar)
139 _GL_ARG_NONNULL ((1, 2, 3)));
141 _GL_CXXALIAS_SYS (tdelete, void *,
142 (const void *key, void **vrootp,
143 _gl_search_compar_fn compar));
145 _GL_CXXALIASWARN (tdelete);
147 /* Perform a depth-first, left-to-right traversal of the tree VROOT.
148 The ACTION function is called:
149 - for non-leaf nodes: 3 times, before the left subtree traversal,
150 after the left subtree traversal but before the right subtree traversal,
151 and after the right subtree traversal,
152 - for leaf nodes: once.
153 The arguments passed to ACTION are:
154 1. the node; it can be casted to a 'const void * const *', i.e. into a
156 2. an indicator which visit of the node this is,
157 3. the level of the node in the tree (0 for the root). */
158 # if @REPLACE_TSEARCH@
159 _GL_FUNCDECL_RPL (twalk, void,
160 (const void *vroot, _gl_search_action_fn action)
161 _GL_ARG_NONNULL ((2)));
162 _GL_CXXALIAS_RPL (twalk, void,
163 (const void *vroot, _gl_search_action_fn action));
166 _GL_FUNCDECL_SYS (twalk, void,
167 (const void *vroot, _gl_search_action_fn action)
168 _GL_ARG_NONNULL ((2)));
170 _GL_CXXALIAS_SYS (twalk, void,
171 (const void *vroot, _gl_search_action_fn action));
173 _GL_CXXALIASWARN (twalk);
175 #elif defined GNULIB_POSIXCHECK
177 # if HAVE_RAW_DECL_TSEARCH
178 _GL_WARN_ON_USE (tsearch, "tsearch is unportable - "
179 "use gnulib module tsearch for portability");
182 # if HAVE_RAW_DECL_TFIND
183 _GL_WARN_ON_USE (tfind, "tfind is unportable - "
184 "use gnulib module tsearch for portability");
187 # if HAVE_RAW_DECL_TDELETE
188 _GL_WARN_ON_USE (tdelete, "tdelete is unportable - "
189 "use gnulib module tsearch for portability");
192 # if HAVE_RAW_DECL_TWALK
193 _GL_WARN_ON_USE (twalk, "twalk is unportable - "
194 "use gnulib module tsearch for portability");
199 #endif /* _GL_SEARCH_H */
200 #endif /* _GL_SEARCH_H */