xref: /unit/src/nxt_djb_hash.h (revision 2084:7d479274f334)
1 
2 /*
3  * Copyright (C) Igor Sysoev
4  * Copyright (C) NGINX, Inc.
5  */
6 
7 #ifndef _NXT_DJB_HASH_H_INCLUDED_
8 #define _NXT_DJB_HASH_H_INCLUDED_
9 
10 
11 /* A fast and simple hash function by Daniel J. Bernstein. */
12 
13 
14 NXT_EXPORT uint32_t nxt_djb_hash(const void *data, size_t len);
15 NXT_EXPORT uint32_t nxt_djb_hash_lowcase(const void *data, size_t len);
16 
17 
18 #define NXT_DJB_HASH_INIT  5381
19 
20 
21 #define nxt_djb_hash_add(hash, val)                                           \
22     ((uint32_t) ((((hash) << 5) + (hash)) ^ (uint32_t) (val)))
23 
24 
25 #endif /* _NXT_DJB_HASH_H_INCLUDED_ */
26