00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef CU_HASH_H
00019 #define CU_HASH_H
00020
00021 #include <cu/fwd.h>
00022 #include <cu/conf.h>
00023
00024 CU_BEGIN_DECLARATIONS
00025
00026 #define CUPRIV_PRIME32A 4212831859U
00027 #define CUPRIV_PRIME32B 2909797907U
00028 #define CUPRIV_PRIME16A 493643U
00029 #define CUPRIV_PRIME16B 382769U
00030 #if CUCONF_SIZEOF_CU_HASH_T > 4
00031 # define CUPRIV_PRIME_HA CUPRIV_PRIME32A
00032 # define CUPRIV_PRIME_HB CUPRIV_PRIME32B
00033 #else
00034 # define CUPRIV_PRIME_HA CUPRIV_PRIME16A
00035 # define CUPRIV_PRIME_HB CUPRIV_PRIME16B
00036 #endif
00037
00038 CU_SINLINE cu_hash_t cu_hash_mix3(cu_hash_t key)
00039 { return (key ^ (key >> 7)) - ((key >> 11) ^ (key >> 19)); }
00040
00041 CU_SINLINE cu_hash_t cu_hash_mix4(cu_hash_t key)
00042 { return (key >> 7) + ((key >> 11) ^ (key >> 19)) + key*1030739; }
00043
00044 CU_SINLINE cu_hash_t cu_hash_mix5(cu_hash_t key)
00045 {
00046 key *= CUPRIV_PRIME_HA;
00047 key ^= key >> sizeof(cu_hash_t)*4;
00048 return key;
00049 }
00050 CU_SINLINE cu_hash_t cu_hash_mix6(cu_hash_t key)
00051 {
00052 key *= CUPRIV_PRIME_HA;
00053 key ^= key >> sizeof(cu_hash_t)*4;
00054 key ^= key >> sizeof(cu_hash_t)*2;
00055 return key;
00056 }
00057
00058 CU_SINLINE cu_hash_t
00059 cu_hash_rot(cu_hash_t x, int k)
00060 {
00061 return (x << k) | (x >> (8*sizeof(cu_hash_t) - k));
00062 }
00063
00064 #define cu_hash_mix cu_hash_mix5
00065
00066 cu_hash_t cu_wordarr_hash_bj(size_t cnt, cu_word_t const *arr, cu_hash_t init);
00067 cu_hash_t cu_1word_hash_bj(cu_word_t d0, cu_hash_t init);
00068 cu_hash_t cu_2word_hash_bj(cu_word_t d0, cu_word_t d1, cu_hash_t init);
00069
00070 cu_hash_t cu_wordarr_hash_noinit_bj(size_t count, cu_word_t const *arr);
00071 cu_hash_t cu_1word_hash_noinit_bj(cu_word_t d0);
00072 cu_hash_t cu_2word_hash_noinit_bj(cu_word_t d0, cu_word_t d1);
00073
00074 CU_END_DECLARATIONS
00075
00076 #endif