767347456c47a4a372b23afb53bda245ff1cf3b4
[satune.git] / src / Collections / structs.cc
1 #include "mymemory.h"
2 #include "orderpair.h"
3 #include "tableentry.h"
4 #include "ordernode.h"
5 #include "orderedge.h"
6 #include "ordergraph.h"
7 #include "orderelement.h"
8 #include "structs.h"
9 #include "decomposeorderresolver.h"
10
11 #define HASHNEXT(hash, newval) {hash += newval; hash += hash << 10; hash ^= hash >> 6;}
12 #define HASHFINAL(hash) {hash += hash << 3; hash ^= hash >> 11; hash += hash << 15;}
13
14 unsigned int table_entry_hash_function(TableEntry *This) {
15         unsigned int h = 0;
16         for (uint i = 0; i < This->inputSize; i++) {
17                 HASHNEXT(h, This->inputs[i]);
18         }
19         HASHFINAL(h);
20         return h;
21 }
22
23 bool table_entry_equals(TableEntry *key1, TableEntry *key2) {
24         if (key1->inputSize != key2->inputSize)
25                 return false;
26         for (uint i = 0; i < key1->inputSize; i++)
27                 if (key1->inputs[i] != key2->inputs[i])
28                         return false;
29         return true;
30 }
31
32 unsigned int order_node_hash_function(OrderNodeKey *This) {
33         return (uint) This->id;
34 }
35
36 bool order_node_equals(OrderNodeKey *key1, OrderNodeKey *key2) {
37         return key1->id == key2->id;
38 }
39
40 unsigned int order_edge_hash_function(OrderEdge *This) {
41         uint hash = 0;
42         HASHNEXT(hash, (uint)(uintptr_t) This->sink);
43         HASHNEXT(hash, (uint)(uintptr_t) This->source);
44         HASHFINAL(hash);
45         return hash;
46 }
47
48 bool order_edge_equals(OrderEdge *key1, OrderEdge *key2) {
49         return key1->sink == key2->sink && key1->source == key2->source;
50 }
51
52 unsigned int order_element_hash_function(OrderElement *This) {
53         return This->getHash();
54 }
55
56 bool order_element_equals(OrderElement *key1, OrderElement *key2) {
57         return key1->equals(key2);
58 }
59
60 unsigned int order_pair_hash_function(OrderPair *This) {
61         uint hash = 0;
62         HASHNEXT(hash, This->first);
63         HASHNEXT(hash, This->second);
64         HASHFINAL(hash);
65         return hash;
66 }
67
68 bool order_pair_equals(OrderPair *key1, OrderPair *key2) {
69         return key1->first == key2->first && key1->second == key2->second;
70 }
71
72 unsigned int doredge_hash_function(DOREdge *key) {
73         uint hash = 0;
74         HASHNEXT(hash, (uint) key->newfirst);
75         HASHNEXT(hash, (uint) key->newsecond);
76         HASHFINAL(hash);
77         return hash;
78 }
79
80 bool doredge_equals(DOREdge *key1, DOREdge *key2) {
81         return key1->newfirst == key2->newfirst &&
82                                  key1->newsecond == key2->newsecond;
83 }