Daniel J. Bernstein

by 0deson 7/5/2022, 6:32 PMwith 2 comments

by 0deson 7/5/2022, 8:59 PM

> djb2

> this algorithm (k=33) was first reported by dan bernstein many years ago in comp.lang.c. another version of this algorithm (now favored by bernstein) uses xor: hash(i) = hash(i - 1) * 33 ^ str[i]; the magic of number 33 (why it works better than many other constants, prime or not) has never been adequately explained.

    unsigned long
    hash(unsigned char *str)
    {
        unsigned long hash = 5381;
        int c;

        while (c = *str++)
            hash = ((hash << 5) + hash) + c; /* hash * 33 + c */

        return hash;
    }
source: http://www.cse.yorku.ca/~oz/hash.html

by tunapon 7/5/2022, 7:37 PM

"Hopes and fears draw in bold strokes, while knowledge advances by small increments & contradictory witnesses."

His are some of my favorite history books. The Discoverers is a great read, but you could just as easily thumb through and just pick a subject to learn about it's origins... it is a long, history of nearly everything(1). I also highly recommend "The Scene". An oldie but a goodie... so, so far ahead of it's time.

(1)Bryson appears to be a fan, too, as he cites DJB twice in his "At Home" book.