-
Notifications
You must be signed in to change notification settings - Fork 715
/
ranked_match.hh
64 lines (49 loc) · 1.73 KB
/
ranked_match.hh
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
#ifndef ranked_match_hh_INCLUDED
#define ranked_match_hh_INCLUDED
#include "string.hh"
#include "meta.hh"
#include <cstdint>
namespace Kakoune
{
using UsedLetters = uint64_t;
UsedLetters used_letters(StringView str);
constexpr UsedLetters upper_mask = 0xFFFFFFC000000;
inline UsedLetters to_lower(UsedLetters letters)
{
return ((letters & upper_mask) >> 26) | (letters & (~upper_mask));
}
struct RankedMatch
{
RankedMatch(StringView candidate, StringView query);
RankedMatch(StringView candidate, UsedLetters candidate_letters,
StringView query, UsedLetters query_letters);
const StringView& candidate() const { return m_candidate; }
bool operator<(const RankedMatch& other) const;
bool operator==(const RankedMatch& other) const { return m_candidate == other.m_candidate; }
explicit operator bool() const { return m_matches; }
void set_input_sequence_number(size_t i) { m_input_sequence_number = i; }
private:
template<typename TestFunc>
RankedMatch(StringView candidate, StringView query, TestFunc test);
enum class Flags : int
{
None = 0,
// Order is important, the highest bit has precedence for comparison
SingleWord = 1 << 0,
Contiguous = 1 << 1,
OnlyWordBoundary = 1 << 2,
Prefix = 1 << 3,
BaseName = 1 << 4,
SmartFullMatch = 1 << 5,
FullMatch = 1 << 6,
};
friend constexpr bool with_bit_ops(Meta::Type<Flags>) { return true; }
StringView m_candidate{};
bool m_matches = false;
Flags m_flags = Flags::None;
int m_word_boundary_match_count = 0;
int m_max_index = 0;
size_t m_input_sequence_number = 0;
};
}
#endif // ranked_match_hh_INCLUDED