trie

package module
v0.0.0-...-5aacdb8 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2015 License: Apache-2.0 Imports: 2 Imported by: 0

README

go-container-trie

Package trie implements a byte trie with edge compression.

This code used to live in code.google.com/p/lvd.go/container/trie.

GoDoc

Documentation

Overview

Package trie implements a byte trie with edge compression.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type KV

type KV struct {
	K string
	V interface{}
}

A KV is a key, value pair, as returned by FindAllPfx

type Trie

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

A Trie maintains a sorted collection of values keyed on a string. Insertion is O(len(key)). Unlike Go's built-in map there is no distinction between a nil and a non-existent value. The zero value for Trie is an empty trie ready to use.

func (*Trie) FindAllPfx

func (t *Trie) FindAllPfx(key string) []KV

FindAllPfx returns all prefixes of key in the trie and their values.

func (*Trie) FindPfx

func (t *Trie) FindPfx(key string) (pfx string, val interface{})

FindPfx finds the longest prefix of key in the trie that has a non-nil value.

func (*Trie) ForEach

func (t *Trie) ForEach(f func(string, interface{}) bool)

ForEach will apply the function f to each key, value pair in the Trie in sorted (depth-first pre-)order. if f returns false, the iteration will stop.

func (*Trie) ForEachB

func (t *Trie) ForEachB(f func([]byte, interface{}) bool)

ForEachB will apply the function f to each key, value pair in the Trie in sorted (depth-first pre-)order. if f returns false, the iteration will stop.

func (*Trie) ForEachPfx

func (t *Trie) ForEachPfx(pfx string, f func(string, interface{}) bool)

ForEachPfx applies ForEach to the sub-trie that starts with the given prefix.

func (*Trie) Get

func (t *Trie) Get(key string) interface{}

Get retrieves an element from the trie if it exists, or nil if it does not.

func (*Trie) Put

func (t *Trie) Put(key string, value interface{})

Put inserts or replaces a value in the trie. To remove a value insert nil.

func (*Trie) String

func (t *Trie) String() string

String returns a multiline string representation of the trie in the form

trie[
   key1: value1
   key2: value2
   ....
]

Jump to

Keyboard shortcuts

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