trie

package
v0.1.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 3, 2024 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Trie

type Trie struct {
	Root *TrieNode `json:"root"` // 存储 Trie 树的根节点
}

func NewTrie

func NewTrie() *Trie

func (*Trie) FindAllByPrefix

func (trie *Trie) FindAllByPrefix(prefix string) []string

func (*Trie) FindAllByPrefixForRecall added in v0.1.1

func (trie *Trie) FindAllByPrefixForRecall(prefix string) []string

FindAllByPrefixForRecall 召回专用的,通过前缀获取所有的节点

func (*Trie) Insert

func (trie *Trie) Insert(word string)

func (Trie) MarshalEasyJSON

func (v Trie) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (Trie) MarshalJSON

func (v Trie) MarshalJSON() ([]byte, error)

MarshalJSON supports json.Marshaler interface

func (*Trie) Merge

func (trie *Trie) Merge(other *Trie)

func (*Trie) Search

func (trie *Trie) Search(word string) bool

func (*Trie) SearchForRecall added in v0.1.1

func (trie *Trie) SearchForRecall(word string) bool

SearchForRecall 召回时查询这个word是否存在

func (*Trie) StartsWith

func (trie *Trie) StartsWith(prefix string) bool

func (*Trie) Traverse

func (trie *Trie) Traverse()

func (*Trie) TraverseForRecall added in v0.1.1

func (trie *Trie) TraverseForRecall()

TraverseForRecall 查看所有节点的信息

func (*Trie) UnmarshalEasyJSON

func (v *Trie) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*Trie) UnmarshalJSON

func (v *Trie) UnmarshalJSON(data []byte) error

UnmarshalJSON supports json.Unmarshaler interface

type TrieNode

type TrieNode struct {
	IsEnd          bool                                  `json:"is_end"`   // 标记该节点是否为一个单词的末尾
	Children       cmap.ConcurrentMap[string, *TrieNode] `json:"children"` // 存储子节点的指针
	ChildrenRecall map[string]*TrieNode                  `json:"children_recall"`
}

TrieNode TODO:后面看看能不能把build和recall的过程分开,主要是 cmap.ConcurrentMap[string, *TrieNode] 没法反序列化...

func NewTrieNode

func NewTrieNode() *TrieNode

func ParseTrieNode added in v0.1.1

func ParseTrieNode(str string) (*TrieNode, error)

ParseTrieNode 解析 TrieNode 结构体, 从数据库读出来是字符串,然后解析这个字符串成一棵树

func (TrieNode) MarshalEasyJSON

func (v TrieNode) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (TrieNode) MarshalJSON

func (v TrieNode) MarshalJSON() ([]byte, error)

MarshalJSON supports json.Marshaler interface

func (*TrieNode) UnmarshalEasyJSON

func (v *TrieNode) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*TrieNode) UnmarshalJSON

func (v *TrieNode) UnmarshalJSON(data []byte) error

UnmarshalJSON supports json.Unmarshaler interface

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL