numi

package
v0.27.2 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2023 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Helper functions for handling integers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Contains

func Contains(slice []int, s int) bool

Checks if given integer exists in the slice.

func Cumsum added in v0.2.5

func Cumsum(slice []int) []int

Calculates a slice of cumulative sum from given slice.

func Delta

func Delta(ints []int) []int

Returns the delta between all consecutive ints. Returned slice length is one item shorter.

func Diff added in v0.20.1

func Diff(a, b []int) []int

Finds the difference in elements between slice A and slice B ; ie. A-B

func FindIndex

func FindIndex(slice []int, val int) (int, bool)

Finds the index of first occurrence of the given value and returns the index and a boolean. Boolean is true when index is found, otherwise index = -1.

func FindMissingIndexes

func FindMissingIndexes(newslice []int, slice []int) (idx []int)

Compares <newslice> against <slice>. Those numbers' indexes from <slice> are collected which are not found from <newslice>.

func GetIndex added in v0.24.0

func GetIndex(slice []int, val int) int

Finds the index of first occurrence of the given value and returns the index. If not found index = -1.

func Insert added in v0.2.3

func Insert(slice []int, idx int, val int) []int

Insert inserts given value to given index into a slice

func Max

func Max(a int, b int) int

Returns the larger of given integers.

func Min

func Min(a int, b int) int

Returns the smaller of given integers.

func NumRange added in v0.16.0

func NumRange(start int, end int, step int) (numberrange []int)

Returns an evenly spaced slice of integers, between <start> and <end> with spacing <step>.

func RandRange

func RandRange(min int, max int) int

Creates a random integer between min and max value.

func Remove added in v0.2.3

func Remove(slice []int, s int) []int

Removes first occurence of given integer from a slice.

func RemoveFrom added in v0.2.3

func RemoveFrom(slice []int, s int) []int

RemoveFrom removes an integer from given index

func ReplaceNil added in v0.22.0

func ReplaceNil(val int, i *int) int

Replaces nil valued *int with given integer

func Select added in v0.21.1

func Select(condition bool, i1, i2 int) int

Returns i1 if condition == TRUE, else returns i2

func SetDefault

func SetDefault(defaultval int, confval int) int

Replaces default value for a parameter, if the configuration value is zero (ie. initialized empty variable). Note that the function does not make any difference, if the configuration is set to zero on purpose.

func SliceOf added in v0.2.5

func SliceOf(value int, size int) []int

SliceOf creates a slice of given size filled with value.

func SwitchIf added in v0.21.0

func SwitchIf(condition bool, i1, i2 int) (int, int)

Returns the given values without changes, if condition == FALSE. Returns the values in switched order, if condition == TRUE.

func Unique

func Unique(t []int) []int

Returns unique integers from given slice.

Types

This section is empty.

Jump to

Keyboard shortcuts

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