flexfloat.ListInt64BitArray

class flexfloat.ListInt64BitArray(chunks=None, length=0)[source]

A memory-efficient bit array class using a list of int64 values.

This implementation packs 64 bits per integer, making it more memory efficient for large bit arrays compared to the boolean list implementation.

__init__(chunks=None, length=0)[source]

Initializes a ListInt64BitArray.

Parameters:
  • chunks (list[int] | None, optional) – Initial list of int64 chunks. Defaults to empty list.

  • length (int, optional) – The amount of bits in the array. Defaults to 0.

Raises:

ValueError – If length is negative.

classmethod from_bits(bits=None)[source]

Creates a BitArray from a list of boolean values.

Parameters:

bits (list[bool] | None, optional) – List of boolean values in LSB-first order. Defaults to None, which creates an empty BitArray.

Returns:

A BitArray created from the bits.

Return type:

ListInt64BitArray

classmethod zeros(length)[source]

Creates a BitArray filled with zeros.

Parameters:

length (int) – The length of the bit array.

Returns:

A BitArray filled with False values.

Return type:

ListInt64BitArray

classmethod ones(length)[source]

Creates a BitArray filled with ones.

Parameters:

length (int) – The length of the bit array.

Returns:

A BitArray filled with True values.

Return type:

ListInt64BitArray

to_int()[source]

Converts the bit array to an unsigned integer (LSB-first).

Returns:

The integer represented by the bit array.

Return type:

int

to_float()[source]

Converts a 64-bit array to a floating-point number (LSB-first).

Returns:

The floating-point number represented by the bit array.

Return type:

float

Raises:

AssertionError – If the bit array is not 64 bits long.

copy()[source]

Creates a copy of the bit array.

Returns:

A new BitArray with the same bits.

Return type:

ListInt64BitArray

__len__()[source]

Returns the length of the bit array.

Returns:

The number of bits in the array.

Return type:

int

__getitem__(index: int) bool[source]
__getitem__(index: slice) ListInt64BitArray

Get a bit or a slice of bits as a new ListInt64BitArray.

__setitem__(index: int, value: bool) None[source]
__setitem__(index: slice, value: BitArray | list[bool]) None

Sets an item or slice in the bit array.

Parameters:
  • index (int or slice) – The index or slice to set.

  • value (bool or list[bool] or BitArray) – The value(s) to assign.

Raises:
  • TypeError – If value type does not match index type.

  • ValueError – If value length does not match slice length.

__iter__()[source]

Iterates over the bits in the array.

Yields:

bool – The next bit in the array.

__add__(other)[source]

Concatenates two bit arrays.

Parameters:

other (BitArray or list[bool]) – The other bit array or list to concatenate.

Returns:

The concatenated bit array.

Return type:

ListInt64BitArray

__radd__(other)[source]

Reverse concatenation with a list.

Parameters:

other (list[bool]) – The list to concatenate before this bit array.

Returns:

The concatenated bit array.

Return type:

ListInt64BitArray

__eq__(other)[source]

Checks equality with another BitArray or list.

Parameters:

other (object) – The object to compare with.

Returns:

True if equal, False otherwise.

Return type:

bool

__bool__()[source]

Returns True if any bit is set.

Returns:

True if any bit is set, False otherwise.

Return type:

bool

__repr__()[source]

Returns a string representation of the BitArray.

Returns:

String representation of the BitArray.

Return type:

str

any()[source]

Returns True if any bit is set to True.

Returns:

True if any bit is set to True, False otherwise.

Return type:

bool

all()[source]

Returns True if all bits are set to True.

Returns:

True if all bits are set to True, False otherwise.

Return type:

bool