CollectionsUtil

Description

static class Tinman.Core.Collections.CollectionsUtil<T>

Helper class for dealing with arrays and generic lists.

Public / Methods

Array​Clear


public static method ArrayClear → (3)

array in : T [ ]

[not-null]
The array to clear.

offset opt : int32 = 0

[>=0]
Offset to first element in array in to clear.

count opt : int32 = -1

[>=-1]
Number of elements in array in to clear. If -1, all remaining elements will be cleared.

Clears the elements of the given array to the default value.

Array​Copy


public static method ArrayCopy → (5)

source in : T [ ]

[not-null]
The source array.

sourceIdx in : int32

[>=0]
Index of first element in source in to copy.

target in : T [ ]

[not-null]
The target array.

targetIdx in : int32

[>=0]
Index of first element in target in to write.

count in : int32

[>=0]
Total number of array elements to copy.

Copies elements from one array to another.

Array​Of


public static method ArrayOf → (1)

elements in : IEnumerable<T>

The elements.

returns → T [ ]

The array or null iff elements in is null.

Creates an array of the given elements.

Binary​Search

2 overloads


[Pure]
public static method BinarySearch1 → (3)

value in : T

The value to search.

array in : T [ ]

[not-null]
The array (must be sorted in ascending order).

comparer in : CompareDelegate<T>

[not-null]
The compare to use.

returns → int32

Index of the array element that equals value in. If the value has not been found in the array, -idx-1 is returned, where idx is the insertion index of value in.

Runs a binary search for value in in the given array.


[Pure]
public static method BinarySearch2 → (5)

value in : T

The value to search.

array in : T [ ]

[not-null]
The array (must be sorted in ascending order).

offset in : int32

[>=0]
Index of first array element to search.

count in : int32

[>=0]
Length of array range to search.

compare in : CompareDelegate<T>

[not-null]
The compare to use.

returns → int32

Index of the array element that equals value in. If the value has not been found in the array, -idx-1 is returned, where idx is the insertion index of value in.

Runs a binary search for value in in the given array.

Choose


[Pure]
public static method Choose → (5)

idx in : int32

[0..3]
The index.

idx0 in : T

The value to return if idx in is 0.

idx1 in : T

The value to return if idx in is 1.

idx2 in : T

The value to return if idx in is 2.

idx3 in : T

The value to return if idx in is 3.

returns → T

The value chosen by idx in.

Chooses one of the four values by the given index.

Concatenate

4 overloads


public static method Concatenate1 → (2)

first in : T

The first array element.

second in : T

The second array element.

returns → T [ ]

The resulting array.

Concatenates the given array elements.


public static method Concatenate2 → (2)

first in : T

The first array element.

second in : T [ ]

[not-null]
The second array elements.

returns → T [ ]

The resulting array.

Concatenates the given array elements.


public static method Concatenate3 → (2)

first in : T [ ]

[not-null]
The first array elements.

second in : T

The second array element.

returns → T [ ]

The resulting array.

Concatenates the given array elements.


public static method Concatenate4 → (2)

first in : T [ ]

[not-null]
The first array elements.

second in : T [ ]

[not-null]
The second array elements.

returns → T [ ]

The resulting array.

Concatenates the given array elements.

Equals​Array


[Pure]
public static method EqualsArray → (3)

first in : T [ ]

The first array or null.

second in : T [ ]

The second array or null.

equals opt : EqualsDelegate<T> = null

Optional equality compare.

returns → bool

true if both arrays contain the same elements, false if not.

Checks if the given arrays are equal.

The given array references are equal if one of the following conditions is true:

  • They refer to the same array instance.

  • They are both null.

  • The two arrays contain the same sequence of elements, where element equality is defined by the given equals opt delegate.

Equals​Collection


[Pure]
public static method EqualsCollection → (2)

first in : IBagConst<T>

First collection.

second in : IBagConst<T>

Second collection.

returns → bool

true if both collections are equal, false if not.

Checks if the given collections are equal.

The given collection references are equal if one of the following conditions is true:

  • They refer to the same collection instance.

  • They are both null.

  • first in contains all elements of second in and vice-versa, which includes the case that both collections are empty.

Equals​List


[Pure]
public static method EqualsList → (2)

first in : IVectorConst<T>

First list.

second in : IVectorConst<T>

Second list.

returns → bool

true if both lists are equal, false if not.

Checks if the given lists are equal.

The given list references are equal if one of the following conditions is true:

  • They refer to the same list instance.

  • They are both null.

  • The two lists contain the same sequence of elements, where element equality is determined by the IEquatable implementation of the given IVectorConst objects.

Grow​To


[Pure]
public static method GrowTo → (3)

array in : T [ ]

The array to grow.

count in : int32

[>=0]
Number of valid elements in array in.

length in : int64

[>=0]
New array length.

returns → T [ ]

The grown array.

Grows the given array to the specified length.

Grow​Until


[Pure]
public static method GrowUntil → (3)

array in : T [ ]

The array to grow.

count in : int32

[>=0]
Number of valid elements in array in.

length in : int64

[>=0]
New array length (minimum).

returns → T [ ]

The grown array.

Proportionally grows the given array until its length is equal to or greater than the specified length.

The new array length is computed as follows:

newLength := max(length, currentLength * 5 / 4)

where newLength is the length of the returned array, length is the value of the length in parameter and currentLength is the length of the given array in.

If count in is greater than zero, all array elements in the range [0..count-1] are copied from the given array in to the newly allocated one.

Index​Of

2 overloads


public static method IndexOf1 → (3)

