rtree

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MBRToTuple

func MBRToTuple(m MBR) tuple.Tuple

MBRToTuple serializes an MBR to a flat tuple [low0, ..., lowN-1, high0, ..., highN-1]. Matches Java's ChildSlot MBR serialization.

Types

type ArithmeticError

type ArithmeticError struct{ Message string }

ArithmeticError is Java's ArithmeticException.

func (*ArithmeticError) Error

func (e *ArithmeticError) Error() string

type ChildSlot

type ChildSlot struct {
	SmallestHV  *big.Int
	SmallestKey tuple.Tuple
	LargestHV   *big.Int
	LargestKey  tuple.Tuple
	ChildID     []byte
	ChildMBR    MBR
}

ChildSlot is an intermediate node slot referencing a child node.

func (ChildSlot) GetMBR

func (s ChildSlot) GetMBR() MBR

GetMBR returns the MBR of the child subtree.

type IndexOutOfBoundsError

type IndexOutOfBoundsError struct{ Index, Length int }

IndexOutOfBoundsError is Java's IndexOutOfBoundsException.

func (*IndexOutOfBoundsError) Error

func (e *IndexOutOfBoundsError) Error() string

type ItemSlot

type ItemSlot struct {
	HilbertValue *big.Int
	Point        Point
	KeySuffix    tuple.Tuple
	Value        tuple.Tuple
}

ItemSlot is a leaf node slot containing a data item.

func (ItemSlot) GetMBR

func (s ItemSlot) GetMBR() MBR

GetMBR returns the MBR for this item (a degenerate point MBR).

func (ItemSlot) ItemKey

func (s ItemSlot) ItemKey() tuple.Tuple

ItemKey returns the combined item key (point coordinates + suffix).

type MBR

type MBR struct {
	Low  []int64
	High []int64
}

MBR is a minimum bounding rectangle for N dimensions. Stored as [low0, low1, ..., lowN-1, high0, high1, ..., highN-1].

func MBRFromPoint

func MBRFromPoint(p Point) MBR

MBRFromPoint creates a degenerate MBR containing only a single point.

func MBRFromTuple

func MBRFromTuple(t tuple.Tuple, numDimensions int) (MBR, error)

MBRFromTuple deserializes an MBR from a flat tuple.

func (MBR) ContainsPoint

func (m MBR) ContainsPoint(p Point) bool

ContainsPoint returns true if the MBR contains the given point.

func (MBR) NumDimensions

func (m MBR) NumDimensions() int

NumDimensions returns the number of dimensions.

func (MBR) Overlaps

func (m MBR) Overlaps(other MBR) bool

Overlaps returns true if this MBR overlaps with another. Returns false if the MBRs have different numbers of dimensions.

func (MBR) Union

func (m MBR) Union(other MBR) MBR

Union returns the smallest MBR containing both this and other. If the MBRs have different numbers of dimensions, returns self unchanged.

type NegativeArraySizeError

type NegativeArraySizeError struct{ Size int }

NegativeArraySizeError is Java's NegativeArraySizeException.

func (*NegativeArraySizeError) Error

func (e *NegativeArraySizeError) Error() string

type NodeKind

type NodeKind byte

NodeKind identifies a node as leaf or intermediate.

const (
	NodeKindLeaf         NodeKind = 0x00
	NodeKindIntermediate NodeKind = 0x01
)

type NullPointerError

type NullPointerError struct{}

NullPointerError is Java's NullPointerException, from Objects.requireNonNull with no message.

func (*NullPointerError) Error

func (*NullPointerError) Error() string

type Point

type Point struct {
	Coordinates tuple.Tuple
}

Point represents an N-dimensional point with int64 coordinates. Null coordinates are represented as nil in the tuple.

func (Point) Coordinate

func (p Point) Coordinate(dim int) int64

Coordinate returns the coordinate at the given dimension index, or MinInt64 if nil.

func (Point) NumDimensions

func (p Point) NumDimensions() int

NumDimensions returns the number of dimensions.

type RTree

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

RTree is a Hilbert R-tree backed by FDB. Matches Java's com.apple.foundationdb.async.rtree.RTree.

func NewRTree

func NewRTree(storage *StorageAdapter, config RTreeConfig) (*RTree, error)

NewRTree creates a new R-tree. Like Java's RTree it takes any minM, maxM and splitS: a configuration that cannot keep the node invariants fails at the operation where Java's fails (see errors.go).

func (*RTree) Clear

func (rt *RTree) Clear(tx fdb.WritableTransaction) error

Clear removes all data from the R-tree.

func (*RTree) Delete

func (rt *RTree) Delete(tx fdb.WritableTransaction, point Point, keySuffix tuple.Tuple) error

Delete removes an item from the R-tree. Matches Java's RTree.delete().

func (*RTree) InsertOrUpdate

func (rt *RTree) InsertOrUpdate(tx fdb.WritableTransaction, point Point, keySuffix tuple.Tuple, value tuple.Tuple) error

InsertOrUpdate inserts a new item or updates an existing one. Matches Java's RTree.insertOrUpdate().

func (*RTree) Scan

func (rt *RTree) Scan(tx fdb.ReadTransaction, lastHV *big.Int, lastKey tuple.Tuple, mbrPredicate func(MBR) bool) ([]ItemSlot, error)

Scan returns all items matching the MBR predicate, starting after (lastHV, lastKey). Items are returned in Hilbert value order. Convenience wrapper around ScanIterator.

func (*RTree) ScanIterator

func (rt *RTree) ScanIterator(tx fdb.ReadTransaction, lastHV *big.Int, lastKey tuple.Tuple, mbrPredicate func(MBR) bool) *RTreeIterator

ScanIterator returns a lazy iterator over items matching the MBR predicate, starting after (lastHV, lastKey). Items are yielded one at a time in Hilbert value order. Only fetches leaf nodes from FDB on demand.

type RTreeConfig

type RTreeConfig struct {
	MinM               int          // Min slots per non-root node (default 16)
	MaxM               int          // Max slots per node (default 32)
	SplitS             int          // Siblings involved in split/fuse (default 2)
	Storage            RTreeStorage // Node layout (default BY_NODE)
	StoreHilbertValues bool         // Store HV in leaf slots (default true)
	UseNodeSlotIndex   bool         // Maintain the node slot index (default false)
	NumDimensions      int          // Number of spatial dimensions
}

RTreeConfig configures the R-tree behavior. Matches Java's RTree.Config.

func DefaultRTreeConfig

func DefaultRTreeConfig(numDimensions int) RTreeConfig

DefaultRTreeConfig returns the default R-tree configuration, Java's RTree.DEFAULT_CONFIG.

type RTreeIterator

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

RTreeIterator lazily walks the R-tree depth-first in Hilbert order, fetching one leaf node at a time from FDB.

func (*RTreeIterator) Next

func (it *RTreeIterator) Next() (ItemSlot, bool, error)

Next returns the next item from the iterator. Returns (item, true, nil) on success, (zero, false, nil) when exhausted, or (zero, false, err) on error.

type RTreeStorage

type RTreeStorage string

RTreeStorage is Java's RTree.Storage: how a node's slots are laid out.

const (
	// RTreeStorageByNode stores a node as one key/value pair, its slots a
	// nested tuple in the value (Java's ByNodeStorageAdapter). The default.
	RTreeStorageByNode RTreeStorage = "BY_NODE"
	// RTreeStorageBySlot stores each slot of a node as its own key/value pair
	// under the node's key (Java's BySlotStorageAdapter).
	RTreeStorageBySlot RTreeStorage = "BY_SLOT"
)

type StorageAdapter

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

StorageAdapter serializes R-tree nodes in FDB in the layout the index's StorageAdapter option names (RTreeConfig.Storage):

  • BY_NODE (Java's ByNodeStorageAdapter): each node is one key-value pair, subspace.pack(nodeId) → tuple(nodeKind, slotList), slotList a nested tuple holding each slot as a sub-tuple (its key items, then its value items).
  • BY_SLOT (Java's BySlotStorageAdapter): each slot is its own pair under the node, subspace.pack(nodeId, nodeKind, slotKey...) → tuple(slotValue...).

With the rtreeUseNodeSlotIndex option it also maintains Java's node slot index (NodeSlotIndexAdapter): an empty-valued key (level, largestHilbertValue, largestKey items..., childId) in the index's secondary subspace for every child slot of every intermediate node, level being the child's (a leaf is level 0). The index is a function of the tree alone, so Go maintains it as the difference the operation made to the intermediate nodes it touched (flushNodeSlotIndex) rather than per slot change as Java's change sets do; the stored entries are the same.

func NewStorageAdapter

func NewStorageAdapter(ss subspace.Subspace, config RTreeConfig) *StorageAdapter

func (*StorageAdapter) WithEnv

func (s *StorageAdapter) WithEnv(env *dst.Env) *StorageAdapter

WithEnv routes node-ID entropy through env (nil keeps production).

func (*StorageAdapter) WithNodeSlotIndex

func (s *StorageAdapter) WithNodeSlotIndex(sub subspace.Subspace) *StorageAdapter

WithNodeSlotIndex sets the node slot index's subspace, which an R-tree with the rtreeUseNodeSlotIndex option maintains.

type VerifyError

type VerifyError struct{}

VerifyError is Guava's VerifyException from one of RTree's Verify.verify checks, which carry no message.

func (*VerifyError) Error

func (*VerifyError) Error() string

Jump to

Keyboard shortcuts

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