A Buffer for bit-level and byte-level manipulation.
public func bitSize() : Nat
Returns the number of bits in the buffer
public func bitCapacity() : Nat
Returns the max number of bits the buffer can hold without resizing
public func byteSize() : Nat
Returns the number of bytes in the buffer
public func byteCapacity() : Nat
Returns the max number of bytes the buffer can hold without resizing
public func bitcount(bit : Bool) : Nat
Returns the number of bits that match the given bit
public func addBit(bit : Bool)
Adds a single bit to the bitbuffer
public func addBits(n : Nat, bits : Nat)
Adds the given bits to the bitbuffer
public func getBit(i : Nat) : Bool
Returns the bit at the given index as a Bool
public func getBits(i : Nat, n : Nat) : Nat
Returns the bits at the given index as a Nat
public func dropBit()
Drops the first bit from the buffer.
public func dropBits(n : Nat)
Drops the first n
bits from the bitbuffer.
Trap if n
is greater than the number of bits in the bitbuffer.
public func invert()
Flips all the bits in the buffer
public func clear()
public func bits() : Iter<Bool>
Returns an iterator over the bits in the buffer
public func bytes() : Iter<Nat8>
Returns an iterator over the bytes in the buffer
public func byteAlign()
Aligns the buffer to the next byte boundary
public func new() : BitBuffer
Initializes an empty bitbuffer
public func withByteCapacity(byte_capacity : Nat) : BitBuffer
Initializes a bitbuffer with the given byte capacity
public func init(bit_capacity : Nat, ones : Bool) : BitBuffer
Initializes a bitbuffer with bit_capacity
bits and fills it with ones
if true
or zeros
if false
.
public func tabulate(bit_capacity : Nat, f : (Nat) -> Bool) : BitBuffer
Initializes a bitbuffer with bit_capacity
bits and fills it with the bits returned by the function f
.
public func isByteAligned(bitbuffer : BitBuffer) : Bool
Checks if the bits in the buffer are byte aligned
public func bitcountNonZero(bitbuffer : BitBuffer) : Nat
Returns the number of bits that are set to true
or 1
in the buffer
public func addByte(bitbuffer : BitBuffer, byte : Nat8)
public func getByte(bitbuffer : BitBuffer, bit_index : Nat) : Nat8
public func dropByte(bitbuffer : BitBuffer)
public func fromBytes(bytes : [Nat8]) : BitBuffer
public func addBytes(bitbuffer : BitBuffer, bytes : [Nat8])
public func getBytes(
bitbuffer : BitBuffer,
bit_index : Nat,
n : Nat
) : [Nat8]
public func dropBytes(bitbuffer : BitBuffer, n : Nat)
public func addNat8(bitbuffer : BitBuffer, nat8 : Nat8)
public func getNat8(bitbuffer : BitBuffer, bit_index : Nat) : Nat8
public func dropNat8(bitbuffer : BitBuffer)
public func addNat16(bitbuffer : BitBuffer, nat16 : Nat16)
public func getNat16(bitbuffer : BitBuffer, bit_index : Nat) : Nat16
public func dropNat16(bitbuffer : BitBuffer)
public func addNat32(bitbuffer : BitBuffer, nat32 : Nat32)
public func getNat32(bitbuffer : BitBuffer, bit_index : Nat) : Nat32
public func dropNat32(bitbuffer : BitBuffer)
public func addNat64(bitbuffer : BitBuffer, nat64 : Nat64)
public func getNat64(bitbuffer : BitBuffer, bit_index : Nat) : Nat64
public func dropNat64(bitbuffer : BitBuffer)
public func addInt8(bitbuffer : BitBuffer, int8 : Int8)
public func addInt16(bitbuffer : BitBuffer, int16 : Int16)
public func addInt32(bitbuffer : BitBuffer, int32 : Int32)
public func addInt64(bitbuffer : BitBuffer, int64 : Int64)