summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>2003-01-20 16:30:59 +0000
committerJim Meyering <jim@meyering.net>2003-01-20 16:30:59 +0000
commitabe155b043d47ce1d2751debb4ba6931654c9da1 (patch)
tree9b68b4eae1ae508a184af5df72d991b1fa062003
parent8a9ca6d9d73f8e73fbf357551b1c58319e120e01 (diff)
downloadcoreutils-abe155b043d47ce1d2751debb4ba6931654c9da1.tar.xz
New file, from GNU libc.
-rw-r--r--lib/search_.h57
1 files changed, 57 insertions, 0 deletions
diff --git a/lib/search_.h b/lib/search_.h
new file mode 100644
index 000000000..01d6f6475
--- /dev/null
+++ b/lib/search_.h
@@ -0,0 +1,57 @@
+/* For use with hsearch(3). */
+#ifndef __COMPAR_FN_T
+# define __COMPAR_FN_T
+typedef int (*__compar_fn_t) (__const void *, __const void *);
+
+# ifdef __USE_GNU
+typedef __compar_fn_t comparison_fn_t;
+# endif
+#endif
+
+/* The tsearch routines are very interesting. They make many
+ assumptions about the compiler. It assumes that the first field
+ in node must be the "key" field, which points to the datum.
+ Everything depends on that. */
+/* For tsearch */
+typedef enum
+{
+ preorder,
+ postorder,
+ endorder,
+ leaf
+}
+VISIT;
+
+/* Search for an entry matching the given KEY in the tree pointed to
+ by *ROOTP and insert a new element if not found. */
+extern void *tsearch (__const void *__key, void **__rootp,
+ __compar_fn_t __compar);
+
+/* Search for an entry matching the given KEY in the tree pointed to
+ by *ROOTP. If no matching entry is available return NULL. */
+extern void *tfind (__const void *__key, void *__const *__rootp,
+ __compar_fn_t __compar);
+
+/* Remove the element matching KEY from the tree pointed to by *ROOTP. */
+extern void *tdelete (__const void *__restrict __key,
+ void **__restrict __rootp,
+ __compar_fn_t __compar);
+
+#ifndef __ACTION_FN_T
+# define __ACTION_FN_T
+typedef void (*__action_fn_t) (__const void *__nodep, VISIT __value,
+ int __level);
+#endif
+
+/* Walk through the whole tree and call the ACTION callback for every node
+ or leaf. */
+extern void twalk (__const void *__root, __action_fn_t __action);
+
+#ifdef __USE_GNU
+/* Callback type for function to free a tree node. If the keys are atomic
+ data this function should do nothing. */
+typedef void (*__free_fn_t) (void *__nodep);
+
+/* Destroy the whole tree, call FREEFCT for each node or leaf. */
+extern void tdestroy (void *__root, __free_fn_t __freefct);
+#endif