xref: /onnv-gate/usr/src/lib/libldap4/include/hsearch.h (revision 3857:21b9b714e4ab)
1 /*
2  * Copyright 1998 Sun Microsystems, Inc.  All rights reserved.
3  * Use is subject to license terms.
4  */
5 
6 
7 #pragma ident	"%Z%%M%	%I%	%E% SMI"
8 
9 #include <sys/types.h>
10 
11 #ident "@(#)hsearch.h	1.3 07/23/97 SMI"
12 typedef struct {	/* Hash table entry */
13     char * key;
14     char * data;
15     int    dsize;
16     int    modified;
17     time_t timestamp;
18 } HASH_ENTRY;
19 
20 typedef struct node {	/* Part of the linked list of entries */
21 	HASH_ENTRY item;
22 	struct node *next;
23 } NODE;
24 
25 typedef enum {
26     FIND,		/* Find, if present */
27     ENTER,		/* Find; enter if not present */
28     REPLACE,	/* replace */
29     DELETE,		/* delete  */
30 } ACTION;
31 
32 /* define everything that a hash table needs to drag around */
33 typedef struct hash_table {
34 	NODE **table;	/* The address of the hash table */
35 	unsigned int length;	/* Size of the hash table */
36 	unsigned int m;		/* Log base 2 of length */
37 	unsigned int count;		/*  nb entries in the hash table */
38 	mutex_t table_lock;	/* currently not used */
39 	int	 alloc_data;	/* true if data is allocated and copied in the hast table */
40 	int	 clean;	        /* to force cleanup of the hash table */
41 	int 	size;		/* Max size of the hast table, defaulted 5000	*/
42 } HASH_TABLE;
43 
44 void hdestroy_s(HASH_TABLE **hash_table);
45 HASH_ENTRY *hsearch_s(HASH_TABLE *hash_table, HASH_ENTRY item, ACTION action);
46 HASH_ENTRY *hlist_s(HASH_TABLE *hash_table, int * i, NODE ** a);
47 HASH_TABLE *hcreate_s(size_t size, int alloc_data);
48 
49 /* convenience functions for adding and find things */
50 int hadd_s(HASH_TABLE **hash_table, char *key, void *data, int size);
51 int hreplace_s(HASH_TABLE **hash_table, char *key, void *data, int size);
52 char *hfind_s(HASH_TABLE *hash_table, char *key);
53 int hdelete_s( HASH_TABLE *hash_table, char * key);
54