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 +}