common

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2024 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package common contains common types and functions used by the nextroute.

Index

Constants

View Source
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
)
View Source
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.

View Source
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.

View Source
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

View Source
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.

View Source
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.

View Source
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 All deprecated

func All[E any](s []E, condition bool, predicate func(E) bool) bool

All returns true if all the given predicate evaluations evaluate to condition.

Deprecated: This package is deprecated and will be removed in the next major release. Use github.com/nextmv-io/sdk/common instead.

func AllFalse deprecated

func AllFalse[E any](s []E, predicate func(E) bool) bool

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

func AllTrue[E any](s []E, predicate func(E) bool) bool

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

func DefineLazy[T any](f func() T) c.Lazy[T]

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

func DurationValue(
	distance Distance,
	speed Speed,
	timeUnit time.Duration,
) float64

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

func Filter[T any](v []T, f func(T) bool) []T

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

func FindIndex[E any](s []E, predicate func(E) bool) int

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 Has deprecated

func Has[E any](s []E, condition bool, predicate func(E) bool) bool

Has returns true if any of the given predicate evaluations is condition.

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

func HasFalse[E any](s []E, predicate func(E) bool) bool

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

func HasTrue[E any](s []E, predicate func(E) bool) bool

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

func Map[T any, R any](v []T, f func(T) R) []R

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

func MapSlice[T any, R any](v []T, f func(T) []R) []R

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

func NSmallest[T any](items []T, f func(T) float64, n int) []T

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

func RandomElement[T any](
	source *rand.Rand,
	elements []T,
) T

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

func RandomElementIndices[T any](
	source *rand.Rand,
	elements []T,
	n int,
) []int

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

func RandomElements[T any](
	source *rand.Rand,
	elements []T,
	n int,
) []T

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

func RandomIndex(source *rand.Rand, size int, indicesUsed map[int]bool) int

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

func Shuffle[T any](source *rand.Rand, slice []T) []T

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

func Truncate(f float64, unit float64) float64

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

func WithinTolerance(a, b, tolerance float64) bool

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

type Alias = c.Alias

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

func NewAlias(weights []float64) (Alias, error)

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

type Distance = c.Distance

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

func Haversine(from, to Location) (Distance, error)

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

type Location = c.Location

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

func NewLocation(longitude float64, latitude float64) (Location, error)

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

type Locations = c.Locations

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

type Speed = c.Speed

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

func NewSpeed(
	distance float64,
	unit SpeedUnit,
) Speed

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

type SpeedUnit = c.SpeedUnit

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.

Jump to

Keyboard shortcuts

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