Documentation ¶
Overview ¶
Package common contains common types and functions used by the nextroute.
Index ¶
- Constants
- Variables
- func All[E any](s []E, condition bool, predicate func(E) bool) booldeprecated
- func AllFalse[E any](s []E, predicate func(E) bool) booldeprecated
- func AllTrue[E any](s []E, predicate func(E) bool) booldeprecated
- func CopyMap[M1 ~map[K]V, M2 ~map[K]V, K comparable, V any](destination M1, source M2)deprecated
- func DefensiveCopy[T any](v []T) []Tdeprecated
- func DefineLazy[T any](f func() T) c.Lazy[T]deprecated
- func DurationValue(distance Distance, speed Speed, timeUnit time.Duration) float64deprecated
- func Filter[T any](v []T, f func(T) bool) []Tdeprecated
- func FindIndex[E any](s []E, predicate func(E) bool) intdeprecated
- func GroupBy[T any, K comparable](s []T, f func(T) K) map[K][]Tdeprecated
- func Has[E any](s []E, condition bool, predicate func(E) bool) booldeprecated
- func HasFalse[E any](s []E, predicate func(E) bool) booldeprecated
- func HasTrue[E any](s []E, predicate func(E) bool) booldeprecated
- func Intersect[T comparable](a []T, b []T) []Tdeprecated
- func Keys[M ~map[K]V, K Comparable, V any](m M) []Kdeprecated
- func Map[T any, R any](v []T, f func(T) R) []Rdeprecated
- func MapSlice[T any, R any](v []T, f func(T) []R) []Rdeprecated
- func NSmallest[T any](items []T, f func(T) float64, n int) []Tdeprecated
- func NewDuration(unit DurationUnit) time.Durationdeprecated
- func NotUnique[T comparable](s []T) []Tdeprecated
- func NotUniqueDefined[T any, I comparable](items []T, f func(T) I) []Tdeprecated
- func RandomElement[T any](source *rand.Rand, elements []T) Tdeprecated
- func RandomElementIndices[T any](source *rand.Rand, elements []T, n int) []intdeprecated
- func RandomElements[T any](source *rand.Rand, elements []T, n int) []Tdeprecated
- func RandomIndex(source *rand.Rand, size int, indicesUsed map[int]bool) intdeprecated
- func RangeMap[M ~map[K]V, K Comparable, V any](m M, f func(key K, value V) bool)deprecated
- func Reverse[T any](slice []T) []Tdeprecated
- func Shuffle[T any](source *rand.Rand, slice []T) []Tdeprecated
- func Truncate(f float64, unit float64) float64deprecated
- func Unique[T comparable](s []T) []Tdeprecated
- func UniqueDefined[T any, I comparable](items []T, f func(T) I) []Tdeprecated
- func Values[M ~map[K]V, K Comparable, V any](m M) []Vdeprecated
- func WithinTolerance(a, b, tolerance float64) booldeprecated
- type Aliasdeprecated
- type BoundingBoxdeprecated
- type Comparabledeprecated
- type Distancedeprecated
- type DistanceUnitdeprecated
- type DurationUnitdeprecated
- type FastHaversinedeprecated
- type Locationdeprecated
- type Locationsdeprecated
- type Speeddeprecated
- type SpeedUnitdeprecated
- type Statisticsdeprecated
Constants ¶
const ( // NanoSecond is 1/1,000,000,000 of a second. // // Deprecated: This package is deprecated and will be removed in the next major release. // Use [github.com/nextmv-io/sdk/common] instead. NanoSecond = c.NanoSecond // MicroSecond is 1/1,000,000 of a second. // // Deprecated: This package is deprecated and will be removed in the next major release. // Use [github.com/nextmv-io/sdk/common] instead. MicroSecond = c.MicroSecond // MilliSecond is 1/1,000 of a second.// // Deprecated: This package is deprecated and will be removed in the next major release. // Use [github.com/nextmv-io/sdk/common] instead. MilliSecond = c.MilliSecond // Second is the SI unit of time. // // Deprecated: This package is deprecated and will be removed in the next major release. // Use [github.com/nextmv-io/sdk/common] instead. Second = c.Second // Minute is 60 seconds. // // Deprecated: This package is deprecated and will be removed in the next major release. // Use [github.com/nextmv-io/sdk/common] instead. Minute = c.Minute // Hour is 60 minutes. // // Deprecated: This package is deprecated and will be removed in the next major release. // Use [github.com/nextmv-io/sdk/common] instead. Hour = c.Hour // Day is 24 hours. // // Deprecated: This package is deprecated and will be removed in the next major release. // Use [github.com/nextmv-io/sdk/common] instead. Day = c.Day )
const Kilometers = c.Kilometers
Kilometers is 1000 meters.
Deprecated: This package is deprecated and will be removed in the next major release. Use github.com/nextmv-io/sdk/common instead.
const Meters = c.Meters
Meters is the distance travelled by light in a vacuum in 1/299,792,458 seconds.
Deprecated: This package is deprecated and will be removed in the next major release. Use github.com/nextmv-io/sdk/common instead.
const Miles = c.Miles
Miles is 1609.34 meters.
Deprecated: This package is deprecated and will be removed in the next major release. Use github.com/nextmv-io/sdk/common instead.
Variables ¶
var KilometersPerHour = c.KilometersPerHour
KilometersPerHour is a speed unit of kilometers per hour.
Deprecated: This package is deprecated and will be removed in the next major release. Use github.com/nextmv-io/sdk/common instead.
var MetersPerSecond = c.MetersPerSecond
MetersPerSecond is a speed unit of meters per second.
Deprecated: This package is deprecated and will be removed in the next major release. Use github.com/nextmv-io/sdk/common instead.
var MilesPerHour = c.MilesPerHour
MilesPerHour is a speed unit of miles per hour.
Deprecated: This package is deprecated and will be removed in the next major release. Use github.com/nextmv-io/sdk/common instead.
Functions ¶
func AllFalse
deprecated
AllFalse returns true if all the given predicate evaluations is false.
Deprecated: This package is deprecated and will be removed in the next major release. Use github.com/nextmv-io/sdk/common instead.
func AllTrue
deprecated
AllTrue returns true if all the given predicate evaluations are true.
Deprecated: This package is deprecated and will be removed in the next major release. Use github.com/nextmv-io/sdk/common instead.
func CopyMap
deprecated
added in
v0.23.9
func CopyMap[M1 ~map[K]V, M2 ~map[K]V, K comparable, V any]( destination M1, source M2)
CopyMap copies all key/value pairs in source adding them to destination. If a key exists in both maps, the value in destination is overwritten.
Deprecated: This package is deprecated and will be removed in the next major release. Use github.com/nextmv-io/sdk/common instead.
func DefensiveCopy
deprecated
func DefensiveCopy[T any](v []T) []T
DefensiveCopy returns a defensive copy of a slice.
Deprecated: This package is deprecated and will be removed in the next major release. Use github.com/nextmv-io/sdk/common instead.
func DefineLazy
deprecated
DefineLazy returns a Lazy[T] that will call the given function to calculate the value. The value is only calculated once, and the result is cached for subsequent calls.
Deprecated: This package is deprecated and will be removed in the next major release. Use github.com/nextmv-io/sdk/common instead.
func DurationValue
deprecated
DurationValue returns the value of a duration in the given time unit. Will panic if the time unit is zero.
Deprecated: This package is deprecated and will be removed in the next major release. Use github.com/nextmv-io/sdk/common instead.
func Filter
deprecated
Filter filters a slice using a predicate function.
Deprecated: This package is deprecated and will be removed in the next major release. Use github.com/nextmv-io/sdk/common instead.
func FindIndex
deprecated
FindIndex returns the first index i satisfying predicate(s[i]).
Deprecated: This package is deprecated and will be removed in the next major release. Use github.com/nextmv-io/sdk/common instead.
func GroupBy
deprecated
func GroupBy[T any, K comparable](s []T, f func(T) K) map[K][]T
GroupBy groups the elements of a slice by a key function.
Deprecated: This package is deprecated and will be removed in the next major release. Use github.com/nextmv-io/sdk/common instead.
func HasFalse
deprecated
HasFalse returns true if any of the given predicate evaluations evaluate to false.
Deprecated: This package is deprecated and will be removed in the next major release. Use github.com/nextmv-io/sdk/common instead.
func HasTrue
deprecated
HasTrue returns true if any of the given predicate evaluations evaluate to true.
Deprecated: This package is deprecated and will be removed in the next major release. Use github.com/nextmv-io/sdk/common instead.
func Intersect
deprecated
added in
v0.30.0
func Intersect[T comparable](a []T, b []T) []T
Intersect returns the intersection of two slices.
Deprecated: This package is deprecated and will be removed in the next major release. Use github.com/nextmv-io/sdk/common instead.
func Keys
deprecated
added in
v0.23.9
func Keys[M ~map[K]V, K Comparable, V any](m M) []K
Keys returns a slice of all values in the given map.
Deprecated: This package is deprecated and will be removed in the next major release. Use github.com/nextmv-io/sdk/common instead.
func Map
deprecated
Map maps a slice of type T to a slice of type R using the function f.
Deprecated: This package is deprecated and will be removed in the next major release. Use github.com/nextmv-io/sdk/common instead.
func MapSlice
deprecated
MapSlice maps a slice of type T to a slice of type R using the function f returning a slice of R.
Deprecated: This package is deprecated and will be removed in the next major release. Use github.com/nextmv-io/sdk/common instead.
func NSmallest
deprecated
NSmallest returns the n-smallest items in the slice items using the function f to determine the value of each item. If n is greater than the length of items, all items are returned.
Deprecated: This package is deprecated and will be removed in the next major release. Use github.com/nextmv-io/sdk/common instead.
func NewDuration
deprecated
added in
v0.24.1
func NewDuration(unit DurationUnit) time.Duration
NewDuration returns a new duration by unit.
Deprecated: This package is deprecated and will be removed in the next major release. Use github.com/nextmv-io/sdk/common instead.
func NotUnique
deprecated
added in
v0.26.0
func NotUnique[T comparable](s []T) []T
NotUnique returns the duplicate instances.
Deprecated: This package is deprecated and will be removed in the next major release. Use github.com/nextmv-io/sdk/common instead.
func NotUniqueDefined
deprecated
added in
v0.26.0
func NotUniqueDefined[T any, I comparable](items []T, f func(T) I) []T
NotUniqueDefined returns the instances for which f returns identical values.
Deprecated: This package is deprecated and will be removed in the next major release. Use github.com/nextmv-io/sdk/common instead.
func RandomElement
deprecated
RandomElement returns a random element from the given slice. If the slice is empty, panic is raised. If source is nil, a new source is created using the current time.
Deprecated: This package is deprecated and will be removed in the next major release. Use github.com/nextmv-io/sdk/common instead.
func RandomElementIndices
deprecated
RandomElementIndices returns a slice of n random element indices from the given slice. If n is greater than the length of the slice, all indices are returned. If n is less than or equal to zero, an empty slice is returned. If source is nil, a new source is created using the current time.
Deprecated: This package is deprecated and will be removed in the next major release. Use github.com/nextmv-io/sdk/common instead.
func RandomElements
deprecated
RandomElements returns a slice of n random elements from the given slice. If n is greater than the length of the slice, all elements are returned. If n is less than or equal to zero, an empty slice is returned. If source is nil, a new source is created using the current time.
Deprecated: This package is deprecated and will be removed in the next major release. Use github.com/nextmv-io/sdk/common instead.
func RandomIndex
deprecated
RandomIndex returns a random index from the given size. If the index has already been used, a new index is generated. If source is nil, a new source is created using the current time.
Deprecated: This package is deprecated and will be removed in the next major release. Use github.com/nextmv-io/sdk/common instead.
func RangeMap
deprecated
added in
v0.23.8
func RangeMap[M ~map[K]V, K Comparable, V any]( m M, f func(key K, value V) bool, )
RangeMap ranges over a map in deterministic order by first sorting the keys. It provides a function which will be called for each key/value pair. The function should return true to stop iteration.
Deprecated: This package is deprecated and will be removed in the next major release. Use github.com/nextmv-io/sdk/common instead.
func Reverse
deprecated
added in
v0.29.0
func Reverse[T any](slice []T) []T
Reverse reverses the given slice in place and returns it.
Deprecated: This package is deprecated and will be removed in the next major release. Use github.com/nextmv-io/sdk/common instead.
func Shuffle
deprecated
added in
v0.29.0
Shuffle returns a shuffled copy of the given slice. If source is nil, a new source is created using the current time.
Deprecated: This package is deprecated and will be removed in the next major release. Use github.com/nextmv-io/sdk/common instead.
func Truncate
deprecated
added in
v0.31.0
Truncate truncates a float64 to the given unit.
Deprecated: This package is deprecated and will be removed in the next major release. Use github.com/nextmv-io/sdk/common instead.
func Unique
deprecated
func Unique[T comparable](s []T) []T
Unique is a universal duplicate removal function for type instances in a slice that implement the comparable interface.
Deprecated: This package is deprecated and will be removed in the next major release. Use github.com/nextmv-io/sdk/common instead.
func UniqueDefined
deprecated
func UniqueDefined[T any, I comparable](items []T, f func(T) I) []T
UniqueDefined is a universal duplicate removal function for type instances in a slice that implement the comparable interface. The function f is used to extract the comparable value from the type instance.
Deprecated: This package is deprecated and will be removed in the next major release. Use github.com/nextmv-io/sdk/common instead.
func Values
deprecated
func Values[M ~map[K]V, K Comparable, V any](m M) []V
Values returns a slice of all values in the given map.
Deprecated: This package is deprecated and will be removed in the next major release. Use github.com/nextmv-io/sdk/common instead.
func WithinTolerance
deprecated
WithinTolerance returns true if a and b are within the given tolerance.
Deprecated: This package is deprecated and will be removed in the next major release. Use github.com/nextmv-io/sdk/common instead.
Types ¶
type Alias
deprecated
Alias is an interface that allows for sampling from a discrete distribution in O(1) time.
Deprecated: This package is deprecated and will be removed in the next major release. Use github.com/nextmv-io/sdk/common instead.
func NewAlias
deprecated
NewAlias creates a new Alias from the given weights. The weights must be positive and at least one weight must be given. The weights are normalized to sum to 1. NewAlias([]float64{1, 2, 3}) will return an Alias that will return 0 with probability 1/6, 1 with probability 1/3 and 2 with probability 1/2.
Deprecated: This package is deprecated and will be removed in the next major release. Use github.com/nextmv-io/sdk/common instead.
type BoundingBox
deprecated
added in
v1.0.0
type BoundingBox = c.BoundingBox
BoundingBox contains information about a box.
Deprecated: This package is deprecated and will be removed in the next major release. Use github.com/nextmv-io/sdk/common instead.
func NewBoundingBox
deprecated
added in
v1.0.0
func NewBoundingBox(locations Locations) BoundingBox
NewBoundingBox returns a bounding box for the given locations.
Deprecated: This package is deprecated and will be removed in the next major release. Use github.com/nextmv-io/sdk/common instead.
func NewInvalidBoundingBox
deprecated
added in
v1.0.0
func NewInvalidBoundingBox() BoundingBox
NewInvalidBoundingBox returns an invalid bounding box.
Deprecated: This package is deprecated and will be removed in the next major release. Use github.com/nextmv-io/sdk/common instead.
type Comparable
deprecated
added in
v0.23.8
type Comparable = c.Comparable
Comparable is a type constraint for three types: int, int64, and string. By using this type constraint for a generic parameter, the parameter can be used as a map key and it can be sorted.
Deprecated: This package is deprecated and will be removed in the next major release. Use github.com/nextmv-io/sdk/common instead.
type Distance
deprecated
Distance is a distance in a given unit.
Deprecated: This package is deprecated and will be removed in the next major release. Use github.com/nextmv-io/sdk/common instead.
func Haversine
deprecated
Haversine calculates the distance between two locations using the Haversine formula. Haversine is a good approximation for short distances (up to a few hundred kilometers).
Deprecated: This package is deprecated and will be removed in the next major release. Use github.com/nextmv-io/sdk/common instead.
func NewDistance
deprecated
func NewDistance( value float64, unit DistanceUnit, ) Distance
NewDistance returns a new distance.
Deprecated: This package is deprecated and will be removed in the next major release. Use github.com/nextmv-io/sdk/common instead.
type DistanceUnit
deprecated
type DistanceUnit = c.DistanceUnit
DistanceUnit is the unit of distance.
Deprecated: This package is deprecated and will be removed in the next major release. Use github.com/nextmv-io/sdk/common instead.
type DurationUnit
deprecated
added in
v0.24.1
type DurationUnit = c.DurationUnit
DurationUnit is the unit of duration.
Deprecated: This package is deprecated and will be removed in the next major release. Use github.com/nextmv-io/sdk/common instead.
type FastHaversine
deprecated
type FastHaversine = c.FastHaversine
FastHaversine is a fast approximation of the haversine distance.
Deprecated: This package is deprecated and will be removed in the next major release. Use github.com/nextmv-io/sdk/common instead.
func NewFastHaversine
deprecated
func NewFastHaversine(lat float64) FastHaversine
NewFastHaversine returns a new FastHaversine.
Deprecated: This package is deprecated and will be removed in the next major release. Use github.com/nextmv-io/sdk/common instead.
type Location
deprecated
Location represents a physical location on the earth.
Deprecated: This package is deprecated and will be removed in the next major release. Use github.com/nextmv-io/sdk/common instead.
func NewInvalidLocation
deprecated
func NewInvalidLocation() Location
NewInvalidLocation creates a new invalid Location. Longitude and latitude are not important.
Deprecated: This package is deprecated and will be removed in the next major release. Use github.com/nextmv-io/sdk/common instead.
func NewLocation
deprecated
NewLocation creates a new Location. An error is returned if the longitude is not between (-180, 180) or the latitude is not between (-90, 90).
Deprecated: This package is deprecated and will be removed in the next major release. Use github.com/nextmv-io/sdk/common instead.
type Locations
deprecated
Locations is a slice of Location.
Deprecated: This package is deprecated and will be removed in the next major release. Use github.com/nextmv-io/sdk/common instead.
type Speed
deprecated
Speed is the interface for a speed.
Deprecated: This package is deprecated and will be removed in the next major release. Use github.com/nextmv-io/sdk/common instead.
func NewSpeed
deprecated
NewSpeed creates a new speed.
Deprecated: This package is deprecated and will be removed in the next major release. Use github.com/nextmv-io/sdk/common instead.
type SpeedUnit
deprecated
SpeedUnit represents a unit of speed.
Deprecated: This package is deprecated and will be removed in the next major release. Use github.com/nextmv-io/sdk/common instead.
func NewSpeedUnit
deprecated
func NewSpeedUnit( distanceUnit DistanceUnit, duration time.Duration, ) SpeedUnit
NewSpeedUnit returns a new speed unit.
Deprecated: This package is deprecated and will be removed in the next major release. Use github.com/nextmv-io/sdk/common instead.
type Statistics
deprecated
type Statistics = c.Statistics
Statistics describes statistics.
Deprecated: This package is deprecated and will be removed in the next major release. Use github.com/nextmv-io/sdk/common instead.
func NewStatistics
deprecated
func NewStatistics[T any](v []T, f func(T) float64) Statistics
NewStatistics creates a new statistics object.
Deprecated: This package is deprecated and will be removed in the next major release. Use github.com/nextmv-io/sdk/common instead.