source: trunk/symbol_table/src/compare_strategy.hpp @ 2092

Last change on this file since 2092 was 2092, checked in by ksherdy, 7 years ago

Refactored id,div2,log2. All tests pass.

File size: 6.2 KB
Line 
1#ifndef COMPARE_STRATEGY_HPP
2#define COMPARE_STRATEGY_HPP
3
4#include "types.hpp"
5
6///////////////////////////////////////////////////////////////////////////////
7// Compare Strategy Interface
8///////////////////////////////////////////////////////////////////////////////
9class icompare_strategy {
10public:
11    static IDISA_ALWAYS_INLINE bool compare(uint8_t * x, uint8_t * y, const uint32_t lgth=0);
12protected:
13    icompare_strategy() {}
14};
15
16///////////////////////////////////////////////////////////////////////////////
17// Length specialized comparison
18///////////////////////////////////////////////////////////////////////////////
19template<uint32_t LGTH, int GROUP_STRATEGY>
20class compare_strategy_t {
21public:
22    static IDISA_ALWAYS_INLINE bool compare(uint8_t * x, uint8_t * y, const uint32_t lgth=0) {
23        return mem_compare(x,y,lgth);
24    }
25};
26
27///////////////////////////////////////////////////////////////////////////////
28// Identity - Default Case - Length 0 specialized for length > 16.
29///////////////////////////////////////////////////////////////////////////////
30template<int GROUP_STRATEGY> class compare_strategy_t<0,GROUP_STRATEGY> {
31public:
32    static IDISA_ALWAYS_INLINE bool compare(uint8_t * x, uint8_t * y, const uint32_t lgth) {
33        //return mem_compare(x,y,lgth); // TODO review
34        return overlap_compare<bitblock128_t>(x,y,lgth);
35    }
36};
37
38template<int GROUP_STRATEGY> class compare_strategy_t<1,GROUP_STRATEGY> {
39public:
40    static IDISA_ALWAYS_INLINE bool compare(uint8_t * x, uint8_t * y, const uint32_t lgth=0) {
41        return overlap_compare<1, uint8_t>(x,y);
42    }
43};
44
45template<int GROUP_STRATEGY> class compare_strategy_t<2,GROUP_STRATEGY> {
46public:
47    static IDISA_ALWAYS_INLINE bool compare(uint8_t * x, uint8_t * y, const uint32_t lgth=0) {
48        return overlap_compare<2, uint16_t>(x,y);
49    }
50};
51
52template<int GROUP_STRATEGY> class compare_strategy_t<3,GROUP_STRATEGY> {
53public:
54    static IDISA_ALWAYS_INLINE bool compare(uint8_t * x, uint8_t * y, const uint32_t lgth=0) {
55        return overlap_compare<3, uint16_t>(x,y);
56    }
57};
58
59template<int GROUP_STRATEGY> class compare_strategy_t<4,GROUP_STRATEGY> {
60public:
61    static IDISA_ALWAYS_INLINE bool compare(uint8_t * x, uint8_t * y, const uint32_t lgth=0) {
62        return overlap_compare<4, uint32_t>(x,y);
63    }
64};
65
66template<int GROUP_STRATEGY> class compare_strategy_t<5,GROUP_STRATEGY> {
67public:
68    static IDISA_ALWAYS_INLINE bool compare(uint8_t * x, uint8_t * y, const uint32_t lgth=0) {
69        return overlap_compare<5, uint32_t>(x,y);
70    }
71};
72
73template<int GROUP_STRATEGY> class compare_strategy_t<6,GROUP_STRATEGY> {
74public:
75    static IDISA_ALWAYS_INLINE bool compare(uint8_t * x, uint8_t * y, const uint32_t lgth=0) {
76        return overlap_compare<6, uint32_t>(x,y);
77    }
78};
79
80template<int GROUP_STRATEGY> class compare_strategy_t<7,GROUP_STRATEGY> {
81public:
82    static IDISA_ALWAYS_INLINE bool compare(uint8_t * x, uint8_t * y, const uint32_t lgth=0) {
83        return overlap_compare<7, uint32_t>(x,y);
84    }
85};
86
87template<int GROUP_STRATEGY> class compare_strategy_t<8,GROUP_STRATEGY> {
88public:
89    static IDISA_ALWAYS_INLINE bool compare(uint8_t * x, uint8_t * y, const uint32_t lgth=0) {
90        return overlap_compare<8, uint64_t>(x,y);
91    }
92};
93
94template<int GROUP_STRATEGY> class compare_strategy_t<9,GROUP_STRATEGY> {
95public:
96    static IDISA_ALWAYS_INLINE bool compare(uint8_t * x, uint8_t * y, const uint32_t lgth=0) {
97        return overlap_compare<9, uint64_t>(x,y);
98    }
99};
100
101template<int GROUP_STRATEGY> class compare_strategy_t<10,GROUP_STRATEGY> {
102public:
103    static IDISA_ALWAYS_INLINE bool compare(uint8_t * x, uint8_t * y, const uint32_t lgth=0) {
104        return overlap_compare<10, uint64_t>(x,y);
105    }
106};
107
108template<int GROUP_STRATEGY> class compare_strategy_t<11,GROUP_STRATEGY> {
109public:
110    static IDISA_ALWAYS_INLINE bool compare(uint8_t * x, uint8_t * y, const uint32_t lgth=0) {
111        return overlap_compare<11, uint64_t>(x,y);
112    }
113};
114
115template<int GROUP_STRATEGY> class compare_strategy_t<12,GROUP_STRATEGY> {
116public:
117    static IDISA_ALWAYS_INLINE bool compare(uint8_t * x, uint8_t * y, const uint32_t lgth=0) {
118        return overlap_compare<12, uint64_t>(x,y);
119    }
120};
121
122template<int GROUP_STRATEGY> class compare_strategy_t<13,GROUP_STRATEGY> {
123public:
124    static IDISA_ALWAYS_INLINE bool compare(uint8_t * x, uint8_t * y, const uint32_t lgth=0) {
125        return overlap_compare<13, uint64_t>(x,y);
126    }
127};
128
129template<int GROUP_STRATEGY> class compare_strategy_t<14,GROUP_STRATEGY> {
130public:
131    static IDISA_ALWAYS_INLINE bool compare(uint8_t * x, uint8_t * y, const uint32_t lgth=0) {
132        return overlap_compare<14, uint64_t>(x,y);
133    }
134};
135
136template<int GROUP_STRATEGY> class compare_strategy_t<15,GROUP_STRATEGY> {
137public:
138    static IDISA_ALWAYS_INLINE bool compare(uint8_t * x, uint8_t * y, const uint32_t lgth=0) {
139        return overlap_compare<15, uint64_t>(x,y);
140    }
141};
142
143template<int GROUP_STRATEGY> class compare_strategy_t<16,GROUP_STRATEGY> {
144public:
145    static IDISA_ALWAYS_INLINE bool compare(uint8_t * x, uint8_t * y, const uint32_t lgth=0) {
146        return overlap_compare<16, bitblock128_t>(x,y);
147    }
148};
149
150template<> class compare_strategy_t<1,logbase2> {
151public:
152    static IDISA_ALWAYS_INLINE bool compare(uint8_t * x, uint8_t * y, const uint32_t lgth) {
153        //return mem_compare(x,y,lgth); // TODO review
154        return overlap_compare<uint8_t>(x,y,lgth);
155    }
156};
157
158template<> class compare_strategy_t<2,logbase2> {
159public:
160    static IDISA_ALWAYS_INLINE bool compare(uint8_t * x, uint8_t * y, const uint32_t lgth) {
161        //return mem_compare(x,y,lgth); // TODO review
162        return overlap_compare<uint8_t>(x,y,lgth);
163    }
164};
165
166template<> class compare_strategy_t<4,logbase2> {
167public:
168    static IDISA_ALWAYS_INLINE bool compare(uint8_t * x, uint8_t * y, const uint32_t lgth) {
169        //return mem_compare(x,y,lgth); // TODO review
170        return overlap_compare<uint16_t>(x,y,lgth);
171    }
172};
173
174template<> class compare_strategy_t<8,logbase2> {
175public:
176    static IDISA_ALWAYS_INLINE bool compare(uint8_t * x, uint8_t * y, const uint32_t lgth) {
177        //return mem_compare(x,y,lgth); // TODO review
178        return overlap_compare<uint32_t>(x,y,lgth);
179    }
180};
181
182template<> class compare_strategy_t<16,logbase2> {
183public:
184    static IDISA_ALWAYS_INLINE bool compare(uint8_t * x, uint8_t * y, const uint32_t lgth) {
185        //return mem_compare(x,y,lgth); // TODO review
186        return overlap_compare<uint64_t>(x,y,lgth);
187    }
188};
189
190#endif // COMPARE_STRATEGY_HPP
Note: See TracBrowser for help on using the repository browser.