bktree

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

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

Go to latest
Published: Dec 28, 2016 License: BSD-3-Clause Imports: 5 Imported by: 0

README

Build Status

Go-bktree

https://travis-ci.org/bahadrix/go-bktree.svg?branch=master Go-bktree provides an implementation of BK-tree.

Fork Info

Forked from github.com/hjr265/go-bktree. Following features added:

  • Saving and reading from file via Protocol Buffers serialization.
  • Payload type converted to bytes instead of string. This way any other distance can be calculated like Hamming Distance.

Installation

Install Go-bktree using the go get command:

$ go get github.com/bahadrix/go-bktree

The only dependency is the Go distribution itself.

Documentation

Contributing

Contributions are welcome.

License

Go-bktree is available under the BSD (3-Clause) License.

Documentation

Overview

Package bktree provides an implementation of BK-tree (http://en.wikipedia.org/wiki/BK-tree).

A BK-tree is a metric tree suggested by Walter Austin Burkhard and Robert M. Keller specifically adapted to discrete metric spaces.

Package model is a generated protocol buffer package.

It is generated from these files:

model.proto

It has these top-level messages:

Node

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BKTree

type BKTree struct {
	Metric Metric // Metric function, required
	// contains filtered or unexported fields
}

BKTree represents a BK-tree with a given metric function.

func New

func New(m Metric) *BKTree

New returns an initialized BK-tree.

func (*BKTree) Add

func (t *BKTree) Add(data []byte)

Add inserts a new word to the BK-tree.

func (*BKTree) Find

func (t *BKTree) Find(data []byte, n int64) [][]byte

Find returns all the words in the BK-tree with a distance of n from w.

func (*BKTree) ReadFromFile

func (t *BKTree) ReadFromFile(dbFile string) (err error)

Reads data from file and deserialize into tree

func (*BKTree) SaveToFile

func (t *BKTree) SaveToFile(filePath string) (saved bool, err error)

Serializes data and saves into file If tree is empty no operation will be made and 'saved' parameter returns false.

type Metric

type Metric func(a, b []byte) int

The Metric type is a function used by BK-tree instances to measure the distance between two given strings.

type Node

type Node struct {
	Data     []byte          `protobuf:"bytes,1,opt,name=data,proto3" json:"data,omitempty"`
	Children map[int64]*Node `` /* 137-byte string literal not displayed */
}

protoc model.proto --go_out=.

func (*Node) Add

func (e *Node) Add(data []byte, m Metric)

func (*Node) Descriptor

func (*Node) Descriptor() ([]byte, []int)

func (*Node) Find

func (e *Node) Find(data []byte, n, d int64, m Metric, r [][]byte) [][]byte

func (*Node) GetChildren

func (m *Node) GetChildren() map[int64]*Node

func (*Node) ProtoMessage

func (*Node) ProtoMessage()

func (*Node) Reset

func (m *Node) Reset()

func (*Node) String

func (m *Node) String() string

Jump to

Keyboard shortcuts

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