rtree

package module
v0.0.0-...-140edb6 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2022 License: MIT Imports: 1 Imported by: 0

README

rtree

A single dimension version of tidwall/rtree

Build Reliability Rating Quality Gate Status Coverage

Usage

import "github.com/segmentq/rtree"

// Init the tree
rt := rtree.NewOneD[int, string]()

// Insert a range
rt.Insert(1, 10, "wow cool rtree!")

// Search for it...
rt.Search(5, 5, func(min, max int, data string) bool {
    println(data)
    return true
})

// Delete it
rt.Delete(1, 10, "wow cool rtree!")

// Cleanup
rt.Clear()

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type IndexType

type IndexType interface {
	~int | ~int8 | ~int16 | ~int32 | ~int64 |
		~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr |
		~float32 | ~float64
}

type OneD

type OneD[I IndexType, T ValueType] struct {
	// contains filtered or unexported fields
}

OneD is an RTree of one ValueType that only takes a single index

func NewOneD

func NewOneD[I IndexType, T ValueType]() OneD[I, T]

NewOneD creates a new instance of OneD

func (*OneD[I, T]) Bounds

func (tr *OneD[I, T]) Bounds() (min, max I)

Bounds returns the minimum bounding box

func (*OneD[I, T]) Clear

func (tr *OneD[I, T]) Clear()

Clear will delete all items.

func (*OneD[I, T]) Copy

func (tr *OneD[I, T]) Copy() *OneD[I, T]

Copy the tree. This is a copy-on-write operation and is very fast because it only performs a shadowed copy.

func (*OneD[I, T]) Delete

func (tr *OneD[I, T]) Delete(min, max I, data T)

Delete an item from the structure

func (*OneD[I, T]) Insert

func (tr *OneD[I, T]) Insert(min, max I, data T)

Insert an item into the structure

func (*OneD[I, T]) Len

func (tr *OneD[I, T]) Len() int

Len returns the number of items in tree

func (*OneD[I, T]) Nearby

func (tr *OneD[I, T]) Nearby(
	algo func(min, max I, data T, item bool) (dist float64),
	iter func(min, max I, data T, dist float64) bool,
)

Nearby performs a kNN-type operation on the index

func (*OneD[I, T]) Replace

func (tr *OneD[I, T]) Replace(
	oldMin, oldMax I, oldData T,
	newMin, newMax I, newData T,
)

Replace an item in the structure. This is effectively just a Delete followed by an Insert. But for some structures it may be possible to optimize the operation to avoid multiple passes

func (*OneD[I, T]) Scan

func (tr *OneD[I, T]) Scan(iter func(min, max I, data T) bool)

Scan iterates through all data in tree in no specified order.

func (*OneD[I, T]) Search

func (tr *OneD[I, T]) Search(
	min, max I,
	iter func(min, max I, data T) bool,
)

Search the structure for items that intersects the rect param

type ValueType

type ValueType interface {
	~int | ~int8 | ~int16 | ~int32 | ~int64 |
		~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr |
		~float32 | ~float64 |
		~string
}

Jump to

Keyboard shortcuts

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