Package slices defines various functions useful with slices of any type.
Static methods
staticinlinebinarySearch(_x:Slice<GoInt8>, _target:GoInt8):{_1:Bool, _0:GoInt}
staticinlinebinarySearch(_x:Slice<GoString>, _target:GoString):{_1:Bool, _0:GoInt}
staticinlinebinarySearch(_x:Slice<GoFloat64>, _target:GoFloat64):{_1:Bool, _0:GoInt}
staticinlinebinarySearch(_x:Slice<GoFloat32>, _target:GoFloat32):{_1:Bool, _0:GoInt}
staticinlinebinarySearch(_x:Slice<GoUIntptr>, _target:GoUIntptr):{_1:Bool, _0:GoInt}
staticinlinebinarySearch(_x:Slice<GoUInt64>, _target:GoUInt64):{_1:Bool, _0:GoInt}
staticinlinebinarySearch(_x:Slice<GoUInt32>, _target:GoUInt32):{_1:Bool, _0:GoInt}
staticinlinebinarySearch(_x:Slice<GoUInt16>, _target:GoUInt16):{_1:Bool, _0:GoInt}
staticinlinebinarySearch(_x:Slice<GoUInt8>, _target:GoUInt8):{_1:Bool, _0:GoInt}
staticinlinebinarySearch(_x:Slice<GoInt64>, _target:GoInt64):{_1:Bool, _0:GoInt}
staticinlinebinarySearch(_x:Slice<GoInt32>, _target:GoInt32):{_1:Bool, _0:GoInt}
staticinlinebinarySearch(_x:Slice<GoInt16>, _target:GoInt16):{_1:Bool, _0:GoInt}
BinarySearch searches for target in a sorted slice and returns the position where target is found, or the position where target would appear in the sort order; it also returns a bool saying whether the target is really found in the slice. The slice must be sorted in increasing order.
See also:
staticinlinebinarySearchFunc<E, T_>(_x:Slice<E>, _target:T_, _cmp:(E, T_) ‑> GoInt):{_1:Bool, _0:GoInt}
BinarySearchFunc works like [BinarySearch], but uses a custom comparison function. The slice must be sorted in increasing order, where "increasing" is defined by cmp. cmp should return 0 if the slice element matches the target, a negative number if the slice element precedes the target, or a positive number if the slice element follows the target. cmp must implement the same ordering as the slice, such that if cmp(a, t) < 0 and cmp(b, t) >= 0, then a must precede b in the slice.
See also:
staticinlineclip<E>(_s:Slice<E>):Slice<E>
Clip removes unused capacity from the slice, returning s[:len(s):len(s)].
See also:
staticinlineclone<E>(_s:Slice<E>):Slice<E>
Clone returns a copy of the slice. The elements are copied using assignment, so this is a shallow clone.
See also:
staticinlinecompact(_s:Slice<Comparable>):Slice<Comparable>
Compact replaces consecutive runs of equal elements with a single copy. This is like the uniq command found on Unix. Compact modifies the contents of the slice s and returns the modified slice, which may have a smaller length. When Compact discards m elements in total, it might not modify the elements s[len(s)-m:len(s)]. If those elements contain pointers you might consider zeroing those elements so that objects they reference can be garbage collected.
See also:
staticinlinecompactFunc<E>(_s:Slice<E>, _eq:(E, E) ‑> Bool):Slice<E>
CompactFunc is like [Compact] but uses an equality function to compare elements. For runs of elements that compare equal, CompactFunc keeps the first one.
See also:
staticinlinecompare(_s1:Slice<GoInt8>, _s2:Slice<GoInt8>):GoInt
staticinlinecompare(_s1:Slice<GoString>, _s2:Slice<GoString>):GoInt
staticinlinecompare(_s1:Slice<GoFloat64>, _s2:Slice<GoFloat64>):GoInt
staticinlinecompare(_s1:Slice<GoFloat32>, _s2:Slice<GoFloat32>):GoInt
staticinlinecompare(_s1:Slice<GoUIntptr>, _s2:Slice<GoUIntptr>):GoInt
staticinlinecompare(_s1:Slice<GoUInt64>, _s2:Slice<GoUInt64>):GoInt
staticinlinecompare(_s1:Slice<GoUInt32>, _s2:Slice<GoUInt32>):GoInt
staticinlinecompare(_s1:Slice<GoUInt16>, _s2:Slice<GoUInt16>):GoInt
staticinlinecompare(_s1:Slice<GoUInt8>, _s2:Slice<GoUInt8>):GoInt
staticinlinecompare(_s1:Slice<GoInt64>, _s2:Slice<GoInt64>):GoInt
staticinlinecompare(_s1:Slice<GoInt32>, _s2:Slice<GoInt32>):GoInt
staticinlinecompare(_s1:Slice<GoInt16>, _s2:Slice<GoInt16>):GoInt
Compare compares the elements of s1 and s2, using [cmp.Compare] on each pair of elements. The elements are compared sequentially, starting at index 0, until one element is not equal to the other. The result of comparing the first non-matching elements is returned. If both slices are equal until one of them ends, the shorter slice is considered less than the longer one. The result is 0 if s1 == s2, -1 if s1 < s2, and +1 if s1 > s2.
See also:
staticinlinecompareFunc<E1, E2>(_s1:Slice<E1>, _s2:Slice<E2>, _cmp:(E1, E2) ‑> GoInt):GoInt
CompareFunc is like [Compare] but uses a custom comparison function on each pair of elements. The result is the first non-zero result of cmp; if cmp always returns 0 the result is 0 if len(s1) == len(s2), -1 if len(s1) < len(s2), and +1 if len(s1) > len(s2).
See also:
staticinlinecontains(_s:Slice<Comparable>, _v:Comparable):Bool
staticinlinecontainsFunc<E>(_s:Slice<E>, _f:E ‑> Bool):Bool
ContainsFunc reports whether at least one element e of s satisfies f(e).
See also:
staticinlinedelete<E>(_s:Slice<E>, _i:GoInt, _j:GoInt):Slice<E>
Delete removes the elements s[i:j] from s, returning the modified slice. Delete panics if s[i:j] is not a valid slice of s. Delete is O(len(s)-j), so if many items must be deleted, it is better to make a single call deleting them all together than to delete one at a time. Delete might not modify the elements s[len(s)-(j-i):len(s)]. If those elements contain pointers you might consider zeroing those elements so that objects they reference can be garbage collected.
See also:
staticinlinedeleteFunc<E>(_s:Slice<E>, _del:E ‑> Bool):Slice<E>
DeleteFunc removes any elements from s for which del returns true, returning the modified slice. When DeleteFunc removes m elements, it might not modify the elements s[len(s)-m:len(s)]. If those elements contain pointers you might consider zeroing those elements so that objects they reference can be garbage collected.
See also:
staticinlineequal(_s1:Slice<Comparable>, _s2:Slice<Comparable>):Bool
Equal reports whether two slices are equal: the same length and all elements equal. If the lengths are different, Equal returns false. Otherwise, the elements are compared in increasing index order, and the comparison stops at the first unequal pair. Floating point NaNs are not considered equal.
See also:
staticinlineequalFunc<E1, E2>(_s1:Slice<E1>, _s2:Slice<E2>, _eq:(E1, E2) ‑> Bool):Bool
EqualFunc reports whether two slices are equal using an equality function on each pair of elements. If the lengths are different, EqualFunc returns false. Otherwise, the elements are compared in increasing index order, and the comparison stops at the first index for which eq returns false.
See also:
staticinlinegrow<E>(_s:Slice<E>, _n:GoInt):Slice<E>
Grow increases the slice's capacity, if necessary, to guarantee space for another n elements. After Grow(n), at least n elements can be appended to the slice without another allocation. If n is negative or too large to allocate the memory, Grow panics.
See also:
staticinlineindex(_s:Slice<Comparable>, _v:Comparable):GoInt
Index returns the index of the first occurrence of v in s, or -1 if not present.
See also:
staticinlineindexFunc<E>(_s:Slice<E>, _f:E ‑> Bool):GoInt
IndexFunc returns the first index i satisfying f(s[i]), or -1 if none do.
See also:
staticinlineinsert<E>(_s:Slice<E>, _i:GoInt, _v:Rest<E>):Slice<E>
Insert inserts the values v... into s at index i, returning the modified slice. The elements at s[i:] are shifted up to make room. In the returned slice r, r[i] == v[0], and r[i+len(v)] == value originally at r[i]. Insert panics if i is out of range. This function is O(len(s) + len(v)).
See also:
staticinlineisSorted(_x:Slice<GoInt8>):Bool
staticinlineisSorted(_x:Slice<GoString>):Bool
staticinlineisSorted(_x:Slice<GoFloat64>):Bool
staticinlineisSorted(_x:Slice<GoFloat32>):Bool
staticinlineisSorted(_x:Slice<GoUIntptr>):Bool
staticinlineisSorted(_x:Slice<GoUInt64>):Bool
staticinlineisSorted(_x:Slice<GoUInt32>):Bool
staticinlineisSorted(_x:Slice<GoUInt16>):Bool
staticinlineisSorted(_x:Slice<GoUInt8>):Bool
staticinlineisSorted(_x:Slice<GoInt64>):Bool
staticinlineisSorted(_x:Slice<GoInt32>):Bool
staticinlineisSorted(_x:Slice<GoInt16>):Bool
IsSorted reports whether x is sorted in ascending order.
See also:
staticinlineisSortedFunc<E>(_x:Slice<E>, _cmp:(E, E) ‑> GoInt):Bool
IsSortedFunc reports whether x is sorted in ascending order, with cmp as the comparison function as defined by [SortFunc].
See also:
staticinlinemax(_x:Slice<GoInt8>):GoInt8
staticinlinemax(_x:Slice<GoString>):GoString
staticinlinemax(_x:Slice<GoFloat64>):GoFloat64
staticinlinemax(_x:Slice<GoFloat32>):GoFloat32
staticinlinemax(_x:Slice<GoUIntptr>):GoUIntptr
staticinlinemax(_x:Slice<GoUInt64>):GoUInt64
staticinlinemax(_x:Slice<GoUInt32>):GoUInt32
staticinlinemax(_x:Slice<GoUInt16>):GoUInt16
staticinlinemax(_x:Slice<GoUInt8>):GoUInt8
staticinlinemax(_x:Slice<GoInt64>):GoInt64
staticinlinemax(_x:Slice<GoInt32>):GoInt32
staticinlinemax(_x:Slice<GoInt16>):GoInt16
Max returns the maximal value in x. It panics if x is empty. For floating-point E, Max propagates NaNs (any NaN value in x forces the output to be NaN).
See also:
staticinlinemaxFunc<E>(_x:Slice<E>, _cmp:(E, E) ‑> GoInt):E
MaxFunc returns the maximal value in x, using cmp to compare elements. It panics if x is empty. If there is more than one maximal element according to the cmp function, MaxFunc returns the first one.
See also:
staticinlinemin(_x:Slice<GoInt8>):GoInt8
staticinlinemin(_x:Slice<GoString>):GoString
staticinlinemin(_x:Slice<GoFloat64>):GoFloat64
staticinlinemin(_x:Slice<GoFloat32>):GoFloat32
staticinlinemin(_x:Slice<GoUIntptr>):GoUIntptr
staticinlinemin(_x:Slice<GoUInt64>):GoUInt64
staticinlinemin(_x:Slice<GoUInt32>):GoUInt32
staticinlinemin(_x:Slice<GoUInt16>):GoUInt16
staticinlinemin(_x:Slice<GoUInt8>):GoUInt8
staticinlinemin(_x:Slice<GoInt64>):GoInt64
staticinlinemin(_x:Slice<GoInt32>):GoInt32
staticinlinemin(_x:Slice<GoInt16>):GoInt16
Min returns the minimal value in x. It panics if x is empty. For floating-point numbers, Min propagates NaNs (any NaN value in x forces the output to be NaN).
See also:
staticinlineminFunc<E>(_x:Slice<E>, _cmp:(E, E) ‑> GoInt):E
MinFunc returns the minimal value in x, using cmp to compare elements. It panics if x is empty. If there is more than one minimal element according to the cmp function, MinFunc returns the first one.
See also:
staticinlinereplace<E>(_s:Slice<E>, _i:GoInt, _j:GoInt, _v:Rest<E>):Slice<E>
Replace replaces the elements s[i:j] by the given v, and returns the modified slice. Replace panics if s[i:j] is not a valid slice of s.
See also:
staticinlinesort(_x:Slice<GoInt8>):Void
staticinlinesort(_x:Slice<GoString>):Void
staticinlinesort(_x:Slice<GoFloat64>):Void
staticinlinesort(_x:Slice<GoFloat32>):Void
staticinlinesort(_x:Slice<GoUIntptr>):Void
staticinlinesort(_x:Slice<GoUInt64>):Void
staticinlinesort(_x:Slice<GoUInt32>):Void
staticinlinesort(_x:Slice<GoUInt16>):Void
staticinlinesort(_x:Slice<GoUInt8>):Void
staticinlinesort(_x:Slice<GoInt64>):Void
staticinlinesort(_x:Slice<GoInt32>):Void
staticinlinesort(_x:Slice<GoInt16>):Void
Sort sorts a slice of any ordered type in ascending order. When sorting floating-point numbers, NaNs are ordered before other values.
See also:
staticinlinesortFunc<E>(_x:Slice<E>, _cmp:(E, E) ‑> GoInt):Void
SortFunc sorts the slice x in ascending order as determined by the cmp function. This sort is not guaranteed to be stable. cmp(a, b) should return a negative number when a < b, a positive number when a > b and zero when a == b.
SortFunc requires that cmp is a strict weak ordering. See https://en.wikipedia.org/wiki/Weak_ordering#Strict_weak_orderings.
See also:
staticinlinesortStableFunc<E>(_x:Slice<E>, _cmp:(E, E) ‑> GoInt):Void
SortStableFunc sorts the slice x while keeping the original order of equal elements, using cmp to compare elements in the same way as [SortFunc].
See also: