FreeBSD/sys/kern/subr_witness.c
/*
 * A simple hash function. Takes a key pointer and a key size. If size == 0,
 * interprets the key as a string and reads until the null
 * terminator. Otherwise, reads the first size bytes. Returns an unsigned 32-bit
 * hash value computed from the key.
 */
A simple hash function. Takes a key pointer and a key size. If size == 0,
interprets the key as a string and reads until the null
terminator. Otherwise, reads the first size bytes. Returns an unsigned 32-bit
hash value computed from the key.
A simple hash function . Takes a key pointer and a key size . If size == 0 interprets the key as a string and reads until the null terminator . Otherwise reads the first size bytes . Returns an unsigned 32 - bit hash value computed from the key .
static uint32_t
witness_hash_djb2(const uint8_t *key, uint32_t size)
{
	unsigned int hash = 5381;
	int i;
	if (size)
		for (i = 0; i < size; i++)
			hash = ((hash << 5) + hash) + (unsigned int)key[i];
	else
		for (i = 0; key[i] != 0; i++)
			hash = ((hash << 5) + hash) + (unsigned int)key[i];
	return (hash);
}
static uint32_t witness_hash_djb2 ( const uint8_t * key , uint32_t size ) { unsigned int hash = 5381 ; int i ; if ( size ) for ( i = 0 ; i < size ; i ++ ) hash = ( ( hash << 5 ) + hash ) + ( unsigned int ) key [ i ] ; else for ( i = 0 ; key [ i ] != 0 ; i ++ ) hash = ( ( hash << 5 ) + hash ) + ( unsigned int ) key [ i ] ; return ( hash ) ; }
A simple hash function.
A simple hash function .
/* hash = hash * 33 + key[i] */