forked from apache/nuttx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearch.h
164 lines (142 loc) · 4.9 KB
/
search.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
/****************************************************************************
* include/search.h
*
* $NetBSD: search.h,v 1.12 1999/02/22 10:34:28 christos Exp $
* $FreeBSD: src/include/search.h,v 1.4 2002/03/23 17:24:53 imp Exp $
*
* Written by J.T. Conklin <jtc@netbsd.org>
* Public domain.
*
****************************************************************************/
#ifndef __INCLUDE_SEARCH_H
#define __INCLUDE_SEARCH_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <sys/types.h>
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/****************************************************************************
* Public Type Definitions
****************************************************************************/
typedef struct entry
{
FAR char *key;
FAR void *data;
} ENTRY;
typedef enum
{
FIND,
ENTER,
DELETE
} ACTION;
struct hsearch_data
{
FAR struct internal_head *htable;
size_t htablesize;
CODE void (*free_entry)(FAR ENTRY *entry);
};
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
/****************************************************************************
* Name: hcreate
*
* Description:
* The hcreate() function creates a new hashing table with nel elements.
* The hashing table will be used by subsequent calls to hsearch() with
* the same htab argument. The hashing table is initialized with nel
* hashing buckets.
*
* The hcreate_r() function is the reentrant version of hcreate().
*
* Returned Value:
* If successful, hcreate() and hcreate_r() return 1; otherwise, they
* return 0.
*
****************************************************************************/
int hcreate(size_t);
/****************************************************************************
* Name: hdestroy
*
* Description:
* The hdestroy() function destroys the hashing table specified by htab.
* The hashing table is destroyed only if there are no entries in the
* table. The hashing table cannot be used again until hcreate() or
* hcreate_r() is called.
*
* The hdestroy_r() function is the reentrant version of hdestroy().
*
* Returned Value:
* None
*
****************************************************************************/
void hdestroy(void);
/****************************************************************************
* Name: hsearch
*
* Description:
* The hsearch() function searches the hashing table specified by htab
* for an entry with a key matching that of item. If such an entry is
* found, hsearch() returns a pointer to the entry's data object. If
* such an entry is not found, hsearch() creates a new entry using the
* key and data objects specified by item and returns a pointer to the
* new entry's data object.
*
* The hsearch_r() function is the reentrant version of hsearch().
*
* Returned Value:
* If successful, hsearch() and hsearch_r() return a pointer to the data
* object of the matching or newly created entry. Otherwise, they return
* NULL.
*
****************************************************************************/
FAR ENTRY *hsearch(ENTRY, ACTION);
/****************************************************************************
* Name: hcreate_r
*
* Description:
* Create a new hash table.
*
* Input Parameters:
* nel - The number of elements in the hash table.
* htab - The location to return the hash table reference.
*
* Returned Value:
* 1 on success; 0 on failure with errno set appropriately.
*
****************************************************************************/
int hcreate_r(size_t, FAR struct hsearch_data *);
/****************************************************************************
* Name: hdestroy_r
*
* Description:
* Destroy a hash table.
*
* Input Parameters:
* htab - The hash table to be destroyed.
*
* Returned Value:
* None
*
****************************************************************************/
void hdestroy_r(FAR struct hsearch_data *);
/****************************************************************************
* Name: hsearch_r
*
* Description:
* Search a hash table.
*
* Input Parameters:
* item - The search key.
* action - The action to take.
* result - The location to return the search result.
* htab - The hash table to be searched.
*
* Returned Value:
* 1 on success; 0 on failure with errno set appropriately.
*
****************************************************************************/
int hsearch_r(ENTRY, ACTION, FAR ENTRY **, FAR struct hsearch_data *);
#endif /* __INCLUDE_SEARCH_H */