world

package
v0.0.3-alpha Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	LocationErrorRequiredId        = errors.New("location id is required")
	LocationErrorInvalidLatitude   = errors.New("invalid latitude")
	LocationErrorInvalidLongitude  = errors.New("invalid longitude")
	LocationErrorRequiredNamespace = errors.New("namespace is required")
)
View Source
var (
	TreeErrLocationNil         = errors.New("insertion failed because location is nil")
	TreeErrLocationOutOfBounds = errors.New("insertion failed because location is out of bounds")
)
View Source
var (
	NamespaceErrorNotFound = errors.New("namespace not found")
)

Functions

This section is empty.

Types

type Location

type Location struct {
	Node *TreeNode
	// contains filtered or unexported fields
}

func NewLocation

func NewLocation(ns string, id string, lat float64, lon float64) (*Location, error)

func (*Location) Id

func (l *Location) Id() string

func (*Location) Lat

func (l *Location) Lat() float64

func (*Location) Lon

func (l *Location) Lon() float64

func (*Location) Ns

func (l *Location) Ns() string

func (*Location) String

func (l *Location) String() string

func (*Location) Update

func (l *Location) Update(lat float64, lon float64) error

func (*Location) UpdatedAt

func (l *Location) UpdatedAt() time.Time

type Namespace

type Namespace struct {
	Name string
	// contains filtered or unexported fields
}

func NewNamespace

func NewNamespace(name string) *Namespace

func (*Namespace) DeleteLocation

func (n *Namespace) DeleteLocation(id string)

func (*Namespace) GetLocation

func (n *Namespace) GetLocation(id string) (*Location, bool)

func (*Namespace) QueryRange

func (n *Namespace) QueryRange(lat1, lat2, lon1, lon2 float64) []*Location

func (*Namespace) SaveLocation

func (n *Namespace) SaveLocation(id string, lat float64, lon float64) (*Location, error)

type QuadTree

type QuadTree struct {
	Root *TreeNode
}

func NewQuadTree

func NewQuadTree(lat1 float64, lat2 float64, lon1 float64, lon2 float64) *QuadTree

func (*QuadTree) Insert

func (q *QuadTree) Insert(location *Location) error

type Stats

type Stats struct {
	Locations int
	Grids     int
}

type TreeNode

type TreeNode struct {
	NE   *TreeNode
	NW   *TreeNode
	SE   *TreeNode
	SW   *TreeNode
	Lat1 float64
	Lat2 float64
	Lon1 float64
	Lon2 float64

	Objects   map[string]*Location
	Capacity  int
	IsDivided bool
	// contains filtered or unexported fields
}

func NewTreeNode

func NewTreeNode(lat1 float64, lat2 float64, lon1 float64, lon2 float64, capacity int) *TreeNode

func (*TreeNode) Delete

func (node *TreeNode) Delete(id string)

func (*TreeNode) ForceDivide

func (node *TreeNode) ForceDivide(level int)

func (*TreeNode) QueryRange

func (node *TreeNode) QueryRange(lat1 float64, lat2 float64, lon1 float64, lon2 float64) []*Location

type World

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

func NewWorld

func NewWorld() *World

func NewWorldFromBytes

func NewWorldFromBytes(buf []byte) *World

func (*World) Delete

func (m *World) Delete(ns string, locId string)

func (*World) GetLocation

func (m *World) GetLocation(ns string, id string) (Location, bool)

func (*World) Merge

func (m *World) Merge(w *World)

func (*World) QueryRange

func (m *World) QueryRange(ns string, lat1, lat2, lon1, lon2 float64) []*Location

func (*World) Save

func (m *World) Save(ns string, locId string, lat float64, lon float64) error

Save a location to the world. If the location already exists, it will be updated.

func (*World) ToBytes

func (m *World) ToBytes() []byte

Jump to

Keyboard shortcuts

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