Documentation
¶
Overview ¶
Package trietree provides two trie-tree (prefix tree) implementations.
Index ¶
- type DNode
- type DTree
- func (dt *DTree) FillFailure()
- func (dt *DTree) Get(k string) *DNode
- func (dt *DTree) LongestPrefix(s string) (prefix string, edgeID int)
- func (dt *DTree) Predict(query string) iter.Seq[Prediction]
- func (dt *DTree) PredictIter(query string) PredictionIter
- func (dt *DTree) Put(k string) int
- func (dt *DTree) Scan(s string, r ScanReporter) error
- func (dt *DTree) ScanContext(ctx context.Context, s string, r ScanReporter) error
- type Prediction
- type PredictionIter
- type SNode
- type STree
- func (st *STree) LongestPrefix(s string) (prefix string, edgeID int)
- func (st *STree) Predict(query string) iter.Seq[Prediction]
- func (st *STree) PredictIter(query string) PredictionIter
- func (st *STree) Scan(s string, r ScanReporter) error
- func (st *STree) ScanContext(ctx context.Context, s string, r ScanReporter) error
- func (st *STree) Write(w io.Writer) error
- type ScanEvent
- type ScanNode
- type ScanReportFunc
- type ScanReporter
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DNode ¶
type DNode struct {
// Label is a rune assigned this node. The label is unique among sibling
// nodes
Label rune
// EdgeID indicates the node has a corresponding key or not.
EdgeID int
// Level is equals key length when EdgeID is not zero.
Level int
// Low is sibling nodes which have smaller Label.
Low *DNode
// High is sibling node which have greater Label.
High *DNode
// Child is a top node of children nods.
Child *DNode
// Failure is used as a search destination when the desired Label is not
// found in Child. This will be filled by FillFailure().
Failure *DNode
}
DNode is a node of dynamic tree.
type DTree ¶
type DTree struct {
Root DNode
// contains filtered or unexported fields
}
DTree is dynamic tree.
func (*DTree) FillFailure ¶
func (dt *DTree) FillFailure()
FillFailure fill Failure field with Aho-Corasick algorithm.
func (*DTree) LongestPrefix ¶ added in v0.0.2
LongestPrefix finds a longest prefix node/edge matches given s string.
func (*DTree) Predict ¶ added in v1.2.0
func (dt *DTree) Predict(query string) iter.Seq[Prediction]
Predict returns an iterator which enumerates Prediction: key suggestions that match the query in the tree.
func (*DTree) PredictIter ¶ added in v1.1.0
func (dt *DTree) PredictIter(query string) PredictionIter
PredictIter returns an iterator function PredictionIter, which enumerates Prediction: key suggestions that match the query in the tree.
func (*DTree) Put ¶
Put allocates an edge node for k key and emits ID for it. The ID will be greater than zero.
func (*DTree) Scan ¶
func (dt *DTree) Scan(s string, r ScanReporter) error
Scan scans a string to find matched words.
func (*DTree) ScanContext ¶
ScanContext scans a string to find matched words. ScanReporter r will receive reports for each characters when scan.
type Prediction ¶ added in v1.1.0
type Prediction struct {
Start int // Start is start index of key in query.
End int // End is end index of key in query.
ID int // ID is for edge node identifier.
}
Prediction is identifier of a key.
type PredictionIter ¶ added in v1.1.0
type PredictionIter func() *Prediction
PredictionIter is the iterator of Prediction.
type SNode ¶
type SNode struct {
Label rune
Start int // start index for children (inclusive)
End int // end index of children (exclusive)
Fail int // index to failure node
EdgeID int
}
SNode is a node for static tree.
type STree ¶
STree is static tree. It is optimized for serialization.
func (*STree) LongestPrefix ¶ added in v0.0.2
LongestPrefix finds a longest prefix node/edge matches given s string.
func (*STree) Predict ¶ added in v1.2.0
func (st *STree) Predict(query string) iter.Seq[Prediction]
Predict returns an iterator which enumerates Prediction: key suggestions that match the query in the tree.
func (*STree) PredictIter ¶ added in v1.1.0
func (st *STree) PredictIter(query string) PredictionIter
PredictIter returns an iterator function PredictionIter, which enumerates Prediction: key suggestions that match the query in the tree.
func (*STree) Scan ¶
func (st *STree) Scan(s string, r ScanReporter) error
Scan scans a string to find matched words.
func (*STree) ScanContext ¶
ScanContext scans a string to find matched words. ScanReporter r will receive reports for each characters when scan.
type ScanReportFunc ¶
type ScanReportFunc func(ev ScanEvent)
ScanReportFunc is a utility type to implements ScanReporter.
func (ScanReportFunc) ScanReport ¶
func (f ScanReportFunc) ScanReport(ev ScanEvent)
ScanReport implements a method of ScanReporter.
type ScanReporter ¶
type ScanReporter interface {
ScanReport(ev ScanEvent)
}
ScanReporter receive reports of scan.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package trie provides trie (prefix tree) algorithm.
|
Package trie provides trie (prefix tree) algorithm. |
|
Package trie2 provides two implementations of a trie-tree that can associate arbitrary values to nodes.
|
Package trie2 provides two implementations of a trie-tree that can associate arbitrary values to nodes. |