util

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2024 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultCapacity = 16

Default capacity for collections (where capacity matters).

Variables

This section is empty.

Functions

func CreateIntListData

func CreateIntListData(arraySize int, seed *int64) (headItems, tailItems, headItemsReverse, tailItemsReverse []int)

func CreateMinMaxTestData

func CreateMinMaxTestData(arraySize int, seed *int64) (data []int, min int, max int)

func CreateRandInt

func CreateRandInt(seed *int64) int

func CreateSerialIntListData

func CreateSerialIntListData(arraySize int, seed *int64) (headItems []int)

func CreateSerialMinMaxTestData

func CreateSerialMinMaxTestData(arraySize int, seed *int64) (data []int, min int, max int)

func CreateSerialSmallIntListData

func CreateSerialSmallIntListData(arraySize int, seed *int64) (headItems, tailItems, headItemsReverse, tailItemsReverse []int)

func CreateSingleIntListData

func CreateSingleIntListData(arraySize int, seed *int64) []int

func CreateSmallIntListData

func CreateSmallIntListData(arraySize int, seed *int64) (headItems, tailItems, headItemsReverse, tailItemsReverse []int)

func CreateTimeListData

func CreateTimeListData(arraySize int, seed *int64) []time.Time

func DeepCopy

func DeepCopy[T any](value T, f functions.DeepCopyFunc[T]) T

func DeepCopySlice

func DeepCopySlice[T any](dest, src []T, f functions.DeepCopyFunc[T])

func DefaultDeepCopy

func DefaultDeepCopy[T any](value T) T

func DefaultPredicate

func DefaultPredicate[T any](T) bool

Default predicate function for anywhere a predicate is required but all elements should be included.

func GetDefaultComparer

func GetDefaultComparer[T any]() functions.ComparerFunc[T]

GetDefaultComparer returns a function to compare two values of types supported by this module.

Return value semantics are that if first value less than second value, the result is a negative integer. If they are equal, the result is zero, else a positive integer. Magniitude of the result is unimportant. This permits a faster compare for signed int values by use of simple subtraction.

func GetLock

func GetLock[T any](c collections.Collection[T]) *sync.RWMutex

func GetTestMinMax

func GetTestMinMax(data []int) (int, int)

func GetVersion

func GetVersion[T any](c collections.Collection[T]) int

func Gosort

func Gosort[T any](values []T, length int, compare functions.ComparerFunc[T])

Gosort sorts values (in-place) with respect to the given ComparerFunc using Go's built in sort.

func GosortDescending

func GosortDescending[T any](values []T, length int, compare functions.ComparerFunc[T])

GosortDescending sorts values (in-place) in descending order with respect to the given ComparerFunc using Go's built in sort.

func Iif

func Iif[T any](pred bool, trueVal T, falseVal T) T

func IndexOf

func IndexOf[T any](slc []T, value T, compare functions.ComparerFunc[T], concurrent bool) (index int)

Get index in slice of given value. Return -1 if no match.

func LastIndexOf

func LastIndexOf[T any](slc []T, value T, compare functions.ComparerFunc[T], concurrent bool) (index int)

Get last index in slice of given value. Return -1 if no match.

func Max

func Max[T any](slc []T, compare functions.ComparerFunc[T], concurrent bool) T

func Min

func Min[T any](slc []T, compare functions.ComparerFunc[T], concurrent bool) T

func PartialCopy

func PartialCopy[T any](source []T, sourceIndex int, dest []T, destIndex int, length int)

As per .NET Array.Copy(Array, Int32, Array, Int32, Int32).

func PartialCopyDeep

func PartialCopyDeep[T any](source []T, sourceIndex int, dest []T, destIndex int, length int, f functions.DeepCopyFunc[T])

As per .NET Array.Copy(Array, Int32, Array, Int32, Int32) but call provided DeepCopy function on every element.

func Reverse

func Reverse[T any](slc []T) []T

Reverse order of slice elements As per .NET Array.Reverse(Array).

func ReverseSubset

func ReverseSubset[T any](slc []T, start, length int) []T

Reverse a subset of slice elements As per .NET Array.Reverse(Array, Int32, Int32).

Types

type ElementType

type ElementType[T any] struct {
	Collection collections.Collection[T]
	Version    int
	ValueP     *T
	local.InternalImpl
}

Concrete representation of Element interface.

func NewElementType

func NewElementType[T any](collection collections.Collection[T], val *T) *ElementType[T]

func (*ElementType[T]) Value

func (e *ElementType[T]) Value() T

func (*ElementType[T]) ValuePtr

func (e *ElementType[T]) ValuePtr() *T

type IteratorBase

type IteratorBase[T any] struct {
	Version    int
	NilElement collections.Element[T]
}

Properties shared by all iterator types.

type SortFunc

type SortFunc[T any] func([]T, int, functions.ComparerFunc[T])

Jump to

Keyboard shortcuts

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