]> www.ginac.de Git - cln.git/blob - src/base/symbol/cl_sy_hashcode.cc
82579ec01906d2af430c623b2fe4d4f8f3ed83fb
[cln.git] / src / base / symbol / cl_sy_hashcode.cc
1 // cl_symbol hashcode().
2
3 // General includes.
4 #include "cl_sysdep.h"
5
6 // Specification.
7 #include "cl_symbol.h"
8
9
10 // Implementation.
11
12 #include "cl_offsetof.h"
13
14 #define declare_alignof(where,type)  \
15   struct CONCAT(aligndummy,__LINE__) { char slot1; type slot2; }; \
16   const unsigned long where = offsetof(CONCAT(aligndummy,__LINE__), slot2);
17
18 unsigned long hashcode (const cl_symbol& s)
19 {
20         // Strings don't move in memory, so we can just take the address.
21         declare_alignof(string_alignment,cl_heap_string);
22         return (unsigned long)(s.pointer)
23                / (string_alignment & -string_alignment); // divide by power of 2
24 }