BitVector
sealed abstract class BitVector extends BitwiseOperations[BitVector, Long] with Ordered[BitVector] with Serializable
Persistent vector of bits, stored as bytes.
Bits are numbered left to right, starting at 0.
- Companion
- object
Document{}
Returns
forces this
true
if the size of this BitVector
is greater than n
. Unlike size
, thisforces this
BitVector
from left to right, halting as soon as it has a definite answer.Returns
forces this
true
if the size of this BitVector
is greater than or equal to n
. Unlike size
, thisforces this
BitVector
from left to right, halting as soon as it has a definite answer.Returns
forces this
true
if the size of this BitVector
is less than n
. Unlike size
, thisforces this
BitVector
from left to right, halting as soon as it has a definite answer.Returns
forces this
true
if the size of this BitVector
is less than or equal to n
. Unlike size
, thisforces this
BitVector
from left to right, halting as soon as it has a definite answer.Returns true if the
n
th bit is high, false otherwise.- Throws
- NoSuchElementException
- NoSuchElementException
Returns a new bit vector representing this vector's contents followed by the specified vector's contents.
Returns a vector of all bits in this vector except the first
n
bits.The resulting vector's size is
0 max (size - n)
.Returns a vector of all bits in this vector except the last
n
bits.The resulting vector's size is
0 max (size - n)
.Returns a vector of the first
n
bits of this vector.The resulting vector's size is
n min size
.Note: if an
n
-bit vector is required, use the acquire
method instead.- See also
- acquire
Returns a vector made up of the bits starting at index
not including the index
from
up to index until
,not including the index
until
.Returns a vector whose contents are the results of taking the first
n
bits of this vector.If this vector does not contain at least
n
bits, an error message is returned.- See also
- take
Like
aquire
, but immediately consumes the Either
via the pair of functions err
and f
.- See also
- acquire
final def consume[A](n: Long)(decode: BitVector => Either[String, A]): Either[String, (BitVector, A)]
Consumes the first
resulting in a vector of the remaining bits and the decoded value. If this vector
does not have
n
bits of this vector and decodes them with the specified function,resulting in a vector of the remaining bits and the decoded value. If this vector
does not have
n
bits or an error occurs while decoding, an error is returned instead.If this vector has at least
otherwise calls
to avoid intermediate allocations of
directly.
n
bits, returns f(take(n),drop(n))
,otherwise calls
err
with a meaningful error message. This function can be usedto avoid intermediate allocations of
Either
objects when using acquire
or consume
directly.
- See also
- acquireThen
Finds the first index of the specified bit pattern in this vector.
- Returns
-
index of slice or -1 if not found
Finds the first index after
from
of the specified bit pattern in this vector.- Returns
-
index of slice or -1 if not found
Returns an
n
-bit vector whose contents are 0 or more low bits followed by this vector's contents.- Throws
- IllegalArgumentException
- IllegalArgumentException
Returns an
n
-bit vector whose contents are 0 or more low bits followed by this vector's contents.- Throws
- IllegalArgumentException
- IllegalArgumentException
Returns a new vector of the same size with the byte order reversed.
Note that
To invert
reverseByteOrder.reverseByteOrder == identity
only when size
is evenly divisble by 8.To invert
reverseByteOrder
for an arbitrary size, use invertReverseByteOrder
.Return a
based off a single
BitVector
with the same contents as this
, butbased off a single
ByteVector
.This may involve copying data to a fresh
has the advantage that lookups index directly into a single
in this tree.
ByteVector
, buthas the advantage that lookups index directly into a single
ByteVector
rather than traversing a logarithmic number of nodesin this tree.
Calling this method on an already compacted vector is a no-op.
Produce a single flat
any non-byte-aligned appends or drops. Unlike
necessarily copied.
Bytes
by interpretingany non-byte-aligned appends or drops. Unlike
compact
, the underlying ByteVector
is notnecessarily copied.
Return a
based off a single flat
to copy all the bytes in this
may no-op if this
chunk.
BitVector
with the same contents as this
, butbased off a single flat
ByteVector
. This function is guaranteedto copy all the bytes in this
BitVector
, unlike compact
, whichmay no-op if this
BitVector
already consists of a single ByteVector
chunk.
Return the sequence of bits in this vector. The returned
IndexedSeq
is just a view; nothing is actually copied.- Throws
- IllegalArgumentException
- IllegalArgumentException
- See also
- acquiretoIndexedSeq
Converts the contents of this vector to a byte vector.
If this vector's size does not divide evenly by 8, the last byte of the returned vector
will be zero-padded to the right.
will be zero-padded to the right.
Converts the contents of this vector to a byte array.
If this vector's size does not divide evenly by 8, the last byte of the returned vector
will be zero-padded to the right.
will be zero-padded to the right.
Converts the contents of this vector to a
java.nio.ByteBuffer
.The returned buffer is freshly allocated with limit set to the minimum number of bytes needed
to represent the contents of this vector, position set to zero, and remaining set to the limit.
to represent the contents of this vector, position set to zero, and remaining set to the limit.
- See also
- toByteVector
Converts the contents of this bit vector to a hexadecimal string of
ceil(size / 4)
nibbles.The last nibble is right-padded with zeros if the size is not evenly divisible by 4.
Converts the contents of this bit vector to a hexadecimal string of
ceil(size / 4)
nibbles.The last nibble is right-padded with zeros if the size is not evenly divisible by 4.
Converts the contents of this vector to a base 32 string.
The last byte is right-padded with zeros if the size is not evenly divisible by 8.
Converts the contents of this vector to a base 32 string using the specified alphabet.
The last byte is right-padded with zeros if the size is not evenly divisible by 8.
Converts the contents of this vector to a base 58 string.
the order is assumed to be the same as (Bitcoin)https://en.bitcoin.it/wiki/Base58Check_encoding#Base58_symbol_chart
Converts the contents of this vector to a base 58 string using the specified alphabet.
the order is assumed to be the same as (Bitcoin)https://en.bitcoin.it/wiki/Base58Check_encoding#Base58_symbol_chart
Converts the contents of this vector to a base 64 string.
The last byte is right-padded with zeros if the size is not evenly divisible by 8.
Converts the contents of this vector to a base 64 string using the specified alphabet.
The last byte is right-padded with zeros if the size is not evenly divisible by 8.
Convert a slice of bits from this vector (
start
until start+bits
) to a Byte
.- Value Params
- signed
-
whether sign extension should be performed
- Throws
- IllegalArgumentException
- IllegalArgumentException
Converts the contents of this vector to a byte.
- Value Params
- signed
-
whether sign extension should be performed
- Throws
- IllegalArgumentException
- IllegalArgumentException
Convert a slice of bits from this vector (
start
until start+bits
) to a Short
.- Value Params
- ordering
-
order bytes should be processed in
- signed
-
whether sign extension should be performed
- Throws
- IllegalArgumentException
- IllegalArgumentException
Converts the contents of this vector to a short.
- Value Params
- ordering
-
order bytes should be processed in
- signed
-
whether sign extension should be performed
- Throws
- IllegalArgumentException
- IllegalArgumentException
Convert a slice of bits from this vector (
start
until start+bits
) to an Int
.- Value Params
- ordering
-
order bytes should be processed in
- signed
-
whether sign extension should be performed
- Throws
- IllegalArgumentException
- IllegalArgumentException
Converts the contents of this vector to an int.
- Value Params
- ordering
-
order bytes should be processed in
- signed
-
whether sign extension should be performed
- Throws
- IllegalArgumentException
- IllegalArgumentException
Convert a slice of bits from this vector (
start
until start+bits
) to a Long
.- Value Params
- ordering
-
order bytes should be processed in
- signed
-
whether sign extension should be performed
- Throws
- IllegalArgumentException
- IllegalArgumentException
Converts the contents of this vector to a long.
- Value Params
- ordering
-
order bytes should be processed in
- signed
-
whether sign extension should be performed
- Throws
- IllegalArgumentException
- IllegalArgumentException
Converts the contents of this bit vector to a UUID.
- Throws
- IllegalArgumentException
- IllegalArgumentException
Compresses this vector using ZLIB.
The last byte is zero padded if the size is not evenly divisible by 8.
- Value Params
- chunkSize
-
buffer size, in bytes, to use when compressing
- level
-
compression level, 0-9, with 0 disabling compression and 9 being highest level of compression -- see
java.util.zip.Deflater
for details - nowrap
-
if true, ZLIB header and checksum will not be used
- strategy
-
compression strategy -- see
java.util.zip.Deflater
for details
Decompresses this vector using ZLIB.
The last byte is zero padded if the size is not evenly divisible by 8.
- Value Params
- chunkSize
-
buffer size, in bytes, to use when compressing
Computes a digest of this bit vector.
Exceptions thrown from the underlying JCA API are propagated.
The last byte is zero padded if the size is not evenly divisible by 8.
- Value Params
- algorithm
-
digest algorithm to use
Computes a digest of this bit vector.
Exceptions thrown from the underlying JCA API are propagated.
The last byte is zero padded if the size is not evenly divisible by 8.
- Value Params
- digest
-
digest to use
final def encrypt(ci: Cipher, key: Key, aparams: Option[AlgorithmParameters])(sr: SecureRandom): Either[GeneralSecurityException, BitVector]
Encrypts this bit vector using the specified cipher and key.
The last byte is zero padded if the size is not evenly divisible by 8.
- Value Params
- aparams
-
optional algorithm paramaters used for encryption (e.g., initialization vector)
- ci
-
cipher to use for encryption
- key
-
key to encrypt with
- sr
-
secure random
final def decrypt(ci: Cipher, key: Key, aparams: Option[AlgorithmParameters])(sr: SecureRandom): Either[GeneralSecurityException, BitVector]
Decrypts this bit vector using the specified cipher and key.
The last byte is zero padded if the size is not evenly divisible by 8.
- Value Params
- aparams
-
optional algorithm paramaters used for decryption (e.g., initialization vector)
- ci
-
cipher to use for decryption
- key
-
key to decrypt with
- sr
-
secure random
Returns true if the specified value is a
BitVector
with the same contents as this vector.- See also
- Definition Classes
- Any
Display the size and bytes of this
For bit vectors beyond a certain size, only a hash of the
contents are shown.
BitVector
.For bit vectors beyond a certain size, only a hash of the
contents are shown.
- Definition Classes
- Any
Returns a bitwise implication of this value with the specified value.
The resulting value's size is the minimum of this value's size and the specified value's size.
- Inhertied from
- BitwiseOperations
Returns a bitwise NAND of this value with the specified value.
The resulting value's size is the minimum of this value's size and the specified value's size.
- Inhertied from
- BitwiseOperations
Returns a bitwise NOR of this value with the specified value.
The resulting value's size is the minimum of this value's size and the specified value's size.
- Inhertied from
- BitwiseOperations
Returns a bitwise OR of this value with the specified value.
The resulting value's size is the minimum of this value's size and the specified value's size.
- Inhertied from
- BitwiseOperations
Returns a value of the same size with each bit shifted to the right
n
bits where the n
left-most bits are low.- Inhertied from
- BitwiseOperations
Returns a bitwise if-and-only-if of this value with the specified value.
The resulting value's size is the minimum of this value's size and the specified value's size.
- Inhertied from
- BitwiseOperations
Returns a bitwise XOR of this value with the specified value.
The resulting value's size is the minimum of this value's size and the specified value's size.
- Inhertied from
- BitwiseOperations
Returns a bitwise AND of this value with the specified value.
The resulting value's size is the minimum of this value's size and the specified value's size.
- Inhertied from
- BitwiseOperations
Returns a value of the same size with each bit shifted to the left
n
bits.- Inhertied from
- BitwiseOperations
Returns a value of the same size with each bit shifted to the right
n
bits where the n
left-most bits are sign extended.- Inhertied from
- BitwiseOperations