bintree

package
v0.0.0-...-3e94386 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2018 License: MIT Imports: 5 Imported by: 2

Documentation

Overview

Package bintree creates a binary tree of Ip Addresses for use in the distributed mutex algorithm.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ByIP

type ByIP []string

ByIP is a special type used for building the binary tree, specifically the initial sorting. Len, Swap, and Less functions are used in sorting the Ipaddrs prior to building the tree.

func (ByIP) Len

func (a ByIP) Len() int

Len returns the length of the binary tree and is used for building the binary tree.

func (ByIP) Less

func (a ByIP) Less(i, j int) bool

Less is used for comparing nodes when building the binary tree.

func (ByIP) Swap

func (a ByIP) Swap(i, j int)

Swap is used for building the binary tree.

type Tree

type Tree struct {
	NumLeaves int
	// contains filtered or unexported fields
}

Tree is used to store the root of the binary tree. Each node, including the root has pointers to its descendants so the rest of the tree is reached from this point.

func NewTree

func NewTree(ipAddrs []string) (*Tree, error)

NewTree initializes the binary tree. It takes an array of strings representing Ip addresses. It will verify the entries in the array are Ip addresses, and then builds the tree and tree paths, returning the Tree type.

func (*Tree) AllPaths

func (t *Tree) AllPaths() [][]string

AllPaths returns all possible paths in the tree starting from the root and ending at a leaf.

func (*Tree) NodePaths

func (t *Tree) NodePaths(ipAddr string) [][]string

NodePaths returns all possible paths in the tree starting from the node at ipAddr and ending at a leaf.

Jump to

Keyboard shortcuts

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