radix

package module
v0.0.0-...-f5082e2 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2014 License: BSD-2-Clause Imports: 3 Imported by: 1

README

Radix

Package radix implement a radix tree in go. It is expected that the keys are in UTF-8 (i.e. go runes), and that insertion and lookup is far more common than deletion.

Use godoc tool to have a full documentation of the package.

Quick usage

go get github.com/js-arias/radix

The main data structure is Radix, that is initialized with New, e.g.

import "github.com/js-arias/radix"
var r = radix.New()

The implementation of radix is private. To access data use:

func (r *Radix) Insert(key string, value interface{}) error

Insert a value in the radix. It returns an error if the key is already in use.

func (r *Radix) Set(key string, value interface{}) error

Set provides a more flexible way to add data to the radix, as it reset a value if the key is already in use, or creates a new key if it is not already in the radix (as Insert).

func (r *Radix) Lookup(key string) interface{}

Searches for a particular key.

func (r *Radix) Prefix(key string) *list.List

Return all elements that has key as its prefix.

func (r *Radix) Delete(key string) interface{}

Removes an element from the radix, and returns it.

The radix can be navigated using an iterator that scan the radix in alphabetical order:

for it := r.Iterator(); it != nil; it.Next() {
    // do something with it.Value or it.Key
}

Authorship and license

Copyright (c) 2013, J. Salvador Arias jsalarias@csnat.unt.edu.ar All rights reserved. Distributed under BSD2 license that can be found in the LICENSE file.

Documentation

Overview

Package radix implement a radix tree. It is expected that the keys are in UTF-8 (i.e. go runes), and that insertion and lookup is far more common than deletion.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Iterator

type Iterator struct {

	// Key of the element
	Key string

	// Value assigned to current element
	Value interface{}
	// contains filtered or unexported fields
}

Iterator is an iterator of a Radix Tree.

It is useful for navigating the radix in alphabetical order:

for it := r.Iterator(); it != nil; it.Next() {
    // do something with it.Value or it.Key
}

func (*Iterator) Next

func (it *Iterator) Next() *Iterator

Next retrieve the next valid iterator, if there are no more elements in the radix, a nil iterator will be returned.

type Radix

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

Radix is a radix tree.

func New

func New() *Radix

New returns a new, empty radix tree.

func (*Radix) Delete

func (rad *Radix) Delete(key string) interface{}

Delete removes the value associated with a particular key and returns it.

func (*Radix) Insert

func (rad *Radix) Insert(key string, value interface{}) error

Insert put a value in the radix. It returns an error if the given key is already in use.

func (*Radix) Iterator

func (rad *Radix) Iterator() *Iterator

Iterator returns a new iterator for a given Radix tree. If the tree is empty, a nil Iterator will be return.

func (*Radix) Lookup

func (rad *Radix) Lookup(key string) interface{}

Lookup searches for a particular string in the tree.

func (*Radix) Prefix

func (rad *Radix) Prefix(prefix string) *list.List

Prefix returns a list of elements that share a given prefix.

func (*Radix) Set

func (rad *Radix) Set(key string, value interface{}) error

Set sets a value in a key already in use. If the key does not exist, then inserts the new key and value.

Jump to

Keyboard shortcuts

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