summaryrefslogtreecommitdiff
path: root/os/src/hash-djb2.c
blob: 82dd7410076075be08d62a7cce4a3c0f2765606a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <stdint.h>
#include "hash-djb2.h"
#include "osdebug.h"

uint32_t hash_djb2(const uint8_t * str, ssize_t _max) {
    uint32_t hash = 5381;
    uint32_t max = (uint32_t) _max;
    int c;
    
    while (((c = *str++)) && max--) {
        hash = ((hash << 5) + hash) ^ c;
    }
    
    return hash;
}