]> www.ginac.de Git - cln.git/blob - src/integer/hash/cl_I_hashcode.cc
Use paths relative the `src' directory in the #include directives.
[cln.git] / src / integer / hash / cl_I_hashcode.cc
1 // cl_I hashcode().
2
3 // General includes.
4 #include "base/cl_sysdep.h"
5
6 // Specification.
7 #include "integer/cl_I.h"
8
9
10 // Implementation.
11
12 namespace cln {
13
14 unsigned long hashcode (const cl_I& x)
15 {
16         var unsigned long code = 0x814BE3A5;
17         // We walk through all limbs. It may take some time for very large
18         // integers, but it's better than completely ignoring some limbs.
19         if (fixnump(x)) {
20                 #if (cl_value_len <= intLsize)
21                 code += FN_to_V(x);
22                 #elif (cl_word_size==64)
23                 code += FN_to_Q(x);
24                 code ^= (code >> 32);
25                 #endif
26                 code &= 0xFFFFFFFF;
27         } else {
28                 var const uintD* MSDptr;
29                 var uintC len;
30                 BN_to_NDS_nocopy(x, MSDptr=,len=,);
31                 for (; len > 0; len--) {
32                         var uintD c = msprefnext(MSDptr);
33                         code = (code << 5) | (code >> 27); // rotate left 5 bits
34                         code += (long)c << 16;
35                         code ^= (long)c;
36                         code &= 0xFFFFFFFF;
37                 }
38         }
39         return code;
40 }
41
42 }  // namespace cln