value in : T

The value to find in array in.

array in : T [ ]

[not-null]
The array to search.

equals opt : EqualsDelegate<T> = null

Optional equality compare.

returns → int32

The index of the found array element or -1 iff not found.

Finds the smallest index of the array element that is equal to the given value.


public static method IndexOf2 → (5)

value in : T

The value to find in array in.

array in : T [ ]

[not-null]
The array to search.

offset in : int32

[0..array.Length]
Offset into array in to first element to search.

count in : int32

[0..array.Length-offset]
Number of elements in array in to search.

equals opt : EqualsDelegate<T> = null

Optional equality compare.

returns → int32

The index of the found array element or -1 iff not found.

Finds the smallest index of the array element that is equal to the given value.

Shuffle


public static method Shuffle → (4)

random in : RandomNumber

[not-null]
The random number generator to use.

array in : T [ ]

[not-null]
The array to shuffle.

offset opt : int32 = 0

[0..array.Length]
Offset to first element in array in to shuffle. Defaults to 0.

count opt : int32 = -1

[-1..array.Length-offset]
Number of elements to shuffle, beginning at offset opt. If -1, all elements up to the end of the array in will be shuffled.

Shuffles the elements of the given array randomly.

Shuffle​List


public static method ShuffleList → (4)

random in : RandomNumber

[not-null]
The random number generator to use.

list in : IVector<T>

[not-null]
The list to shuffle.

offset opt : int32 = 0

[0..list.Count]
Offset to first element in list in to shuffle.

count opt : int32 = -1

[-1..list.Count-offset]
Number of elements to shuffle, beginning at offset opt. If -1, all elements up to the end of the list in will be shuffled.

Shuffles the elements of the given list randomly.

Sort

2 overloads


public static method Sort1 → (2)

array in : T [ ]

[not-null]
The array that holds the range to sort.

comparer in : CompareDelegate<T>

[not-null]
The compare to use.

returns → T [ ]

The sorted input array in.

Sorts the given array range.

The method uses an unstable hybrid quicksort (median-3 pivot) / insertion sort algorithm.


public static method Sort2 → (4)

array in : T [ ]

[not-null]
The array that holds the range to sort.

offset in : int32

[>=0]
Offset into array in to first element in range.

count in : int32

[>=0]
Total number of elements in range.

comparer in : CompareDelegate<T>

[not-null]
The compare to use.

returns → T [ ]

The sorted input array in.

Sorts the given array range.

The method uses an unstable hybrid quicksort (median-3 pivot) / insertion sort algorithm.

Sort4


[Pure]
public static method Sort4 → (5)

d0 in : T

First value to sort.

d1 in : T

Second value to sort.

d2 in : T

Third value to sort.

d3 in : T

Fourth value to sort.

compare in : CompareDelegate<T>

[not-null]
The compare to use.

returns → Vec4I

The sort order:
Vec4I.X: sort order index of d0 in
Vec4I.Y: sort order index of d1 in
Vec4I.Z: sort order index of d2 in
Vec4I.W: sort order index of d3 in

Sorts the given values.

Sort​Index

2 overloads


public static method SortIndex1 → (3)

array in : T [ ]

[not-null]
The array that holds the elements to compare. This array will not be modified.

indices in : int32 [ ]

[not-null]
The array indices to be sorted (the values in this array are used to access array in).

comparer in : CompareDelegate<T>

[not-null]
The compare to use.

returns → T [ ]

The sorted input array in.

Sorts the given array range.

The method uses a stable hybrid quicksort (median-3 pivot) / insertion sort algorithm.


public static method SortIndex2 → (5)

array in : T [ ]

[not-null]
The array that holds the elements to compare. This array will not be modified.

indices in : int32 [ ]

[not-null]
The array indices to be sorted (the values in this array are used to access array in).

offset in : int32

[>=0]
Offset into array in to first element in range.

count in : int32

[>=0]
Total number of elements in range.

comparer in : CompareDelegate<T>

[not-null]
The compare to use.

returns → T [ ]

The sorted input array in.

Sorts the given array range.

The method uses a stable hybrid quicksort (median-3 pivot) / insertion sort algorithm.

Sort​List

2 overloads


public static method SortList1 → (2)

list in : IVector<T>

[not-null]
The list that holds the range to sort.

comparer in : CompareDelegate<T>

[not-null]
The compare to use.

returns → IVector<T>

The sorted input list in.

Sorts the given list range.

The method uses an unstable hybrid quicksort (median-3 pivot) / insertion sort algorithm.


public static method SortList2 → (4)

list in : IVector<T>

[not-null]
The list that holds the range to sort.

offset in : int32

[>=0]
Offset into list in to first element in range.

count in : int32

[>=0]
Total number of elements in range.

comparer in : CompareDelegate<T>

[not-null]
The compare to use.

returns → IVector<T>

The sorted input list in.

Sorts the given list range.

The method uses an unstable hybrid quicksort (median-3 pivot) / insertion sort algorithm.

Wrap

2 overloads


[Pure]
public static method Wrap1 → (1)

element in : T

The list element.

returns → IVectorConst<T>

The list.

Returns a new list that initially holds the given element.


public static method Wrap2 → (3)

array in : T [ ]

The array to wrap.

count opt : int32 = -1

The number of array elements to wrap. If negative, the whole array will be wrapped.

equals opt : EqualsDelegate<T> = null

The equality delegate.

returns → IArrayVector<T>

The list object or null if array in is null.

Returns a IVectorConst object that wraps the given array.

The list will use the given array, no elements will be copied.