treap

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2015 License: MIT Imports: 2 Imported by: 0

README

treap

This Go package provides a balanced binary search tree data structure, expected to have logarithmic height.

This is for go version 1.0.

For more on treaps, check out the following links:

This implementation borrows a lot of ideas from GoLLRB by Petar Maymounkov.

Status

This package was extracted from production code powering StatHat, so clearly we feel that it is production-ready, but it should still be considered experimental as other uses of it could reveal issues we aren't experiencing.

Contact us

We'd love to hear from you if you are using this in your projects! Please drop us a line: @stathat or contact us here.

About

Written by Patrick Crosby at StatHat. Twitter: @stathat

Documentation

Overview

The treap package provides a balanced binary tree datastructure, expected to have logarithmic height.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Item

type Item interface{}

Item can be anything.

type Key

type Key interface{}

Key can be anything. It will use LessFunc to compare keys.

type LessFunc

type LessFunc func(a, b interface{}) bool

LessFunc returns true if a < b

type Node

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

A Node in the Tree.

type OverlapFunc

type OverlapFunc func(a, b interface{}) bool

OverlapFunc return true if a overlaps b. Optional. Only used by overlap trees.

type Tree

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

A Tree is the data structure that stores everything

func NewOverlapTree

func NewOverlapTree(lessfn LessFunc, overfn OverlapFunc) *Tree

To create a tree that also lets you iterate by key overlap, supply a LessFunc and an OverlapFunc

func NewTree

func NewTree(lessfn LessFunc) *Tree

To create a Tree, you need to supply a LessFunc that can compare the keys in the Node.

func (*Tree) Delete

func (t *Tree) Delete(key Key)

Delete the item from the tree that has this key.

func (*Tree) Exists

func (t *Tree) Exists(key Key) bool

Returns true if there is an item in the tree with this key.

func (*Tree) Get

func (t *Tree) Get(key Key) Item

Get an Item in the tree.

func (*Tree) Height

func (t *Tree) Height(key Key) int

Returns the height (depth) of the tree.

func (*Tree) Insert

func (t *Tree) Insert(key Key, item Item)

Insert an item into the tree.

func (*Tree) IterAscend

func (t *Tree) IterAscend() <-chan Item

Returns a channel of Items whose keys are in ascending order.

func (*Tree) IterKeysAscend

func (t *Tree) IterKeysAscend() <-chan Key

Returns a channel of keys in ascending order.

func (*Tree) IterateOverlap

func (t *Tree) IterateOverlap(key Key) <-chan Item

Returns a channel of items that overlap key.

func (*Tree) Len

func (t *Tree) Len() int

The length of the tree (number of nodes).

func (*Tree) Max

func (t *Tree) Max() Item

Returns the maximum item in the tree.

func (*Tree) Merge

func (t *Tree) Merge(left, right *Node) *Node

Merge two trees together by supplying the root node of each tree.

func (*Tree) Min

func (t *Tree) Min() Item

Returns the minimum item in the tree.

func (*Tree) Reset

func (t *Tree) Reset()

Remove everything from the tree.

func (*Tree) Split

func (t *Tree) Split(key Key) (*Node, *Node)

Split the tree by creating a tree with a node of priority -1 so it will be the root

Jump to

Keyboard shortcuts

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