Skip to main content

Poindexter

Snider Labs
Go WASM KDTree UEPS

A Go library for spatial indexing - finding things that are near other things, quickly. Used for WASM KDTree lookups in UEPS networking NAT tables. Supports nearest-neighbour, k-nearest, and radius searches with two backends: a gonum-optimised version for speed, or a simpler linear backend. Compiles to WASM so browsers can make peer routing decisions without a server round-trip.

Features

Generic KDTree

KDTree[T] with parameterised payload - nearest-neighbour, k-nearest, radius search, insert/delete by ID

Dual Backend

Gonum backend (median-split with branch-and-bound pruning) or linear backend via WithBackend()

Distance Metrics

Euclidean (L2), Manhattan (L1), Chebyshev (L∞), Cosine, WeightedCosine - extensible via DistanceMetric interface

Point Construction

BuildND/2D/3D/4D helpers with axis inversion, per-axis weighting, ComputeNormStatsND()

Analytics Tracking

TreeAnalytics and PeerAnalytics for operation monitoring

Sorting & Search

SortInts/Strings/Float64s, generic SortBy(), binary search capabilities

Installation

go get github.com/Snider/Poindexter

Usage

KDTree Spatial Search

pts := []poindexter.KDPoint[string]{
    {ID: "A", Coords: []float64{0, 0}, Value: "alpha"},
    {ID: "B", Coords: []float64{1, 1}, Value: "beta"},
    {ID: "C", Coords: []float64{2, 2}, Value: "gamma"},
}

tree, _ := poindexter.NewKDTree(pts,
    poindexter.WithMetric(poindexter.EuclideanDistance{}),
    poindexter.WithBackend(poindexter.BackendGonum),
)

// Find nearest neighbour to query point
nearest := tree.NearestNeighbor([]float64{0.5, 0.5})

// K-nearest neighbours
kNearest := tree.KNearest([]float64{1, 1}, 2)

// Radius search
inRadius := tree.RadiusSearch([]float64{0, 0}, 1.5)

Sorting Utilities

numbers := []int{3, 1, 4, 1, 5, 9}
poindexter.SortInts(numbers)
// Result: [1, 1, 3, 4, 5, 9]

More from Snider Labs

View all projects →

Fancy helping out?

Spotted a bug? Got an idea? We'd love to hear from you.

Read the contributing guide →