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

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

Updated symbol table to represent group 0 as the arbitrary length group.

File size: 6.5 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
150///////////////////////////////////////////////////////////////////////////////
151// Log base 2 specialized
152///////////////////////////////////////////////////////////////////////////////
153template<> class compare_strategy_t<1,logbase2> {
154public:
155    static IDISA_ALWAYS_INLINE bool compare(uint8_t * x, uint8_t * y, const uint32_t lgth) {
156        return overlap_compare<uint8_t>(x,y,lgth);
157    }
158};
159
160template<> class compare_strategy_t<2,logbase2> {
161public:
162    static IDISA_ALWAYS_INLINE bool compare(uint8_t * x, uint8_t * y, const uint32_t lgth) {
163        return overlap_compare<uint8_t>(x,y,lgth);
164    }
165};
166
167template<> class compare_strategy_t<4,logbase2> {
168public:
169    static IDISA_ALWAYS_INLINE bool compare(uint8_t * x, uint8_t * y, const uint32_t lgth) {
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 overlap_compare<uint32_t>(x,y,lgth);
178    }
179};
180
181template<> class compare_strategy_t<16,logbase2> {
182public:
183    static IDISA_ALWAYS_INLINE bool compare(uint8_t * x, uint8_t * y, const uint32_t lgth) {
184        return overlap_compare<uint64_t>(x,y,lgth);
185    }
186};
187
188///////////////////////////////////////////////////////////////////////////////
189// Single specialized
190///////////////////////////////////////////////////////////////////////////////
191template<> class compare_strategy_t<0,single> {
192public:
193    static IDISA_ALWAYS_INLINE bool compare(uint8_t * x, uint8_t * y, const uint32_t lgth) {
194        return overlap_compare<uint8_t>(x,y,lgth);
195    }
196};
197
198#endif // COMPARE_STRATEGY_HPP
Note: See TracBrowser for help on using the repository browser.