### Function

# GLib str_hash

since: 2.0

#### Declaration

    guint
    g_str_hash (
      gconstpointer v
    )

#### Description

Converts a string to a hash value.

This function implements the widely used “djb” hash apparently posted by Daniel Bernstein to comp.lang.c some time ago. The 32 bit unsigned hash value starts at 5381 and for each byte ‘c’ in the string, is updated: `hash = hash * 33 + c`. This function uses the signed value of each byte.

It can be passed to `g_hash_table_new()` as the `hash_func` parameter, when using non-`NULL` strings as keys in a `GHashTable`.

Note that this function may not be a perfect fit for all use cases. For example, it produces some hash collisions with strings as short as 2.

Available since: 2.0

#### Parameters

`v`

  Type: `gconstpointer`

  A string key.

  The data is owned by the caller of the function.

#### Return value

Type: `guint`

A hash value corresponding to the key.