All Projects → kyroy → kdtree

kyroy / kdtree

Licence: Apache-2.0 License
A k-d tree implementation in Go.

Programming Languages

go
31211 projects - #10 most used programming language

Projects that are alternatives of or similar to kdtree

kdtree-rs
K-dimensional tree in Rust for fast geospatial indexing and lookup
Stars: ✭ 137 (+39.8%)
Mutual labels:  tree, nearest-neighbor-search
pynanoflann
Unofficial python wrapper to the nanoflann k-d tree
Stars: ✭ 24 (-75.51%)
Mutual labels:  nearest-neighbor-search, kdtree
react
Basic Primitives Diagrams for React. Data visualization components library that implements organizational chart and multi-parent dependency diagrams.
Stars: ✭ 15 (-84.69%)
Mutual labels:  tree
xmas-tree
XMAS Tree from stacked ws2812 rings driven by a Digispark
Stars: ✭ 22 (-77.55%)
Mutual labels:  tree
Dolphinn
High Dimensional Approximate Near(est) Neighbor
Stars: ✭ 32 (-67.35%)
Mutual labels:  nearest-neighbor-search
wlui
wl-ui 精美易用的前端复杂组件解决方案。Beautiful and easy-to-use front-end complex component solution
Stars: ✭ 32 (-67.35%)
Mutual labels:  tree
AdTree
Accurate, Detailed, and Automatic Modelling of Laser-Scanned Trees
Stars: ✭ 88 (-10.2%)
Mutual labels:  tree
react-native-nested-listview
A UI component for React Native for representing nested arrays of N levels
Stars: ✭ 163 (+66.33%)
Mutual labels:  tree
php-tools
Some code snippets that are often used in PHP
Stars: ✭ 25 (-74.49%)
Mutual labels:  tree
geeks-for-geeks-solutions
✅ My own Amazon, Microsoft and Google SDE Coding challenge Solutions (offered by GeeksForGeeks).
Stars: ✭ 246 (+151.02%)
Mutual labels:  tree
knn-cpp
A header-only C++ library for k nearest neighbor search with Eigen3.
Stars: ✭ 25 (-74.49%)
Mutual labels:  nearest-neighbor-search
go-inet
A Go library for reading, formatting, sorting, lookup and converting IP-addresses and IP-blocks
Stars: ✭ 14 (-85.71%)
Mutual labels:  tree
AlgoDaily
just for fun
Stars: ✭ 118 (+20.41%)
Mutual labels:  tree
SWDM
SIGIR 2017: Embedding-based query expansion for weighted sequential dependence retrieval model
Stars: ✭ 35 (-64.29%)
Mutual labels:  nearest-neighbor
pscircle
https://gitlab.com/mildlyparallel/pscircle visualizes Linux processes in a form of radial tree.
Stars: ✭ 33 (-66.33%)
Mutual labels:  tree
ann-benchmarks
Benchmarking approximate nearest neighbors. Note: This is an archived version from our SISAP 2017 paper, see below.
Stars: ✭ 30 (-69.39%)
Mutual labels:  nearest-neighbor-search
myleetcode
♨️ Detailed Java & Python solution of LeetCode.
Stars: ✭ 34 (-65.31%)
Mutual labels:  tree
tree.hh
An STL-like C++ header-only tree library
Stars: ✭ 79 (-19.39%)
Mutual labels:  tree
atom-file-bookmark
Bookmark files in your project for quick access
Stars: ✭ 16 (-83.67%)
Mutual labels:  tree
EurekaTrees
Visualizes the Random Forest debug string from the MLLib in Spark using D3.js
Stars: ✭ 37 (-62.24%)
Mutual labels:  tree

kdtree

GoDoc Build Status Codecov Go Report Card License

A k-d tree implementation in Go with:

  • n-dimensional points
  • k-nearest neighbor search
  • range search
  • remove without rebuilding the whole subtree
  • data attached to the points
  • using own structs by implementing a simple 2 function interface

Usage

go get github.com/kyroy/kdtree
import "github.com/kyroy/kdtree"

Implement the kdtree.Point interface

// Point specifies one element of the k-d tree.
type Point interface {
	// Dimensions returns the total number of dimensions
	Dimensions() int
	// Dimension returns the value of the i-th dimension
	Dimension(i int) float64
}

points.Point2d

type Data struct {
	value string
}

func main() {
	tree := kdtree.New([]kdtree.Point{
		&points.Point2D{X: 3, Y: 1},
		&points.Point2D{X: 5, Y: 0},
		&points.Point2D{X: 8, Y: 3},
	})

	// Insert
	tree.Insert(&points.Point2D{X: 1, Y: 8})
	tree.Insert(&points.Point2D{X: 7, Y: 5})

	// KNN (k-nearest neighbor)
	fmt.Println(tree.KNN(&points.Point{Coordinates: []float64{1, 1, 1}}, 2))
	// [{3.00 1.00} {5.00 0.00}]
	
	// RangeSearch
	fmt.Println(tree.RangeSearch(kdrange.New(1, 8, 0, 2)))
	// [{5.00 0.00} {3.00 1.00}]
    
	// Points
	fmt.Println(tree.Points())
	// [{3.00 1.00} {1.00 8.00} {5.00 0.00} {8.00 3.00} {7.00 5.00}]

	// Remove
	fmt.Println(tree.Remove(&points.Point2D{X: 5, Y: 0}))
	// {5.00 0.00}

	// String
	fmt.Println(tree)
	// [[{1.00 8.00} {3.00 1.00} [<nil> {8.00 3.00} {7.00 5.00}]]]

	// Balance
	tree.Balance()
	fmt.Println(tree)
	// [[[{3.00 1.00} {1.00 8.00} <nil>] {7.00 5.00} {8.00 3.00}]]
}

n-dimensional Points (points.Point)

type Data struct {
	value string
}

func main() {
    tree := kdtree.New([]kdtree.Point{
        points.NewPoint([]float64{7, 2, 3}, Data{value: "first"}),
        points.NewPoint([]float64{3, 7, 10}, Data{value: "second"}),
        points.NewPoint([]float64{4, 6, 1}, Data{value: "third"}),
    })
    
    // Insert
    tree.Insert(points.NewPoint([]float64{12, 4, 6}, Data{value: "fourth"}))
    tree.Insert(points.NewPoint([]float64{8, 1, 0}, Data{value: "fifth"}))
    
    // KNN (k-nearest neighbor)
    fmt.Println(tree.KNN(&points.Point{Coordinates: []float64{1, 1, 1}}, 2))
    // [{[4 6 1] {third}} {[7 2 3] {first}}]
    
    // RangeSearch
    fmt.Println(tree.RangeSearch(kdrange.New(1, 15, 1, 5, 0, 5)))
    // [{[7 2 3] {first}} {[8 1 0] {fifth}}]
    
    // Points
    fmt.Println(tree.Points())
    // [{[3 7 10] {second}} {[4 6 1] {third}} {[8 1 0] {fifth}} {[7 2 3] {first}} {[12 4 6] {fourth}}]

    // Remove
    fmt.Println(tree.Remove(points.NewPoint([]float64{3, 7, 10}, nil)))
    // {[3 7 10] {second}}

    // String
    fmt.Println(tree)
    // [[<nil> {[4 6 1] {third}} [{[8 1 0] {fifth}} {[7 2 3] {first}} {[12 4 6] {fourth}}]]]

    // Balance
    tree.Balance()
    fmt.Println(tree)
    // [[[{[7 2 3] {first}} {[4 6 1] {third}} <nil>] {[8 1 0] {fifth}} {[12 4 6] {fourth}}]]
}
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].