---
name: "globus_hashtable"
section: "3"
platform: "linux"
package: "libglobus-common-doc"
version: "18.14-3"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/globus_hashtable"
---

# globus\_hashtable(3)

Hash Table - Hash Table.

## NAME

globus\_hashtable - Hash Table

 \- Hash Table.

## SYNOPSIS

### Modules

**Iterators**\
 Iterators.

### Typedefs

typedef int(\* **globus\_hashtable\_hash\_func\_t**) (void \*key, int limit)\
 typedef int(\* **globus\_hashtable\_keyeq\_func\_t**) (void \*key1, void \*key2)\
 typedef void(\* **globus\_hashtable\_copy\_func\_t**) (void \*\*dest\_key, void \*\*dest\_datum, void \*src\_key, void \*src\_datum)\
 typedef void(\* **globus\_hashtable\_destructor\_func\_t**) (void \*datum)\

### Functions

int **globus\_hashtable\_init** (globus\_hashtable\_t \*table, int size, **globus\_hashtable\_hash\_func\_t** hash\_func, **globus\_hashtable\_keyeq\_func\_t** keyeq\_func)\
 Initialize a hash table.  int **globus\_hashtable\_insert** (globus\_hashtable\_t \*table, void \*key, void \*datum)\
 Insert a datum into a hash table.  void \* **globus\_hashtable\_update** (globus\_hashtable\_t \*table, void \*key, void \*datum)\
 Update a hash table mapping.  void \* **globus\_hashtable\_lookup** (globus\_hashtable\_t \*table, void \*key)\
 Look up a datum in a hash table.  void \* **globus\_hashtable\_remove** (globus\_hashtable\_t \*table, void \*key)\
 Remove a datum from a hash table.  int **globus\_hashtable\_to\_list** (globus\_hashtable\_t \*table, **globus\_list\_t** \*\*list)\
 Create a list of all datums in a hash table.  **globus\_bool\_t** **globus\_hashtable\_empty** (globus\_hashtable\_t \*table)\
 Test hash table emptiness.  int **globus\_hashtable\_size** (globus\_hashtable\_t \*table)\
 Hash table size.  int **globus\_hashtable\_destroy** (globus\_hashtable\_t \*table)\
 Destroy a hash table

Destroys a hashtable representation, releasing any resources used to represent the mappings (abandoning any data in the queue). After this call, a hashtable is no longer considered initialized. " int **globus\_hashtable\_string\_hash** (void \*string, int limit)\
 Null-terminated string hash function.  int **globus\_hashtable\_string\_keyeq** (void \*string1, void \*string2)\
 Null-terminated string equality predicate.  int **globus\_hashtable\_voidp\_hash** (void \*voidp, int limit)\
 Void pointer hash function.  int **globus\_hashtable\_voidp\_keyeq** (void \*voidp1, void \*voidp2)\
 Void pointer equality predicate.  int **globus\_hashtable\_int\_hash** (void \*integer, int limit)\
 Integer hash function.  int **globus\_hashtable\_int\_keyeq** (void \*integer1, void \*integer2)\
 Integer equality predicate.

## Detailed Description

Hash Table.

The globus\_hashtable data type provides an abstract hashtable mapping representation and operations on such mappings. These queues can contain arbitrary data in the form of a void pointer for each key and a void pointer for each datum. It is the user's responsibility to provide and interpret keys and data of the correct type.

## Typedef Documentation

### typedef void(\* globus\_hashtable\_copy\_func\_t) (void \*\*dest\_key, void \*\*dest\_datum, void \*src\_key, void \*src\_datum)

datum copy func

### typedef void(\* globus\_hashtable\_destructor\_func\_t) (void \*datum)

Destructor callback for use with globus\_hashtable\_destroy\_all

### typedef int(\* globus\_hashtable\_hash\_func\_t) (void \*key, int limit)

An anonymous hash function providing an onto mapping of (key, limit) pairs to integers, where the result integer is in the range \[ 0, limit - 1 \] .

