Documentation ¶
Index ¶
- Constants
- Variables
- type Cedar
- func (da *Cedar) Delete(key []byte) error
- func (da *Cedar) DumpGraph(fname string)
- func (da *Cedar) Get(key []byte) (value interface{}, err error)
- func (da *Cedar) Insert(key []byte, value interface{}) error
- func (da *Cedar) Jump(path []byte, from int) (to int, err error)
- func (da *Cedar) Key(id int) (key []byte, err error)
- func (da *Cedar) Load(in io.Reader, dataType string) error
- func (da *Cedar) LoadFromFile(fileName string, dataType string) error
- func (da *Cedar) PrefixMatch(key []byte, num int) (ids []int)
- func (da *Cedar) PrefixPredict(key []byte, num int) (ids []int)
- func (da *Cedar) Save(out io.Writer, dataType string) error
- func (da *Cedar) SaveToFile(fileName string, dataType string) error
- func (da *Cedar) Status() (keys, nodes, size, capacity int)
- func (da *Cedar) Update(key []byte, value int) error
- type MatchToken
- type Matcher
- type Response
Constants ¶
const ( DefaultTokenBufferSize = 137500 DefaultMatchBufferSize = 137500 )
const ( CJKZhMin = '\u4E00' CJKZhMax = '\u9FFF' )
defines max & min value of chinese CJK code
Variables ¶
var ( ErrInvalidDataType = errors.New("cedar: invalid datatype") ErrInvalidValue = errors.New("cedar: invalid value") ErrInvalidKey = errors.New("cedar: invalid key") ErrNoPath = errors.New("cedar: no path") ErrNoValue = errors.New("cedar: no value") ErrTooLarge = errors.New("acmatcher: Tool Large for grow") )
defines Error type
Functions ¶
This section is empty.
Types ¶
type Cedar ¶
type Cedar struct {
// contains filtered or unexported fields
}
Cedar encapsulates a fast and compressed double array trie for words query
func (*Cedar) Delete ¶
Delete removes a key-value pair from the cedar. It will return ErrNoPath, if the key has not been added.
func (*Cedar) Get ¶
Get returns the value associated with the given `key`. It is equivalent to
id, err1 = Jump(key) value, err2 = Value(id)
Thus, it may return ErrNoPath or ErrNoValue,
func (*Cedar) Insert ¶
Insert adds a key-value pair into the cedar. It will return ErrInvalidValue, if value < 0 or >= valueLimit.
func (*Cedar) Jump ¶
Jump travels from a node `from` to another node `to` by following the path `path`. For example, if the following keys were inserted:
id key 19 abc 23 ab 37 abcd
then
Jump([]byte("ab"), 0) = 23, nil // reach "ab" from root Jump([]byte("c"), 23) = 19, nil // reach "abc" from "ab" Jump([]byte("cd"), 23) = 37, nil // reach "abcd" from "ab"
func (*Cedar) Key ¶
Key returns the key of the node with the given `id`. It will return ErrNoPath, if the node does not exist.
func (*Cedar) Load ¶
Load loads the cedar from an io.Writer, where dataType is either "json" or "gob".
func (*Cedar) LoadFromFile ¶
LoadFromFile loads the cedar from a file, where dataType is either "json" or "gob".
func (*Cedar) PrefixMatch ¶
PrefixMatch returns a list of at most `num` nodes which match the prefix of the key. If `num` is 0, it returns all matches. For example, if the following keys were inserted:
id key 19 abc 23 ab 37 abcd
then
PrefixMatch([]byte("abc"), 1) = [ 23 ] // match ["ab"] PrefixMatch([]byte("abcd"), 0) = [ 23, 19, 37] // match ["ab", "abc", "abcd"]
func (*Cedar) PrefixPredict ¶
PrefixPredict returns a list of at most `num` nodes which has the key as their prefix. These nodes are ordered by their keys. If `num` is 0, it returns all matches. For example, if the following keys were inserted:
id key 19 abc 23 ab 37 abcd
then
PrefixPredict([]byte("ab"), 2) = [ 23, 19 ] // predict ["ab", "abc"] PrefixPredict([]byte("ab"), 0) = [ 23, 19, 37 ] // predict ["ab", "abc", "abcd"]
func (*Cedar) Save ¶
Save saves the cedar to an io.Writer, where dataType is either "json" or "gob".
func (*Cedar) SaveToFile ¶
SaveToFile saves the cedar to a file, where dataType is either "json" or "gob".
func (*Cedar) Status ¶
Status reports the following statistics of the cedar:
keys: number of keys that are in the cedar, nodes: number of trie nodes (slots in the base array) has been taken, size: the size of the base array used by the cedar, capacity: the capicity of the base array used by the cedar.
type MatchToken ¶
type MatchToken struct { KLen int // len of key Value interface{} At int // match position of source text Freq uint }
MatchToken matched words in Aho Corasick Matcher
type Matcher ¶
type Matcher struct {
// contains filtered or unexported fields
}
Matcher Aho Corasick Matcher
type Response ¶
type Response struct {
// contains filtered or unexported fields
}
func NewResponse ¶
func (*Response) NextMatchItem ¶
func (r *Response) NextMatchItem(content []byte) []MatchToken