version 1 showing authors affecting page license.
.
Rev |
Author |
# |
Line |
1 |
perry |
1 |
HSEARCH |
|
|
2 |
!!!HSEARCH |
|
|
3 |
NAME |
|
|
4 |
SYNOPSIS |
|
|
5 |
DESCRIPTION |
|
|
6 |
RETURN VALUE |
|
|
7 |
CONFORMS TO |
|
|
8 |
BUGS |
|
|
9 |
EXAMPLE |
|
|
10 |
SEE ALSO |
|
|
11 |
---- |
|
|
12 |
!!NAME |
|
|
13 |
|
|
|
14 |
|
|
|
15 |
hcreate, hdestroy, hsearch - hash table management |
|
|
16 |
!!SYNOPSIS |
|
|
17 |
|
|
|
18 |
|
|
|
19 |
__#include |
|
|
20 |
__ ''item''__, ACTION__ ''action''__); |
|
|
21 |
int hcreate(unsigned__ ''nel''__); |
|
|
22 |
void hdestroy(void); |
|
|
23 |
__ |
|
|
24 |
!!DESCRIPTION |
|
|
25 |
|
|
|
26 |
|
|
|
27 |
These three functions allow the user to create a hash table |
|
|
28 |
which associates a key with any data. |
|
|
29 |
|
|
|
30 |
|
|
|
31 |
First the table must be created with the function |
|
|
32 |
__hcreate()__. ''nel'' is an estimate of the number of |
|
|
33 |
entries in the table. __hcreate()__ may adjust this value |
|
|
34 |
upward to improve the performance of the resulting hash |
|
|
35 |
table. The GNU implementation of __hsearch()__ will also |
|
|
36 |
enlarge the table if it gets nearly full. malloc(3) |
|
|
37 |
is used to allocate space for the table. |
|
|
38 |
|
|
|
39 |
|
|
|
40 |
The corresponding function __hdestroy()__ frees the |
|
|
41 |
memory occupied by the hash table so that a new table can be |
|
|
42 |
constructed. |
|
|
43 |
|
|
|
44 |
|
|
|
45 |
''item'' is of type __ENTRY__, which is a typedef |
|
|
46 |
defined in '''' and includes these |
|
|
47 |
elements: |
|
|
48 |
|
|
|
49 |
|
|
|
50 |
typedef struct entry |
|
|
51 |
{ |
|
|
52 |
char *''key''; |
|
|
53 |
char *''data''; |
|
|
54 |
} ENTRY; |
|
|
55 |
''key'' points to the zero-terminated ASCII string which is the search key. ''data'' points to the data associated with that key. (A pointer to a type other than character should be cast to pointer-to-character.) __hsearch()__ searches the hash table for an item with the same key as ''item'', and if successful returns a pointer to it. ''action'' determines what __hsearch()__ does after an unsuccessful search. A value of __ENTER__ instructs it to insert the new item, while a value of __FIND__ means to return __NULL__. |
|
|
56 |
!!RETURN VALUE |
|
|
57 |
|
|
|
58 |
|
|
|
59 |
__hcreate()__ returns __NULL__ if the hash table |
|
|
60 |
cannot be successfully installed. |
|
|
61 |
|
|
|
62 |
|
|
|
63 |
__hsearch()__ returns __NULL__ if ''action'' is |
|
|
64 |
__ENTER__ and there is insufficient memory to expand the |
|
|
65 |
hash table, or ''action'' is __FIND__ and ''item'' |
|
|
66 |
cannot be found in the hash table. |
|
|
67 |
!!CONFORMS TO |
|
|
68 |
|
|
|
69 |
|
|
|
70 |
SVID, except that in SysV, the hash table cannot |
|
|
71 |
grow. |
|
|
72 |
!!BUGS |
|
|
73 |
|
|
|
74 |
|
|
|
75 |
The implementation can manage only one hash table at a time. |
|
|
76 |
Individual hash table entries can be added, but not |
|
|
77 |
deleted. |
|
|
78 |
!!EXAMPLE |
|
|
79 |
|
|
|
80 |
|
|
|
81 |
The following program inserts 24 items in to a hash table, |
|
|
82 |
then prints some of them. |
|
|
83 |
|
|
|
84 |
|
|
|
85 |
#include |
|
|
86 |
!!SEE ALSO |
|
|
87 |
|
|
|
88 |
|
|
|
89 |
bsearch(3), lsearch(3), tsearch(3), |
|
|
90 |
malloc(3) |
|
|
91 |
---- |