- •

  Note that as a proper function, such hash routines must always compute the same result given the same key and limit value.

**Parameters**

*key* Value to map \
 *limit* Map range limit

**Returns**

Integer hash value of key

### typedef int(\* globus\_hashtable\_keyeq\_func\_t) (void \*key1, void \*key2)

An anonymous predicate that returns true when the keys are equal and false otherwise. Truth and falsity are represented by non-zero and zero (0) integers for use directly in C language conditionals.

## Function Documentation

### int globus\_hashtable\_destroy (globus\_hashtable\_t \* table)

Destroy a hash table

Destroys a hashtable representation, releasing any resources used to represent the mappings (abandoning any data in the queue). After this call, a hashtable is no longer considered initialized. It is an error to destroy a hashtable that is not initialized.

**Parameters**

*table* Hash table to destroy.

### globus\_bool\_t globus\_hashtable\_empty (globus\_hashtable\_t \* table)

Test hash table emptiness.

**Returns**

GLOBUS\_TRUE if hashtable is empty, GLOBUS\_FALSE otherwise

### int globus\_hashtable\_init (globus\_hashtable\_t \* table, int size, globus\_hashtable\_hash\_func\_t hash\_func, globus\_hashtable\_keyeq\_func\_t keyeq\_func)

Initialize a hash table. Initializes a generic chaining hashtable to represent an empty mapping and returns zero, or returns non-zero on failure. The size parameter specifies the number of chains with which to represent the mapping. This defines the maximum possible number of mappings that can be represented without conflict given a perfect hash, and therefore affects performance as hash conflicts will be resolved by linear chains.

The hash\_func and keyeq\_func anonymous functions will be used by the table to manipulate the user's keys.

### int globus\_hashtable\_insert (globus\_hashtable\_t \* table, void \* key, void \* datum)

Insert a datum into a hash table. The routine globus\_hashtable\_insert adds a new mapping to the table, returning zero on success or non-zero on failure. Any previous mapping for the same key (where equality is defined by the keyeq\_func provided at table initialization) is lost.

It is an error to call this routine on an uninitialized table.

### int globus\_hashtable\_int\_hash (void \* integer, int limit)

Integer hash function. A pathetic hash function for integers, calculating the index as the remainder of dividing the integer by the table size.

Your pet gerbil could probably design a better hash function for your integer keys, but you might as well use this one if you were going to use modular division anyway.

### void \* globus\_hashtable\_lookup (globus\_hashtable\_t \* table, void \* key)

Look up a datum in a hash table. The globus\_hashtable\_lookup routine returns the datum mapped to the given key in the table, or NULL if the key is not mapped.

It is an error to call this routine on an uninitialized or empty table.

### void \* globus\_hashtable\_remove (globus\_hashtable\_t \* table, void \* key)

Remove a datum from a hash table. The **globus\_hashtable\_remove()** function removes the mapping of key in the table, or does nothing if no such mapping exists.

It is an error to call this routine on an uninitialized or empty table.

### int globus\_hashtable\_size (globus\_hashtable\_t \* table)

Hash table size.

**Returns**

Number of entries in hashtable

### int globus\_hashtable\_string\_hash (void \* string, int limit)

Null-terminated string hash function. A decent hash function for null-terminated character arrays.

### void \* globus\_hashtable\_update (globus\_hashtable\_t \* table, void \* key, void \* datum)

Update a hash table mapping. Update an existing key -\> datum association with new values for both, key and datum. The old datum is returned. If key is non-scalar (eg, string), it should be part of datum so its resources may be recovered. If old key does not exist, NULL is returned.

### int globus\_hashtable\_voidp\_hash (void \* voidp, int limit)

Void pointer hash function. A decent hash function for void pointers. This routine goes to some effort to distribute the information from the address into the hash index by XORing the upper and lower halves of the pointer into one accumulator and calculating the index as the remainder of dividing the accumulator by the table size.

## Author

Generated automatically by Doxygen for globus\_common from the source code.
