[ CCode ( cname = "g_str_hash" ) ]
public HashFunc<string> str_hash

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 GenericSet.

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.



a string key


a hash value corresponding to the key

Namespace: GLib
Package: glib-2.0