numi

package
v0.19.1 Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2021 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 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 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 and returns the result as a new 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 and returns the result as a new slice.

func RemoveFrom added in v0.2.3

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

RemoveFrom removes an integer from given index and returns the result as a new slice.

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