forked from aalhour/C-Sharp-Algorithms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAhoCorasickVertex.cs
68 lines (57 loc) · 1.78 KB
/
AhoCorasickVertex.cs
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
using System.Collections.Generic;
namespace Algorithms.Strings
{
internal class AhoCorasickVertex
{
/// <summary>
/// A flag indicating whether our vertex is the source string.
/// </summary>
public bool IsPattern;
/// <summary>
/// The number (Value) of the vertex to which we arrive by symbol (Key).
/// </summary>
public readonly SortedDictionary<char, int> NextVertex;
/// <summary>
/// Remembering the transition of the automaton.
/// </summary>
public readonly SortedDictionary<char, int> AutoMove;
/// <summary>
/// The suffix link of the vertex X is a pointer to the vertex Y,
/// such that the string Y is the largest own suffix of the string X, or,
/// if there is no such vertex in the tree, then the pointer to the root.
/// In particular, a link from the root leads to it.
/// </summary>
public int SuffLink;
/// <summary>
/// "Good" suffix link.
/// </summary>
public int GoodSuffLink;
/// <summary>
/// parrent vertex in a tree.
/// </summary>
public readonly int Parent;
/// <summary>
/// Symbol on the vertex.
/// </summary>
public readonly char Symbol;
/// <summary>
/// For tests.
/// </summary>
public string Str;
/// <summary>
/// Create a vertex by initializing the variables and setting the parrent and symbol.
/// </summary>
/// <param name="parent">Number of the parrent</param>
/// <param name="symbol">Symbol on the vertex in the tree.</param>
public AhoCorasickVertex(int parent, char symbol)
{
IsPattern = false;
NextVertex = new SortedDictionary<char, int>();
AutoMove = new SortedDictionary<char, int>();
Parent = parent;
Symbol = symbol;
GoodSuffLink = -1; // initially - no suffix flink.
SuffLink = -1; // initially - no suffix link.
}
}
}