From 60c0098cfb9554549adc07db90787e92627a70fb Mon Sep 17 00:00:00 2001 From: loser <1711788888@qq.com> Date: Fri, 10 Nov 2023 09:12:30 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20'trie.go'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: loser <1711788888@qq.com> --- trie.go | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 trie.go diff --git a/trie.go b/trie.go new file mode 100644 index 0000000..a68df27 --- /dev/null +++ b/trie.go @@ -0,0 +1,32 @@ +package flashtext + +type Node struct { + children map[rune]*Node // 使用 map 存储叶子节点,key:'char' ,value: *Node + exist map[int]struct{} // 关键词节点是一个完整的匹配词,记录其长度 + failure *Node // 记录失败指针 +} + +func newNode() *Node { + return &Node{ + children: make(map[rune]*Node), + exist: make(map[int]struct{}), + } +} + +type Match struct { + match string + start int + end int +} + +func (m *Match) MatchString() string { + return m.match +} + +func (m *Match) Start() int { + return m.start +} + +func (m *Match) End() int { + return m.end +}