node

package module
v0.0.0-...-b030805 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2024 License: MIT Imports: 6 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var CSVData string = "" /* 27402628-byte string literal not displayed */
View Source
var DataPoints []City

points from embedded csv

Functions

func Distance

func Distance(city1, city2 City) float64

func Haversine

func Haversine(lat1, lon1, lat2, lon2 float64) float64

Haversine distance between two cities (approximation of the great-circle distance)

func MathEqualWithinAbsRel

func MathEqualWithinAbsRel(a, b float64, absTol float64) bool

func ParseEmbeddedCSV

func ParseEmbeddedCSV() error

This function will parse the embedded csv file into the go binary. If the csv file is lost this go program will still work

Types

type City

type City struct {
	Latitude, Longitude float64
	CityName, Country   string
}

func Median

func Median(cities []City, dim int) City

Get the median city based on the specified dimension (latitude or longitude)

type KDTree

type KDTree struct {
	Root *KDTreeNode
}

func NewKDTree

func NewKDTree(cities []City) *KDTree

NewKDTree initializes a new KD-Tree

func (*KDTree) FindNearestNeighbor

func (tree *KDTree) FindNearestNeighbor(target City) *KDTreeNode

FindNearestNeighbor is a method of KDTree to find the nearest neighbor of a target city

func (*KDTree) NearestNeighbor

func (tree *KDTree) NearestNeighbor(root *KDTreeNode, target City, depth int, best *KDTreeNode, bestDist *float64) *KDTreeNode

Nearest neighbor search in the KD-Tree

type KDTreeNode

type KDTreeNode struct {
	City        City
	Left, Right *KDTreeNode
	Depth       int
}

func BuildKDTree

func BuildKDTree(cities []City, depth int) *KDTreeNode

KD-Tree construction function

Jump to

Keyboard shortcuts

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