shiftElementsRight
Elements are shifted rightwards (towards higher indices). New elements are added to the left, and the rightmost elements are cut off so that the length of the vector stays the same.
Function parameters
Parameters
- vec:anytype
- amount:VectorCount(@TypeOf(vec))
- shift_in:std.meta.Child(@TypeOf(vec))
Functions in this namespace
Functions
- suggestVectorLength
- Suggests a target-dependant vector length for a given type, or null if scalars are recommended.
- VectorIndex
- Returns the smallest type of unsigned ints capable of indexing any element within the given vector type.
- VectorCount
- Returns the smallest type of unsigned ints capable of holding the length of the given vector type.
- iota
- Returns a vector containing the first `len` integers in order from 0 to `len`-1.
- repeat
- Returns a vector containing the same elements as the input, but repeated until the desired length is reached.
- join
- Returns a vector containing all elements of the first vector at the lower indices followed by all elements of the second vector
- interlace
- Returns a vector whose elements alternates between those of each input vector.
- deinterlace
- The contents of `interlaced` is evenly split between vec_count vectors that are returned as an array.
- mergeShift
- Joins two vectors, shifts them leftwards (towards lower indices) and extracts the leftmost elements into a vector the length of a and b.
- shiftElementsRight
- Elements are shifted rightwards (towards higher indices).
- shiftElementsLeft
- Elements are shifted leftwards (towards lower indices).
- rotateElementsLeft
- Elements are shifted leftwards (towards lower indices).
- rotateElementsRight
- Elements are shifted rightwards (towards higher indices).
- prefixScanWithFunc
- Same as prefixScan, but with a user-provided, mathematically associative function.
- prefixScan
- Returns a vector whose elements are the result of performing the specified operation on the corresponding
Source
Implementation
pub fn shiftElementsRight(vec: anytype, comptime amount: VectorCount(@TypeOf(vec)), shift_in: std.meta.Child(@TypeOf(vec))) @TypeOf(vec) {
// It may be possible to implement shifts and rotates with a runtime-friendly slice of two joined vectors, as the length of the
// slice would be comptime-known. This would permit vector shifts and rotates by a non-comptime-known amount.
// However, I am unsure whether compiler optimizations would handle that well enough on all platforms.
const V = @TypeOf(vec);
const len = vectorLength(V);
return mergeShift(@as(V, @splat(shift_in)), vec, len - amount);
}