Debian Codegraph @

src/bin/dwarfdump/dd_tsearchbal.h

raw
1 #ifndef DWARF_TSEARCH_H
2 #define DWARF_TSEARCH_H
3 /* Copyright (c) 2013-2019, David Anderson
4 All rights reserved.
5 Redistribution and use in source and binary forms, with
6 or without modification, are permitted provided that the
7 following conditions are met:
8 Redistributions of source code must retain the above
9 copyright notice, this list of conditions and the following
10 disclaimer.
11 Redistributions in binary form must reproduce the above
12 copyright notice, this list of conditions and the following
13 disclaimer in the documentation and/or other materials
14 provided with the distribution.
15 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
16 CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
17 INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
20 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
26 OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
27 EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30 /* The following interfaces follow tsearch (See the Single
31 Unix Specification) but the implementation is
32 written without reference to the source code
33 of any version of tsearch. Only uses
34 of tsearch were examined, not tsearch source code.
35 See https://www.prevanders.net/tsearch.html
36 and https://www.prevanders.net/dwarf.html#tsearch
37 for information about tsearch.
38 We are matching the standard functional
39 interface here, but to avoid interfering with
40 libc implementations or code using libc
41 implementations, we change all the names.
42 */
43
44 /* The DW_VISIT values passed back to you through
45 the callback function in dwarf_twalk();
46 */
47 typedef enum
48 {
49 dwarf_preorder, /* Before visit children */
50 dwarf_postorder,/* After first children visit, before last */
51 dwarf_endorder, /* After visit of children, last visit */
52 dwarf_leaf
53 }
54 DW_VISIT;
55
56 /* We rename these so there is no conflict with another version
57 of the tsearch sources, such as is used in dwarfdump. */
58 #define dwarf_tsearch dd_tsearch
59 #define dwarf_tfind dd_tfind
60 #define dwarf_tdelete dd_tdelete
61 #define dwarf_twalk dd_twalk
62 #define dwarf_tdestroy dd_tdestroy
63 #define dwarf_tdump dd_tdump
64 #define dwarf_initialize_search_hash dd_initialize_search_hash
65
66 /* void * return values are actually
67 void **key so you must dereference these
68 once to get a key you passed in.
69 Hence the void ** and rootp name.
70 */
71
72 void *dwarf_tsearch(const void * /*key*/, void ** /*rootp*/,
73 int (* /*compar*/)(const void *, const void *));
74
75 void *dwarf_tfind(const void * /*key*/, void *const * /*rootp*/,
76 int (* /*compar*/)(const void *, const void *));
77
78 /*
79 dwarf_tdelete() returns NULL if it cannot delete anything
80 or if the tree is now empty (if empty, *rootp
81 is set NULL by dwarf_tdelete()).
82 If the delete succeeds and the tree is non-empty returns
83 a pointer to the parent node of the deleted item,
84 unless the deleted item was at the root, in which
85 case the returned pointer relates to the new root.
86 */
87 void *dwarf_tdelete(const void * /*key*/, void ** /*rootp*/,
88 int (* /*compar*/)(const void *, const void *));
89
90 /* Here the argument is really void *, theroot*/
91 void dwarf_twalk(const void * /*root*/,
92 void (* /*action*/)(const void * /*nodep*/,
93 const DW_VISIT /*which*/,
94 const int /*depth*/));
95
96 /* dwarf_tdestroy() cannot set the root pointer NULL, you must do
97 so on return from dwarf_tdestroy(). */
98 void dwarf_tdestroy(void * /*root*/,
99 void (* /*free_node*/)(void * /*nodep*/));
100
101 /* Prints a simple tree representation to stdout. For debugging.
102 */
103 void dwarf_tdump(const void*root,
104 char *(* /*keyprint*/)(const void *),
105 const char *msg);
106 #endif /* DWARF_TSEARCH_H */