]> mj.ucw.cz Git - libucw.git/blob - lib/hashfunc.h
Added license notices to all library files which are not specific
[libucw.git] / lib / hashfunc.h
1 /*
2  *      Hyper-super-meta-alt-control-shift extra fast str_len() and hash_*()
3  *      routines
4  *
5  *      (c) 2002, Robert Spalek <robert@ucw.cz>
6  *
7  *      This software may be freely distributed and used according to the terms
8  *      of the GNU Lesser General Public License.
9  */
10
11 #ifndef _SHERLOCK_HASHFUNC_H
12 #define _SHERLOCK_HASHFUNC_H
13
14 #include "lib/lib.h"
15
16 /* An equivalent of the Intel's rol instruction.  */
17 #define ROL(x, bits)    (((x) << (bits)) | ((x) >> (sizeof(uns)*8 - (bits))))
18
19 /* The following functions need str to be aligned to uns.  */
20 uns str_len_aligned(const byte *str) CONST;
21 uns hash_string_aligned(const byte *str) CONST;
22 uns hash_block_aligned(const byte *str, uns len) CONST;
23
24 #ifdef  CPU_ALLOW_UNALIGNED
25 #define str_len(str)            str_len_aligned(str)
26 #define hash_string(str)        hash_string_aligned(str)
27 #define hash_block(str, len)    hash_block_aligned(str, len)
28 #else
29 uns str_len(const byte *str) CONST;
30 uns hash_string(const byte *str) CONST;
31 uns hash_block(const byte *str, uns len) CONST;
32 #endif
33
34 uns hash_string_nocase(const byte *str) CONST;
35
36 static inline uns CONST hash_int(uns x) { return 6442450967*x; }
37
38 #endif