Implementing CDB hash in PHP

The CDB (Constant Database) got a really cool and simple hash function, what I'm trying to do, is implementing CDB hash function in PHP script. There are interesting explanation from here and here.

According to the author, the hash function is:

h = ((h << 5) + h) ^ c
function cdb_hash( $s )
{
    $h = 5381; //magic
    for( $i = 0, $len = strlen($s); $i<$len; $i++ )
    {
        $h = ((($h << 5) + $h) ^ ord($s{$i})) & 0xFFFFFFFF;
    }
    return $h;
}

0 Comments

Leave a Reply

eleven subtract by four is equal hint: use google ;)