region

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2023 License: BSD-2-Clause Imports: 9 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CountryLen

func CountryLen() int

CountryLen returns the number of countries in the countryBins list.

func CreateLinkTable

func CreateLinkTable() (distanceLatency [12][12]int)

CreateLinkTable creates a latency table that maps different region's latencies to all other defined regions. Latency is derived through educated guesses right now without any real world data.

TODO: This table needs better real-world accuracy. Once data is collected

this table can be updated for better accuracy and selection.

func CreateSetLatencyTableWeights

func CreateSetLatencyTableWeights(distanceLatency [12][12]int) [12][12]int

func GetCountryBins

func GetCountryBins() map[string]GeoBin

GetCountryBins returns a copy of the countryBins map.

func GetCountryList

func GetCountryList() []string

GetCountryList returns a list of all country alpha-2 codes.

func OrderNodeTeam

func OrderNodeTeam(nodes []*id.ID, countries map[id.ID]string,
	countryToBins map[string]GeoBin, distanceLatency [12][12]int,
	rng io.Reader) ([]*id.ID, int, error)

func Permute

func Permute(items []*id.ID) [][]*id.ID

Permute is based off of Heap's algorithm found here: https://en.wikipedia.org/wiki/Heap%27s_algorithm.

It runs n! time, but in place in terms of space. As of writing, we use this for permuting all orders of a team, of which team size is small, justifying the high complexity.

Types

type GeoBin

type GeoBin uint8

GeoBin is the numerical representation of a geographical regional.

const (
	NorthAmerica GeoBin = iota
	SouthAndCentralAmerica
	WesternEurope
	CentralEurope
	EasternEurope
	MiddleEast
	NorthernAfrica
	SouthernAfrica
	Russia
	EasternAsia
	WesternAsia
	Oceania
)

func GetCountryBin

func GetCountryBin(countryCode string) (GeoBin, bool)

GetCountryBin return the bin for the given country alpha-2 code.

func GetRegion

func GetRegion(region string) (GeoBin, error)

GetRegion converts the region to a numerical representation.

func (GeoBin) Bytes

func (b GeoBin) Bytes() []byte

Bytes returns the byte representation of the GeoBin.

func (GeoBin) MarshalJSON

func (b GeoBin) MarshalJSON() ([]byte, error)

MarshalJSON allows a GeoBin to be marshaled into JSON. This functions satisfies the json.Marshaler interface.

func (GeoBin) String

func (b GeoBin) String() string

String returns the string representation of the GeoBin. This functions satisfies the fmt.Stringer interface.

func (*GeoBin) UnmarshalJSON

func (b *GeoBin) UnmarshalJSON(data []byte) error

UnmarshalJSON and allows a GeoBin to be marshaled into JSON. This functions satisfies the json.Unmarshaler interface.

Jump to

Keyboard shortcuts

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