trie

package
v1.0.5 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2022 License: MIT Imports: 4 Imported by: 1

Documentation

Overview

Package trie implements the double array trie library.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DoubleArray

type DoubleArray []struct {
	Base, Check int32
}

DoubleArray represents the TRIE data structure.

func Build

func Build(keywords []string) (DoubleArray, error)

Build constructs a double array from given keywords.

func BuildWithIDs

func BuildWithIDs(keywords []string, ids []int) (DoubleArray, error)

BuildWithIDs constructs a double array from given keywords and ids.

func Read

func Read(r io.Reader) (DoubleArray, error)

Read loads a double array.

func (DoubleArray) CommonPrefixSearch

func (d DoubleArray) CommonPrefixSearch(input string) (ids, lens []int)

CommonPrefixSearch finds keywords sharing common prefix in an input and returns the ids and it's lengths if found.

func (DoubleArray) CommonPrefixSearchCallback

func (d DoubleArray) CommonPrefixSearchCallback(input string, callback func(id, l int))

CommonPrefixSearchCallback finds keywords sharing common prefix in an input and callback with id and length.

func (DoubleArray) Find

func (d DoubleArray) Find(input string) (id int, ok bool)

Find searches TRIE by a given keyword and returns the id if found.

func (DoubleArray) PrefixSearch

func (d DoubleArray) PrefixSearch(input string) (id int, ok bool)

PrefixSearch returns the longest common prefix keyword in an input if found.

func (DoubleArray) WriteTo

func (d DoubleArray) WriteTo(w io.Writer) (n int64, err error)

WriteTo saves a double array.

Jump to

Keyboard shortcuts

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