trie

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2021 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Overview

Package trie implements a simple trie data structure that maps "paths" (which are slices of strings) to arbitrary data values (type interface{}).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Trie

type Trie struct {
	Entry      interface{}
	SplatEntry interface{} // to match xxx.xxx.*
	Children   trieChildren
}

func NewTrie

func NewTrie() *Trie

NewTrie makes a new empty Trie

func (*Trie) Get

func (t *Trie) Get(path []string) (entry interface{}, ok bool)

Get retrieves an element from the Trie

Takes a path (which can be empty, to denote the root element of the Trie), and returns the object if the path exists in the Trie, or nil and a status of false. Example:

if res, ok := trie.Get([]string{"foo", "bar"}), ok {
  fmt.Println("Value at /foo/bar was", res)
}

func (*Trie) Set

func (t *Trie) Set(path []string, value interface{}) error

Set creates an element in the Trie

Takes a path (which can be empty, to denote the root element of the Trie), and an arbitrary value (interface{}) to use as the leaf data.

Jump to

Keyboard shortcuts

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