I need a Julia BitArray-like object that can encode more than 64 bits, say 128 bits. Does a simple replacement of UInt64 with UInt128 in bitarray.jl work?
Based on the information in your comment, the existing BitArray
would itself serve your needs. Note that BitArray
uses UInt64
s internally, but that's not a limitation on the size of the array - it actually stores the bits as a Vector
of UInt64
s, so there's no special size limitation. You can create a 5x5x5 BitArray
with no problem.
julia> b = BitArray(undef, 5, 5, 5);
julia> b .= 0;
julia> b[3, 5, 5] = 1
1
julia> b[3, :, :]
5×5 BitMatrix:
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 1
Maybe this part of the documentation threw you off:
BitArrays pack up to 64 values into every 8 bytes, resulting in an 8x space efficiency over Array{Bool, N} and allowing some operations to work on 64 values at once.
but that's talking about internal implementation details. BitArray
s are not limited to 8 bytes, so they're not limited to having just 64 values in them either.
Creating a new type of bit array using UInt128
s would likely not be optimized, and is unnecessary anyway.