Documentation ¶
Index ¶
- Constants
- Variables
- func Iter(level int, fn func(index uint, cell h3.H3Index))
- func Level0Area() uint
- func Level1Area() uint
- func Level2Area() uint
- func Level3Area() uint
- func Level4Area() uint
- func Level5Area() uint
- func Level6Area() uint
- func ToHash(val uint64) uint64
- type Cell
- type Distributed
- func (d *Distributed) Add(addr string) error
- func (d *Distributed) Addr(vnode uint64) (addr string, ok bool)
- func (d *Distributed) AvgLoad() float64
- func (d *Distributed) EachCell(iter func(c Cell))
- func (d *Distributed) EachVNode(fn func(vnode uint64, addr string) bool)
- func (d *Distributed) IsEmpty() bool
- func (d *Distributed) IsOwned(c Cell) bool
- func (d *Distributed) Lookup(cell h3.H3Index) (Cell, bool)
- func (d *Distributed) LookupFromLatLon(lat float64, lon float64) (c Cell, err error)
- func (d *Distributed) LookupMany(cell []h3.H3Index, iter func(c Cell) bool) bool
- func (d *Distributed) NeighborsFromLatLon(lat float64, lon float64) (target Cell, neighbors []Neighbor, err error)
- func (d *Distributed) Nodes() []string
- func (d *Distributed) NumReplica() int
- func (d *Distributed) Remove(addr string)
- func (d *Distributed) ReplicaFor(cell h3.H3Index, n int) ([]string, error)
- func (d *Distributed) Stats() []NodeInfo
- func (d *Distributed) VNodeIndex(cell h3.H3Index) int
- func (d *Distributed) VNodes() uint64
- func (d *Distributed) WhereIsMyParent(child h3.H3Index) (c Cell, err error)
- type Neighbor
- type NodeInfo
- type Option
Constants ¶
const ( Level0 = iota // number of unique indexes 122 Level1 // number of unique indexes 842 Level2 // number of unique indexes 5882 Level3 // number of unique indexes 41162 Level4 // number of unique indexes 288122 Level5 // number of unique indexes 2016842 Level6 // number of unique indexes 14117882 )
Supported H3 resolutions.
const ( DefaultReplicationFactor = 9 DefaultLoadFactor = 1.25 DefaultVNodes = 64 )
Variables ¶
var ( // ErrNoSlots means that the number of virtual nodes is distributed by 100%. // It is necessary to change the configuration of virtual nodes. ErrNoSlots = errors.New("h3geodist: no distribute slots") // ErrVNodes returns when there are no virtual nodes. ErrVNodes = errors.New("h3geodist: vnodes not found") )
Functions ¶
Types ¶
type Cell ¶
type Cell struct { H3ID h3.H3Index Host string }
Cell is a type to represent a distributed cell with specifying the hostname and H3 Index.
type Distributed ¶
type Distributed struct {
// contains filtered or unexported fields
}
Distributed holds information about nodes, and scheduler of virtual nodes with replicas. Thread-safe.
func Default ¶
func Default() *Distributed
Default creates and returns a new Distributed instance with level - Level5.
func New ¶
func New(cellLevel int, opts ...Option) (*Distributed, error)
New creates and returns a new Distributed instance with specified cell level and options.
func (*Distributed) Addr ¶ added in v0.4.0
func (d *Distributed) Addr(vnode uint64) (addr string, ok bool)
Addr returns the addr of the node by vnode id.
func (*Distributed) AvgLoad ¶
func (d *Distributed) AvgLoad() float64
AvgLoad returns the average load.
func (*Distributed) EachCell ¶
func (d *Distributed) EachCell(iter func(c Cell))
EachCell iterate each distributed cell, calling fn for each cell.
func (*Distributed) EachVNode ¶ added in v0.4.0
func (d *Distributed) EachVNode(fn func(vnode uint64, addr string) bool)
EachVNode iterate each vnode, calling fn for each vnode.
func (*Distributed) IsEmpty ¶
func (d *Distributed) IsEmpty() bool
IsEmpty returns TRUE if the nodes list are empty, otherwise FALSE.
func (*Distributed) IsOwned ¶
func (d *Distributed) IsOwned(c Cell) bool
IsOwned сhecks if the host for a distributed cell has changed.
func (*Distributed) Lookup ¶
func (d *Distributed) Lookup(cell h3.H3Index) (Cell, bool)
Lookup returns distributed cell.
func (*Distributed) LookupFromLatLon ¶
func (d *Distributed) LookupFromLatLon(lat float64, lon float64) (c Cell, err error)
LookupFromLatLon returns distributed cell.
func (*Distributed) LookupMany ¶
func (d *Distributed) LookupMany(cell []h3.H3Index, iter func(c Cell) bool) bool
LookupMany returns a list of distributed cell.
func (*Distributed) NeighborsFromLatLon ¶ added in v0.2.0
func (d *Distributed) NeighborsFromLatLon(lat float64, lon float64) (target Cell, neighbors []Neighbor, err error)
NeighborsFromLatLon returns the current distributed cell for a geographic coordinate and neighbors sorted by distance in descending order. Distance is measured from geographic coordinates to the center of each neighbor.
func (*Distributed) NumReplica ¶
func (d *Distributed) NumReplica() int
NumReplica returns number of replicas.
func (*Distributed) ReplicaFor ¶
func (d *Distributed) ReplicaFor(cell h3.H3Index, n int) ([]string, error)
ReplicaFor returns a list of hosts for replication.
func (*Distributed) Stats ¶
func (d *Distributed) Stats() []NodeInfo
Stats returns load distribution by nodes.
func (*Distributed) VNodeIndex ¶
func (d *Distributed) VNodeIndex(cell h3.H3Index) int
VNodeIndex returns the Index of the virtual node by H3Index.
func (*Distributed) VNodes ¶
func (d *Distributed) VNodes() uint64
VNodes returns number of virtual nodes.
func (*Distributed) WhereIsMyParent ¶
func (d *Distributed) WhereIsMyParent(child h3.H3Index) (c Cell, err error)
WhereIsMyParent finds and returns parent distributed cell. The child object must be less resolution than the parent's parent.
type Neighbor ¶ added in v0.2.0
Neighbor is a type for represent a neighbor distributed cell, with the distance from a target point to the center of each neighbor.
type Option ¶
type Option func(*Distributed)
Option is a type to represent various Distributed options.
func WithLoadFactor ¶
WithLoadFactor sets the number of load factor. Default 1.25.
func WithReplicationFactor ¶
WithReplicationFactor sets the number of replication factor. Default 9. A value less than or equal to 0 is set to 1.
func WithVNodes ¶
WithVNodes sets the number of virtual nodes. Default 64.