|
@@ -59,11 +59,6 @@
|
|
* [Knuth] The Art of Computer Programming, part 3 (6.4)
|
|
* [Knuth] The Art of Computer Programming, part 3 (6.4)
|
|
*/
|
|
*/
|
|
|
|
|
|
-/*
|
|
|
|
- * The non-reentrant version use a global space for storing the hash table.
|
|
|
|
- */
|
|
|
|
-static struct hsearch_data htab;
|
|
|
|
-
|
|
|
|
/*
|
|
/*
|
|
* The reentrant version has no static variables to maintain the state.
|
|
* The reentrant version has no static variables to maintain the state.
|
|
* Instead the interface of all functions is extended to take an argument
|
|
* Instead the interface of all functions is extended to take an argument
|
|
@@ -97,11 +92,6 @@ static int isprime(unsigned int number)
|
|
return number % div != 0;
|
|
return number % div != 0;
|
|
}
|
|
}
|
|
|
|
|
|
-int hcreate(size_t nel)
|
|
|
|
-{
|
|
|
|
- return hcreate_r(nel, &htab);
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
/*
|
|
/*
|
|
* Before using the hash table we must allocate memory for it.
|
|
* Before using the hash table we must allocate memory for it.
|
|
* Test for an existing table are done. We allocate one element
|
|
* Test for an existing table are done. We allocate one element
|
|
@@ -110,6 +100,7 @@ int hcreate(size_t nel)
|
|
* The contents of the table is zeroed, especially the field used
|
|
* The contents of the table is zeroed, especially the field used
|
|
* becomes zero.
|
|
* becomes zero.
|
|
*/
|
|
*/
|
|
|
|
+
|
|
int hcreate_r(size_t nel, struct hsearch_data *htab)
|
|
int hcreate_r(size_t nel, struct hsearch_data *htab)
|
|
{
|
|
{
|
|
/* Test for correct arguments. */
|
|
/* Test for correct arguments. */
|
|
@@ -143,15 +134,12 @@ int hcreate_r(size_t nel, struct hsearch_data *htab)
|
|
/*
|
|
/*
|
|
* hdestroy()
|
|
* hdestroy()
|
|
*/
|
|
*/
|
|
-void hdestroy(void)
|
|
|
|
-{
|
|
|
|
- hdestroy_r(&htab);
|
|
|
|
-}
|
|
|
|
|
|
|
|
/*
|
|
/*
|
|
* After using the hash table it has to be destroyed. The used memory can
|
|
* After using the hash table it has to be destroyed. The used memory can
|
|
* be freed and the local static variable can be marked as not used.
|
|
* be freed and the local static variable can be marked as not used.
|
|
*/
|
|
*/
|
|
|
|
+
|
|
void hdestroy_r(struct hsearch_data *htab)
|
|
void hdestroy_r(struct hsearch_data *htab)
|
|
{
|
|
{
|
|
int i;
|
|
int i;
|
|
@@ -214,15 +202,6 @@ void hdestroy_r(struct hsearch_data *htab)
|
|
* example for functions like hdelete().
|
|
* example for functions like hdelete().
|
|
*/
|
|
*/
|
|
|
|
|
|
-ENTRY *hsearch(ENTRY item, ACTION action)
|
|
|
|
-{
|
|
|
|
- ENTRY *result;
|
|
|
|
-
|
|
|
|
- (void) hsearch_r(item, action, &result, &htab);
|
|
|
|
-
|
|
|
|
- return result;
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
int hsearch_r(ENTRY item, ACTION action, ENTRY ** retval,
|
|
int hsearch_r(ENTRY item, ACTION action, ENTRY ** retval,
|
|
struct hsearch_data *htab)
|
|
struct hsearch_data *htab)
|
|
{
|
|
{
|
|
@@ -369,11 +348,6 @@ int hsearch_r(ENTRY item, ACTION action, ENTRY ** retval,
|
|
* do that.
|
|
* do that.
|
|
*/
|
|
*/
|
|
|
|
|
|
-int hdelete(const char *key)
|
|
|
|
-{
|
|
|
|
- return hdelete_r(key, &htab);
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
int hdelete_r(const char *key, struct hsearch_data *htab)
|
|
int hdelete_r(const char *key, struct hsearch_data *htab)
|
|
{
|
|
{
|
|
ENTRY e, *ep;
|
|
ENTRY e, *ep;
|
|
@@ -442,11 +416,6 @@ int hdelete_r(const char *key, struct hsearch_data *htab)
|
|
* bytes in the string will be '\0'-padded.
|
|
* bytes in the string will be '\0'-padded.
|
|
*/
|
|
*/
|
|
|
|
|
|
-ssize_t hexport(const char sep, char **resp, size_t size)
|
|
|
|
-{
|
|
|
|
- return hexport_r(&htab, sep, resp, size);
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
static int cmpkey(const void *p1, const void *p2)
|
|
static int cmpkey(const void *p1, const void *p2)
|
|
{
|
|
{
|
|
ENTRY *e1 = *(ENTRY **) p1;
|
|
ENTRY *e1 = *(ENTRY **) p1;
|
|
@@ -605,11 +574,6 @@ ssize_t hexport_r(struct hsearch_data *htab, const char sep,
|
|
* '\0' and '\n' have really been tested.
|
|
* '\0' and '\n' have really been tested.
|
|
*/
|
|
*/
|
|
|
|
|
|
-int himport(const char *env, size_t size, const char sep, int flag)
|
|
|
|
-{
|
|
|
|
- return himport_r(&htab, env, size, sep, flag);
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
int himport_r(struct hsearch_data *htab,
|
|
int himport_r(struct hsearch_data *htab,
|
|
const char *env, size_t size, const char sep, int flag)
|
|
const char *env, size_t size, const char sep, int flag)
|
|
{
|
|
{
|