trie

package
v0.0.0-...-c6d90aa Latest Latest
Warning

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

Go to latest
Published: Dec 27, 2022 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Aggregator

type Aggregator struct {
	sync.RWMutex
	Params map[InvParam]int64
}

Aggregator struct holding various inventory param values

func NewAggregator

func NewAggregator() *Aggregator

NewAggregator creates Aggregator

func (*Aggregator) Add

func (a *Aggregator) Add(param InvParam, val int64)

Add adds inv parameter value to aggregation

func (*Aggregator) Clone

func (a *Aggregator) Clone() *Aggregator

Clone creates a copy of aggregator

type InvParam

type InvParam uint

InvParam represent type or inventory parameter

const (
	// BytesSize size of the values in bytes
	BytesSize InvParam = iota
	// KeysCount number of keys
	KeysCount
)

func (InvParam) MarshalText

func (p InvParam) MarshalText() (text []byte, err error)

MarshalText renders InvParam as a string when marshalling

func (InvParam) String

func (p InvParam) String() string

String implements stringer interface to display InvParam as a string

func (*InvParam) UnmarshalText

func (p *InvParam) UnmarshalText(text []byte) error

UnmarshalText decodes InvParam value from string

type Node

type Node struct {
	Children              map[string]*Node `json:"Children,omitempty"`
	Aggr                  *Aggregator      `json:"Values,omitempty"`
	OverflowChildrenCount uint64           `json:"Overflow,omitempty"`
	// contains filtered or unexported fields
}

Node node of the trie

func NewNode

func NewNode() *Node

NewNode creates Node

func (*Node) AddAggregator

func (n *Node) AddAggregator(aggr *Aggregator)

AddAggregator adds aggregator

func (*Node) AddChild

func (n *Node) AddChild(key string, node *Node)

AddChild add child nodes on provided key

func (*Node) Aggregator

func (n *Node) Aggregator() *Aggregator

Aggregator Returns aggregator attached to the node

func (*Node) ChildCount

func (n *Node) ChildCount() int

ChildCount return number of child nodes

func (*Node) FindNextAggregatedNode

func (n *Node) FindNextAggregatedNode() *Node

FindNextAggregatedNode descends down trie branch till the next node with aggregator

func (*Node) FindNextAggregatedNodeWithKey

func (n *Node) FindNextAggregatedNodeWithKey() ([]string, *Node)

FindNextAggregatedNodeWithKey descends down trie branch till the next node with aggregator and returns key path to it

func (*Node) FirstChild

func (n *Node) FirstChild() *Node

FirstChild returns child node, panics if there are no child nodes

func (*Node) FirstChildWithKey

func (n *Node) FirstChildWithKey() (string, *Node)

FirstChildWithKey return child node and its key, panics if there are no child nodes

func (*Node) GetChild

func (n *Node) GetChild(key string) *Node

GetChild returns a child node by provided key, if key doesn't exist returns nil

func (*Node) HasAggregator

func (n *Node) HasAggregator() bool

HasAggregator returns if the node has aggregator attached

func (*Node) HasChildren

func (n *Node) HasChildren() bool

HasChildren returns if the node has at least one child node

type ParamValue

type ParamValue struct {
	Param InvParam
	Value int64
}

ParamValue value for inventory param

type PunctuationSplitter

type PunctuationSplitter struct {
	// contains filtered or unexported fields
}

PunctuationSplitter splitting keys by a specific set of symbols (i.e. punctuation)

func NewPunctuationSplitter

func NewPunctuationSplitter(punctuation ...rune) *PunctuationSplitter

NewPunctuationSplitter creates PunctuationSplitter

func (*PunctuationSplitter) Split

func (s *PunctuationSplitter) Split(in string) []string

Split splits string key to fragments with given strategy

type Splitter

type Splitter interface {
	// Split splits string key to fragments with given strategy
	Split(in string) []string
}

Splitter abstraction to split string in fragments

type Trie

type Trie struct {
	// contains filtered or unexported fields
}

Trie stores data about keys in a prefix tree

func NewTrie

func NewTrie(splitter Splitter, maxChildren int) *Trie

NewTrie created Trie

func (*Trie) Add

func (t *Trie) Add(key string, paramValues ...ParamValue)

Add adds information about another key with set of params

func (*Trie) Root

func (t *Trie) Root() *Node

Root returns root of the trie

Jump to

Keyboard shortcuts

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