prefixmap: github.com/alediaferia/prefixmap Index | Files

package prefixmap

import "github.com/alediaferia/prefixmap"

Index

Package Files

prefixmap.go queue.go

type Node Uses

type Node struct {
    // true if this node is a leaf node
    IsLeaf bool

    // the reference to the parent node
    Parent *Node

    // the children nodes
    Children []*Node
    // contains filtered or unexported fields
}

Node is a single node within the map

func (*Node) Depth Uses

func (m *Node) Depth() int

Depth returns the depth of the current node within the map

func (*Node) Key Uses

func (m *Node) Key() string

Key Retrieves current node key complexity: MAX|O(log(N))| where N is the number of nodes in the map. Number of nodes in the map cannot exceed number of keys + 1.

type Prefix Uses

type Prefix struct {

    // The current prefix string
    Key string

    // The values associated to the current prefix
    Values []interface{}
    // contains filtered or unexported fields
}

Prefix holds prefix information passed to the PrefixCallback instance by the EachPrefifx method.

func (*Prefix) Depth Uses

func (p *Prefix) Depth() int

Depth returns the depth of the corresponding node for this prefix in the map.

type PrefixCallback Uses

type PrefixCallback func(prefix Prefix) (skipBranch bool, halt bool)

PrefixCallback is invoked by EachPrefix for each prefix reached by the traversal. The callback has the ability to affect the traversal. Returning skipBranch = true will make the traversal skip the current branch and jump to the sibling node in the map. Returning halt = true, instead, will halt the traversal altogether.

type PrefixMap Uses

type PrefixMap Node

PrefixMap type

func New Uses

func New() *PrefixMap

New returns a new empty map

func (*PrefixMap) Contains Uses

func (m *PrefixMap) Contains(key string) bool

Contains checks if the given key is present in the map In this case, an exact match case is considered If you're interested in prefix-based check: ContainsPrefix

func (*PrefixMap) ContainsPrefix Uses

func (m *PrefixMap) ContainsPrefix(key string) bool

ContainsPrefix checks if the given prefix is present as key in the map

func (*PrefixMap) EachPrefix Uses

func (m *PrefixMap) EachPrefix(callback PrefixCallback)

EachPrefix iterates over the prefixes contained in the map using a DFS algorithm. The callback can be used to skip a prefix branch altogether or halt the iteration.

func (*PrefixMap) Get Uses

func (m *PrefixMap) Get(key string) []interface{}

Get returns the data associated with the given key in the map or nil if no such key is present in the map

func (*PrefixMap) GetByPrefix Uses

func (m *PrefixMap) GetByPrefix(key string) []interface{}

GetByPrefix returns a flattened collection of values associated with the given prefix key

func (*PrefixMap) Insert Uses

func (m *PrefixMap) Insert(key string, values ...interface{})

Insert inserts a new value in the map for the specified key If the key is already present in the map, the value is appended to the values list associated with the given key

func (*PrefixMap) Replace Uses

func (m *PrefixMap) Replace(key string, values ...interface{})

Replace replaces the value(s) for the given key in the map with the give ones. If no such key is present, this method behaves the same as Insert

Package prefixmap imports 1 packages (graph) and is imported by 1 packages. Updated 2016-07-14. Refresh now. Tools for package owners.