-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Copy pathCharTrie.h
91 lines (74 loc) · 2.8 KB
/
CharTrie.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
//-------------------------------------------------------------------------------------------------------
// Copyright (C) Microsoft. All rights reserved.
// Copyright (c) ChakraCore Project Contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
//-------------------------------------------------------------------------------------------------------
#pragma once
namespace UnifiedRegex
{
// ----------------------------------------------------------------------
// CharTrie
// ----------------------------------------------------------------------
// FORWARD
struct CharTrieEntry;
class CharTrie : private Chars<char16>
{
friend class RuntimeCharTrie;
static const int initCapacity = 4;
CharTrieEntry* children;
bool isAccepting;
int capacity;
int count;
// Array of capacity entries, first count are used, in increasing character order
inline bool Find(Char c, int& outi);
public:
inline CharTrie() : isAccepting(false), capacity(0), count(0), children(0) {}
inline void Reset() { isAccepting = false; capacity = 0; count = 0; children = 0; }
void FreeBody(ArenaAllocator* allocator);
inline int Count() const { return count; }
inline bool IsAccepting() const { return isAccepting; }
inline void SetAccepting() { isAccepting = true; }
CharTrie* Add(ArenaAllocator* allocator, Char c);
bool IsDepthZero() const;
bool IsDepthOne() const;
#if ENABLE_REGEX_CONFIG_OPTIONS
void Print(DebugWriter* w) const;
#endif
};
struct CharTrieEntry : private Chars<char16>
{
Char c;
CharTrie node;
};
// ----------------------------------------------------------------------
// RuntimeCharTrie
// ----------------------------------------------------------------------
// FORWARD
struct RuntimeCharTrieEntry;
class RuntimeCharTrie : private Chars<char16>
{
int count;
// Array of count entries, in increasing character order
RuntimeCharTrieEntry* children;
public:
inline RuntimeCharTrie() : count(0), children(0) {}
void FreeBody(ArenaAllocator* allocator);
void CloneFrom(Js::ScriptContext* scriptContext, ArenaAllocator* allocator, const CharTrie& other);
bool Match
( const Char* const input
, const CharCount inputLength
, CharCount &inputOffset
#if ENABLE_REGEX_CONFIG_OPTIONS
, RegexStats* stats
#endif
) const;
#if ENABLE_REGEX_CONFIG_OPTIONS
void Print(DebugWriter* w) const;
#endif
};
struct RuntimeCharTrieEntry : private Chars<char16>
{
Char c;
RuntimeCharTrie node;
};
}