intervalradix

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2025 License: Apache-2.0 Imports: 4 Imported by: 0

README

Interval Radix

Interval radix tree with byte slice keys optimized for point query read performance.

Go Reference Go Report Card Go Coverage

tree := intvradix.New[int]()
tree.Insert([]byte(`alpha`), []byte(`bravo`), 100)
tree.Insert([]byte(`bravo`), []byte(`charlie`), 200)
c := tree.Insert([]byte(`bravo`), []byte(`delta`), 300)

items := tree.Find([]byte(`bravo`))  // [200, 300]
items = tree.Find([]byte(`charlie`)) // [300]

items = tree.FindAny([]byte(`alpha`), []byte(`bravo`), []byte(`charlie`)) // [100, 200, 300]

c.Remove()

items = tree.Find([]byte(`bravo`))   // [200]
items = tree.Find([]byte(`charlie`)) // []

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Interval

type Interval[V any] struct {
	// contains filtered or unexported fields
}

Interval represnts an interval inserted into the tree.

func (*Interval[V]) Remove

func (i *Interval[V]) Remove()

Remove is the only way to remove items from the tree.

type Tree

type Tree[V any] struct {
	// contains filtered or unexported fields
}

Tree is a thread safe interval radix tree.

func New

func New[V any]() *Tree[V]

New returns a new interval radix tree.

func (*Tree[V]) Find

func (t *Tree[V]) Find(k []byte) (vals []V)

Find returns value of all intervals intersecting point key.

func (*Tree[V]) FindAny

func (t *Tree[V]) FindAny(keys ...[]byte) (vals []V)

FindAny returns value of all intervals intersecting any point in keys (no dupes).

func (*Tree[V]) Insert

func (t *Tree[V]) Insert(start, end []byte, val V) (i *Interval[V])

Insert makes the value available between interval [start, end). Exact matches on end are excluded.

Jump to

Keyboard shortcuts

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