weightedtrie

package module
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2020 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Leafs

type Leafs []*PlainLeaf

sorter interface

func (Leafs) Len

func (slice Leafs) Len() int

func (Leafs) Less

func (slice Leafs) Less(i, j int) bool

func (Leafs) Swap

func (slice Leafs) Swap(i, j int)

type PlainLeaf

type PlainLeaf struct {
	Value    string
	Category string
	Weight   float64
}

func (*PlainLeaf) String

func (m *PlainLeaf) String() string

type Trie

type Trie struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func LoadFromFile

func LoadFromFile(fname string) (tr *Trie, err error)

LoadFromFile loads a gib encoded wordlist from a file and creates a new Trie by Add()ing all of them.

func New

func New() *Trie

NewTrie returns the pointer to a new Trie with an initialized root Branch

func (*Trie) Add

func (t *Trie) Add(val, cat string, w float64)

Add adds an entry to the trie

func (*Trie) Find

func (t *Trie) Find(prefix string) Leafs

Find returns all entries of the Trie that have the given prefix with their counts as Leaf sorted by weights

func (*Trie) FindFirstN

func (t *Trie) FindFirstN(prefix string, n int) Leafs

FindFirstN returns first N results for given prefix sorted by weights

func (*Trie) SaveToFile

func (t *Trie) SaveToFile(fname string) (err error)

SaveToFile dumps all values into a slice of strings and writes that to a file using encoding/gob.

The Trie itself can currently not be encoded directly because gob does not directly support structs with a sync.Mutex on them.

Jump to

Keyboard shortcuts

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