]> mj.ucw.cz Git - libucw.git/blob - lib/hashfunc.h
CONST attribute of functions noted in a better place
[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
8 #ifndef _SHERLOCK_HASHFUNC_H
9 #define _SHERLOCK_HASHFUNC_H
10
11 #include "lib/lib.h"
12
13 /* An equivalent of the Intel's rol instruction.  */
14 #define ROL(x, bits)    (((x) << (bits)) | ((x) >> (sizeof(uns)*8 - (bits))))
15
16 /* The following functions need str to be aligned to uns.  */
17 uns str_len_aligned(const byte *str) CONST;
18 uns hash_string_aligned(const byte *str) CONST;
19 uns hash_block_aligned(const byte *str, uns len) CONST;
20
21 #ifdef  CPU_ALLOW_UNALIGNED
22 #define str_len(str)            str_len_aligned(str)
23 #define hash_string(str)        hash_string_aligned(str)
24 #define hash_block(str, len)    hash_block_aligned(str, len)
25 #else
26 uns str_len(const byte *str) CONST;
27 uns hash_string(const byte *str) CONST;
28 uns hash_block(const byte *str, uns len) CONST;
29 #endif
30
31 uns hash_string_nocase(const byte *str) CONST;
32
33 static inline uns CONST hash_int(uns x) { return 6442450967*x; }
34
35 #endif