Fixed-length vectors
SmallCollections.AbstractFixedVector
— TypeAbstractFixedVector{N,T} <: AbstractVector{T}
AbstractFixedVector{N,T}
is the supertype of FixedVector{N,T}
and MutableFixedVector{N,T}
.
See also FixedVector
, MutableFixedVector
.
SmallCollections.FixedVector
— TypeFixedVector{N,T} <: AbstractFixedVector{N,T}
FixedVector{N,T}(iter)
FixedVector{N}(iter)
FixedVector(iter)
FixedVector{N,T}
is an immutable vector type that holds exactly N
elements of type T
. (It is analogous to StaticArrays.SVector
and StaticVectors.Values
.) The size N
can be any (small) positive integer. However, at least for bit integer and hardware float types, one usually takes N
to be a power of 2
.
If the element type T
or the size N
are omitted, they are determined from the iterator given as argument. Performance degrades if this is not possible at compile time. (For tuples, the element type is determined via promote_type
.) As a rule of thumb, the size should only be omitted for Tuple
arguments.
See also MutableFixedVector
, Base.promote_type
.
SmallCollections.MutableFixedVector
— TypeMutableFixedVector{N,T} <: AbstractFixedVector{N,T}
MutableFixedVector{N,T}(iter)
MutableFixedVector{N}(iter)
MutableFixedVector(iter)
MutableFixedVector{N,T}(undef)
MutableFixedVector{N,T}
is a mutable vector type that holds exactly N
elements of type T
. (It is analogous to StaticArrays.MVector
and StaticVectors.Variables
.) The size N
can be any (small) positive integer. However, at least for bit integer and hardware float types, one usually takes N
to be a power of 2
.
If the element type T
or the size N
are omitted, they are determined from the iterator given as argument. Performance degrades if this is not possible at compile time. As a rule of thumb, the size should only be omitted for Tuple
arguments.
Note that setting individual vector elements (via setindex!
) is only supported for isbits
element types.
The special form MutableFixedVector{N,T}(undef)
returns a non-initialized vector.
See also FixedVector
, Base.isbitstype
.
SmallCollections.bits
— Methodbits(v::AbstractFixedVector{N,T}) where {N, T <: Union{Base.BitInteger,Bool,Char,Enum}} -> Unsigned
Convert the given vector to an unsigned integer.
For bit integers, Char
and Enum
types this is the same as reinterpret(U, Tuple(v))
provided that U
is an unsigned integer type with N*bitsize(T)
bits, possibly defined by the package BitIntegers
. Otherwise the result will be zero-extended to the next unsigned integer type U
whose bit length is a power of 2
.
If the element type is Bool
, then each element only takes one bit in the return value. If N
is less than 8
or not a power of 2
, then the result will again be zero-extended.
See also SmallCollections.bitsize
, Base.BitInteger
, Base.reinterpret
, BitIntegers
.
Examples
julia> FixedVector{4,Int8}(1:4) |> bits
0x04030201
julia> FixedVector{3}('a':'c') |> bits
0x00000000630000006200000061000000
julia> m = FixedVector{6,UInt32}(1:6) |> bits
0x0000000000000000000000060000000500000004000000030000000200000001
julia> typeof(m)
BitIntegers.UInt256
julia> FixedVector{22}(map(isodd, 1:22)) |> bits
0x00155555
SmallCollections.fasthash
— Methodfasthash(v::AbstractFixedVector [, h0::UInt]) -> UInt
Return a hash for v
that may be computed faster than the standard hash
for vectors. This new hash is consistent across all AbstractFixedVector
s of the same element type, but it may not be compatible with hash
or with fasthash
for a AbstractFixedVector
having a different element type.
Currently, fasthash
differs from hash
only if the element type of v
is a bit integer type with at most 32 bits, Bool
or Char
.
See also Base.hash
.
Base.setindex
— Methodsetindex(v::AbstractFixedVector{N,T}, x, i::Integer) where {N,T} -> FixedVector{N,T}
Substitute x
for the i
-th component of v
and return the result. The vector v
is not modified.
See also Base.setindex
, addindex
.
SmallCollections.addindex
— Methodaddindex(v::AbstractFixedVector{N,T}, x, i::Integer) where {N,T} -> FixedVector{N,T}
Add x
to the i
-th component of v
and return the result. The vector v
is not modified.
See also setindex
.
SmallCollections.sum_fast
— Methodsum_fast(v::AbstractFixedVector)
Return the @fastmath
sum of the elements of v
. Unlike for sum
, the return value always is of the element type of v
, even for small bit integers.
See also Base.sum
, Base.@fastmath
.
SmallCollections.extrema_fast
— Methodextrema_fast(v::AbstractFixedVector; [init])
Return the @fastmath
minimum and maximum of the elements of v
. The init
keyword argument may not be used.
See also Base.extrema
, Base.@fastmath
.
SmallCollections.extrema_fast
— Methodextrema_fast(f, v::AbstractFixedVector; [init])
Return the @fastmath
minimum and maximum of the values of f
applied to the elements of v
. The init
keyword argument may not be used.
See also Base.extrema
, Base.@fastmath
.
SmallCollections.support
— Methodsupport(v::AbstractFixedVector) -> SmallBitSet
Return the SmallBitSet
with the indices of the non-zero elements of v
.
See also SmallBitSet
.
Example
julia> v = FixedVector{4,Int8}([1, 0, 0, 3]);
julia> support(v)
SmallBitSet{UInt64} with 2 elements:
1
4