Documentation
¶
Index ¶
Constants ¶
const (
DefaultPatternDelimeter = ":"
)
consts
Variables ¶
var (
ErrDuplicatedPatternName = errors.New("trie.go: the pattern name already exists")
)
Errors
Functions ¶
func RegisterPattern ¶
RegisterPattern allow you add a customize pattern to the defaultPatternStore.
Types ¶
type Node ¶
type Node struct {
Pattern *Pattern
Value interface{}
Data map[string]interface{}
Children map[string]*Node
// contains filtered or unexported fields
}
Node is the tree node of the Trie.
type Pattern ¶
type Pattern struct {
IsRegexpPattern bool
// contains filtered or unexported fields
}
Pattern of trie node.
func (*Pattern) EqualToStr ¶
EqualToStr returns true if the pattern's regexpStr just equal to self's patternStr
func (*Pattern) Match ¶
Match matches the given string with self's regexpStr, if pattern matched, it will return true and the params it found. Otherwise, just returns false and nil.
func (*Pattern) MatchEverything ¶
MatchEverything returns true, if the pattern is the `*` pattern.
type PatternStore ¶
PatternStore is a pattern register.
func NewPatternStore ¶
func NewPatternStore() *PatternStore
NewPatternStore returns a new PatternStore object.
func (*PatternStore) GetPattern ¶
func (store *PatternStore) GetPattern(name string) string
GetPattern returns a pattern which is bound to name. If there is none, returns the default pattern. In the Default Pattern Store, it just returns then `str` pattern.
type Result ¶
type Result struct {
Params map[string]string
Value interface{}
ChainData []map[string]interface{}
}
Result is return by Match and GetNode.
type Trie ¶
Trie is a tree
func (*Trie) GetNode ¶
GetNode allows you use the origin pattern string which was used in Put to get the node which points it.
func (*Trie) Has ¶
Has returns true if the pattern is duplicated in the trie tree. Otherwise, returns false.
func (*Trie) Match ¶
Match try to match the key with a pattern, if successful, it will return true and the value which was put with the matched pattern. If the pattern is't a certain string, this function will also return the params matched by this pattern.
func (*Trie) SetDelimeter ¶
SetDelimeter sets the delimeter of the trie object.