Answers for "djb2 hash function c explained"

1

djb2 hash function c explained

// Djb2 hash function
unsigned long hash(char *str) 
{

        unsigned long hash = 5381;
        int c;
        while ((c = *str++))
            hash = ((hash << 5) + hash) + c; /* hash * 33 + c */
        return hash % NUM_BUCKETS;

}
Posted by: Guest on May-21-2021
0

djb2 algorithm for C

// Djb2 hash function - really good and implementable code
unsigned long hash(char *str) {

        unsigned long hash = 5381;
        int c;
        while ((c = *str++))
            hash = ((hash << 5) + hash) + c; /* hash * 33 + c */
        return hash % NUM_BUCKETS;

}
Posted by: Guest on October-10-2020

Browse Popular Code Answers by Language