]> www.ginac.de Git - cln.git/blob - src/base/hash/cl_rcpointer2_hashweak_rcpointer.h
Initial revision
[cln.git] / src / base / hash / cl_rcpointer2_hashweak_rcpointer.h
1 // cl_rcpointer hash tables
2
3 #ifndef _CL_RCPOINTER2_HASHWEAK_RCPOINTER_H
4 #define _CL_RCPOINTER2_HASHWEAK_RCPOINTER_H
5
6 #include "cl_object.h"
7
8 #include "cl_hash2weak.h"
9
10 // Equality.
11 static inline bool equal (const cl_rcpointer& x, const cl_rcpointer& y)
12 { return (x.pointer == y.pointer); }
13
14 // Hash code. Luckily objects don't move around in memory.
15 inline unsigned long hashcode (const cl_rcpointer& x1, const cl_rcpointer& x2)
16 {
17         var unsigned long hashcode1 = (unsigned long)x1.pointer;
18         var unsigned long hashcode2 = (unsigned long)x2.pointer;
19         hashcode2 = (hashcode2 << 5) | (hashcode2 >> (long_bitsize-5)); // rotate
20         return hashcode1 ^ hashcode2;
21 }
22
23 typedef cl_htentry2<cl_rcpointer,cl_rcpointer,cl_rcpointer> cl_htentry_from_rcpointer2_to_rcpointer;
24
25 typedef cl_heap_weak_hashtable_2<cl_rcpointer,cl_rcpointer,cl_rcpointer> cl_heap_weak_hashtable_from_rcpointer2_to_rcpointer;
26
27 typedef _cl_hashtable_iterator<cl_htentry_from_rcpointer2_to_rcpointer> cl_hashtable_from_rcpointer2_to_rcpointer_iterator;
28
29 struct cl_wht_from_rcpointer2_to_rcpointer : public cl_rcpointer {
30         // Constructors.
31         cl_wht_from_rcpointer2_to_rcpointer (cl_boolean (*maygc_htentry) (const cl_htentry_from_rcpointer2_to_rcpointer&));
32         cl_wht_from_rcpointer2_to_rcpointer (const cl_wht_from_rcpointer2_to_rcpointer&);
33         // Assignment operators.
34         cl_wht_from_rcpointer2_to_rcpointer& operator= (const cl_wht_from_rcpointer2_to_rcpointer&);
35         // Iterator.
36         cl_hashtable_from_rcpointer2_to_rcpointer_iterator iterator () const
37         { return ((cl_heap_weak_hashtable_from_rcpointer2_to_rcpointer*)pointer)->iterator(); }
38         // Lookup.
39         cl_rcpointer * get (const cl_rcpointer& x, const cl_rcpointer& y) const;
40         // Store.
41         void put (const cl_rcpointer& x, const cl_rcpointer& y, const cl_rcpointer& z) const;
42 };
43
44 #endif /* _CL_RCPOINTER2_HASHWEAK_RCPOINTER_H */