Library Version 12.1.6.2

Db::set_h_hash()
Prev | Chapter 2. The Db Handle | Next

## Db::set_h_hash()

    #include <db_cxx.h>

    extern "C" {
        typedef u_int32_t (*h_hash_fcn_type)
    	(DB *, const void *bytes, u_int32_t length);
    };
    int
    Db::set_h_hash(h_hash_fcn_type h_hash_fcn);

Set a user-defined hash function; if no hash function is specified, a default hash function is used. Because no hash function performs equally well on all possible data, the user may find that the built-in hash function performs poorly with a particular data set.

The `Db::set_h_hash()` method configures operations performed using the specified Db handle, not all operations performed on the underlying database.

The `Db::set_h_hash()` method may not be called after the Db::open() method is called. If the database already exists when Db::open() is called, the information specified to `Db::set_h_hash()` must be the same as that historically used to create the database or corruption can occur.

The `Db::set_h_hash()` method either returns a non-zero error value or throws an exception that encapsulates a non-zero error value on failure, and returns 0 on success.

### Parameters

#### h_hash_fcn

The h_hash_fcn parameter is the application-specified hash function.

Application-specified hash functions take a pointer to a byte string and a length as parameters, and return a value of type u_int32_t. The hash function must handle any key values used by the application (possibly including zero-length keys).

### Errors

The `Db::set_h_hash()` method may fail and throw a DbException exception, encapsulating one of the following non-zero errors, or return one of the following non-zero errors:

#### EINVAL

If the method was called after Db::open() was called; or if an invalid flag value or parameter was specified.

### Class

Db

### See Also

Database and Related Methods

Prev | Up | Next
Db::set_h_ffactor() | Home | Db::set_h_nelem()