forked from MrAlexSee/sopang
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sopang.hpp
78 lines (59 loc) · 2.34 KB
/
sopang.hpp
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#ifndef SOPANG_HPP
#define SOPANG_HPP
#include <map>
#include <string>
#include <unordered_set>
#include <vector>
#ifndef SOPANG_WHITEBOX
#define SOPANG_WHITEBOX
#endif
namespace sopang
{
class Sopang
{
public:
Sopang();
~Sopang();
/*
*** PARSING
*/
static const std::string *const *parseTextArray(std::string text, unsigned *nSegments, unsigned **segmentSizes);
static std::vector<std::string> parsePatterns(std::string patternsStr);
/*
*** MATCHING
*/
std::unordered_set<unsigned> match(const std::string *const *segments,
unsigned nSegments, const unsigned *segmentSizes,
const std::string &pattern, const std::string &alphabet);
std::unordered_set<unsigned> matchApprox(const std::string *const *segments,
unsigned nSegments, const unsigned *segmentSizes,
const std::string &pattern, const std::string &alphabet,
unsigned k);
private:
void initCounterPositionMasks();
void fillPatternMaskBuffer(const std::string &pattern, const std::string &alphabet);
void fillPatternMaskBufferApprox(const std::string &pattern, const std::string &alphabet);
/** Buffer size for processing segment variants, the size of the largest segment (i.e. the number of variants)
* from the input file cannot be larger than this value. */
static constexpr unsigned dBufferSize = 262144;
/** Buffer size for Shift-Or masks for the input alphabet, must be larger than the largest input character ASCII code,
* up to 'Z' = 90. */
static constexpr unsigned maskBufferSize = 91;
/** Word size (in bits) used by the Shift-Or algorithm. */
static constexpr unsigned wordSize = 64;
/** Shift-Add counter size in bits. */
static constexpr unsigned saCounterSize = 5;
/** Maximum pattern size for approximate search. */
static constexpr unsigned maxPatternApproxSize = 12;
/** Full single Shift-Add counter indicating no match. */
static constexpr uint64_t saFullCounter = 0x10ULL;
/** Single Shift-Add counter with all bits set. */
static constexpr uint64_t saCounterAllSet = 0x20ULL - 0x1ULL;
static constexpr uint64_t allOnes = ~(0x0ULL);
uint64_t counterPosMasks[maxPatternApproxSize];
uint64_t *dBuffer;
uint64_t maskBuffer[maskBufferSize];
SOPANG_WHITEBOX
};
} // namespace sopang
#endif // SOPANG_HPP