-
Notifications
You must be signed in to change notification settings - Fork 1
/
mortoncompare.h
56 lines (44 loc) · 1.4 KB
/
mortoncompare.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#ifndef _MORTONCOMPARE_H_
#define _MORTONCOMPARE_H_
template <class ITYPE>
class MortonCompare: public binary_function< ITYPE , ITYPE , bool > // (par1, par2, return_type)
{
public:
MortonCompare() {}
MortonCompare (ITYPE nrbits, ITYPE ncbits, ITYPE rmask, ITYPE cmask )
: nrowbits(nrbits), ncolbits(ncbits), rowmask(rmask), colmask(cmask) {}
// rhs is the splitter that is already in bit-interleaved order
// lhs is the actual value that is in row-major order
bool operator()(const ITYPE & lhs, const ITYPE & rhs) const
{
ITYPE rlowbits = ((lhs >> ncolbits) & rowmask);
ITYPE clowbits = (lhs & colmask);
ITYPE bikey = BitInterleaveLow(rlowbits, clowbits);
return bikey < rhs;
}
private:
ITYPE nrowbits;
ITYPE ncolbits;
ITYPE rowmask;
ITYPE colmask;
};
template <class ITYPE>
class MortCompSym: public binary_function< ITYPE , ITYPE , bool > // (par1, par2, return_type)
{
public:
MortCompSym() {}
MortCompSym(ITYPE bits, ITYPE lowmask): nbits(bits), lmask(lowmask) {}
// rhs is the splitter that is already in bit-interleaved order
// lhs is the actual value that is in row-major order
bool operator()(const ITYPE & lhs, const ITYPE & rhs) const
{
ITYPE rlowbits = ((lhs >> nbits) & lmask);
ITYPE clowbits = (lhs & lmask);
ITYPE bikey = BitInterleaveLow(rlowbits, clowbits);
return bikey < rhs;
}
private:
ITYPE nbits;
ITYPE lmask;
};
#endif