|
Packit Service |
db8eaa |
/* Declarations for System V style searching functions.
|
|
Packit Service |
db8eaa |
Copyright (C) 1995-1999, 2000 Free Software Foundation, Inc.
|
|
Packit Service |
db8eaa |
This file is part of the GNU C Library.
|
|
Packit Service |
db8eaa |
|
|
Packit Service |
db8eaa |
The GNU C Library is free software; you can redistribute it and/or
|
|
Packit Service |
db8eaa |
modify it under the terms of the GNU Lesser General Public License as
|
|
Packit Service |
db8eaa |
published by the Free Software Foundation; either version 2.1 of the
|
|
Packit Service |
db8eaa |
License, or (at your option) any later version.
|
|
Packit Service |
db8eaa |
|
|
Packit Service |
db8eaa |
The GNU C Library is distributed in the hope that it will be useful,
|
|
Packit Service |
db8eaa |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit Service |
db8eaa |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit Service |
db8eaa |
Lesser General Public License for more details.
|
|
Packit Service |
db8eaa |
|
|
Packit Service |
db8eaa |
You should have received a copy of the GNU Lesser General Public
|
|
Packit Service |
db8eaa |
License along with the GNU C Library; see the file COPYING.LIB. If not,
|
|
Packit Service |
db8eaa |
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
Packit Service |
db8eaa |
Boston, MA 02111-1307, USA. */
|
|
Packit Service |
db8eaa |
|
|
Packit Service |
db8eaa |
#ifndef _SEARCH_H
|
|
Packit Service |
db8eaa |
#define _SEARCH_H 1
|
|
Packit Service |
db8eaa |
|
|
Packit Service |
db8eaa |
#include <features.h>
|
|
Packit Service |
db8eaa |
|
|
Packit Service |
db8eaa |
#define __need_size_t
|
|
Packit Service |
db8eaa |
#include <stddef.h>
|
|
Packit Service |
db8eaa |
|
|
Packit Service |
db8eaa |
__BEGIN_DECLS
|
|
Packit Service |
db8eaa |
|
|
Packit Service |
db8eaa |
#if defined __USE_SVID || defined __USE_XOPEN_EXTENDED
|
|
Packit Service |
db8eaa |
/* Prototype structure for a linked-list data structure.
|
|
Packit Service |
db8eaa |
This is the type used by the `insque' and `remque' functions. */
|
|
Packit Service |
db8eaa |
|
|
Packit Service |
db8eaa |
# ifdef __USE_GNU
|
|
Packit Service |
db8eaa |
struct qelem
|
|
Packit Service |
db8eaa |
{
|
|
Packit Service |
db8eaa |
struct qelem *q_forw;
|
|
Packit Service |
db8eaa |
struct qelem *q_back;
|
|
Packit Service |
db8eaa |
char q_data[1];
|
|
Packit Service |
db8eaa |
};
|
|
Packit Service |
db8eaa |
# endif
|
|
Packit Service |
db8eaa |
|
|
Packit Service |
db8eaa |
|
|
Packit Service |
db8eaa |
/* Insert ELEM into a doubly-linked list, after PREV. */
|
|
Packit Service |
db8eaa |
extern void insque __P ((void *__elem, void *__prev));
|
|
Packit Service |
db8eaa |
|
|
Packit Service |
db8eaa |
/* Unlink ELEM from the doubly-linked list that it is in. */
|
|
Packit Service |
db8eaa |
extern void remque __P ((void *__elem));
|
|
Packit Service |
db8eaa |
#endif
|
|
Packit Service |
db8eaa |
|
|
Packit Service |
db8eaa |
|
|
Packit Service |
db8eaa |
/* For use with hsearch(3). */
|
|
Packit Service |
db8eaa |
#ifndef __COMPAR_FN_T
|
|
Packit Service |
db8eaa |
# define __COMPAR_FN_T
|
|
Packit Service |
db8eaa |
typedef int (*__compar_fn_t) __PMT ((__const __ptr_t, __const __ptr_t));
|
|
Packit Service |
db8eaa |
|
|
Packit Service |
db8eaa |
# ifdef __USE_GNU
|
|
Packit Service |
db8eaa |
typedef __compar_fn_t comparison_fn_t;
|
|
Packit Service |
db8eaa |
# endif
|
|
Packit Service |
db8eaa |
#endif
|
|
Packit Service |
db8eaa |
|
|
Packit Service |
db8eaa |
/* Action which shall be performed in the call the hsearch. */
|
|
Packit Service |
db8eaa |
typedef enum
|
|
Packit Service |
db8eaa |
{
|
|
Packit Service |
db8eaa |
FIND,
|
|
Packit Service |
db8eaa |
ENTER
|
|
Packit Service |
db8eaa |
}
|
|
Packit Service |
db8eaa |
ACTION;
|
|
Packit Service |
db8eaa |
|
|
Packit Service |
db8eaa |
typedef struct entry
|
|
Packit Service |
db8eaa |
{
|
|
Packit Service |
db8eaa |
char *key;
|
|
Packit Service |
db8eaa |
void *data;
|
|
Packit Service |
db8eaa |
}
|
|
Packit Service |
db8eaa |
ENTRY;
|
|
Packit Service |
db8eaa |
|
|
Packit Service |
db8eaa |
/* Opaque type for internal use. */
|
|
Packit Service |
db8eaa |
struct _ENTRY;
|
|
Packit Service |
db8eaa |
|
|
Packit Service |
db8eaa |
/* Family of hash table handling functions. The functions also
|
|
Packit Service |
db8eaa |
have reentrant counterparts ending with _r. The non-reentrant
|
|
Packit Service |
db8eaa |
functions all work on a single internal hashing table. */
|
|
Packit Service |
db8eaa |
|
|
Packit Service |
db8eaa |
/* Search for entry matching ITEM.key in internal hash table. If
|
|
Packit Service |
db8eaa |
ACTION is `FIND' return found entry or signal error by returning
|
|
Packit Service |
db8eaa |
NULL. If ACTION is `ENTER' replace existing data (if any) with
|
|
Packit Service |
db8eaa |
ITEM.data. */
|
|
Packit Service |
db8eaa |
extern ENTRY *hsearch __P ((ENTRY __item, ACTION __action));
|
|
Packit Service |
db8eaa |
|
|
Packit Service |
db8eaa |
/* Create a new hashing table which will at most contain NEL elements. */
|
|
Packit Service |
db8eaa |
extern int hcreate __P ((size_t __nel));
|
|
Packit Service |
db8eaa |
|
|
Packit Service |
db8eaa |
/* Destroy current internal hashing table. */
|
|
Packit Service |
db8eaa |
extern void hdestroy __P ((void));
|
|
Packit Service |
db8eaa |
|
|
Packit Service |
db8eaa |
#ifdef __USE_GNU
|
|
Packit Service |
db8eaa |
/* Data type for reentrant functions. */
|
|
Packit Service |
db8eaa |
struct hsearch_data
|
|
Packit Service |
db8eaa |
{
|
|
Packit Service |
db8eaa |
struct _ENTRY *table;
|
|
Packit Service |
db8eaa |
unsigned int size;
|
|
Packit Service |
db8eaa |
unsigned int filled;
|
|
Packit Service |
db8eaa |
};
|
|
Packit Service |
db8eaa |
|
|
Packit Service |
db8eaa |
/* Reentrant versions which can handle multiple hashing tables at the
|
|
Packit Service |
db8eaa |
same time. */
|
|
Packit Service |
db8eaa |
extern int hsearch_r __P ((ENTRY __item, ACTION __action, ENTRY **__retval,
|
|
Packit Service |
db8eaa |
struct hsearch_data *__htab));
|
|
Packit Service |
db8eaa |
extern int hcreate_r __P ((size_t __nel, struct hsearch_data *__htab));
|
|
Packit Service |
db8eaa |
extern void hdestroy_r __P ((struct hsearch_data *__htab));
|
|
Packit Service |
db8eaa |
#endif
|
|
Packit Service |
db8eaa |
|
|
Packit Service |
db8eaa |
|
|
Packit Service |
db8eaa |
/* The tsearch routines are very interesting. They make many
|
|
Packit Service |
db8eaa |
assumptions about the compiler. It assumes that the first field
|
|
Packit Service |
db8eaa |
in node must be the "key" field, which points to the datum.
|
|
Packit Service |
db8eaa |
Everything depends on that. */
|
|
Packit Service |
db8eaa |
/* For tsearch */
|
|
Packit Service |
db8eaa |
typedef enum
|
|
Packit Service |
db8eaa |
{
|
|
Packit Service |
db8eaa |
preorder,
|
|
Packit Service |
db8eaa |
postorder,
|
|
Packit Service |
db8eaa |
endorder,
|
|
Packit Service |
db8eaa |
leaf
|
|
Packit Service |
db8eaa |
}
|
|
Packit Service |
db8eaa |
VISIT;
|
|
Packit Service |
db8eaa |
|
|
Packit Service |
db8eaa |
/* Search for an entry matching the given KEY in the tree pointed to
|
|
Packit Service |
db8eaa |
by *ROOTP and insert a new element if not found. */
|
|
Packit Service |
db8eaa |
extern void *tsearch __PMT ((__const void *__key, void **__rootp,
|
|
Packit Service |
db8eaa |
__compar_fn_t __compar));
|
|
Packit Service |
db8eaa |
|
|
Packit Service |
db8eaa |
/* Search for an entry matching the given KEY in the tree pointed to
|
|
Packit Service |
db8eaa |
by *ROOTP. If no matching entry is available return NULL. */
|
|
Packit Service |
db8eaa |
extern void *tfind __PMT ((__const void *__key, void *__const *__rootp,
|
|
Packit Service |
db8eaa |
__compar_fn_t __compar));
|
|
Packit Service |
db8eaa |
|
|
Packit Service |
db8eaa |
/* Remove the element matching KEY from the tree pointed to by *ROOTP. */
|
|
Packit Service |
db8eaa |
extern void *tdelete __PMT ((__const void *__key, void **__rootp,
|
|
Packit Service |
db8eaa |
__compar_fn_t __compar));
|
|
Packit Service |
db8eaa |
|
|
Packit Service |
db8eaa |
#ifndef __ACTION_FN_T
|
|
Packit Service |
db8eaa |
# define __ACTION_FN_T
|
|
Packit Service |
db8eaa |
typedef void (*__action_fn_t) __PMT ((__const void *__nodep,
|
|
Packit Service |
db8eaa |
VISIT __value,
|
|
Packit Service |
db8eaa |
int __level));
|
|
Packit Service |
db8eaa |
#endif
|
|
Packit Service |
db8eaa |
|
|
Packit Service |
db8eaa |
/* Walk through the whole tree and call the ACTION callback for every node
|
|
Packit Service |
db8eaa |
or leaf. */
|
|
Packit Service |
db8eaa |
extern void twalk __PMT ((__const void *__root, __action_fn_t __action));
|
|
Packit Service |
db8eaa |
|
|
Packit Service |
db8eaa |
#ifdef __USE_GNU
|
|
Packit Service |
db8eaa |
/* Callback type for function to free a tree node. If the keys are atomic
|
|
Packit Service |
db8eaa |
data this function should do nothing. */
|
|
Packit Service |
db8eaa |
typedef void (*__free_fn_t) __PMT ((void *__nodep));
|
|
Packit Service |
db8eaa |
|
|
Packit Service |
db8eaa |
/* Destroy the whole tree, call FREEFCT for each node or leaf. */
|
|
Packit Service |
db8eaa |
extern void tdestroy __PMT ((void *__root, __free_fn_t __freefct));
|
|
Packit Service |
db8eaa |
#endif
|
|
Packit Service |
db8eaa |
|
|
Packit Service |
db8eaa |
|
|
Packit Service |
db8eaa |
/* Perform linear search for KEY by comparing by COMPAR in an array
|
|
Packit Service |
db8eaa |
[BASE,BASE+NMEMB*SIZE). */
|
|
Packit Service |
db8eaa |
extern void *lfind __PMT ((__const void *__key, __const void *__base,
|
|
Packit Service |
db8eaa |
size_t *__nmemb, size_t __size,
|
|
Packit Service |
db8eaa |
__compar_fn_t __compar));
|
|
Packit Service |
db8eaa |
|
|
Packit Service |
db8eaa |
/* Perform linear search for KEY by comparing by COMPAR function in
|
|
Packit Service |
db8eaa |
array [BASE,BASE+NMEMB*SIZE) and insert entry if not found. */
|
|
Packit Service |
db8eaa |
extern void *lsearch __PMT ((__const void *__key, void *__base,
|
|
Packit Service |
db8eaa |
size_t *__nmemb, size_t __size,
|
|
Packit Service |
db8eaa |
__compar_fn_t __compar));
|
|
Packit Service |
db8eaa |
|
|
Packit Service |
db8eaa |
__END_DECLS
|
|
Packit Service |
db8eaa |
|
|
Packit Service |
db8eaa |
#endif /* search.h */
|