system.interfaces.bit_sequence module

Abstract interfaces for bit sequences (uncompressed and compressed variants).

class system.interfaces.bit_sequence.BitSequence(represented_number_of_bits: int)[source]

Bases: ABC

Defines a bit sequence. Also called bitvector, bitarray, bitlist, etc.

get_number_of_bits() → int[source]

Returns the number of bits in this bit-sequence. :return: The number of bits.

as_set() → set[int][source]

Returns the bit-sequence as a set of integer positions, i.e. the set of integer positions set to true. :return: A set containing all positions that are set to 1.

get_bit_sequence_for_range(lower_idx: int, upper_idx: int, represented_number_of_bits: int | None = None) → BitSequence[source]

Returns a bit sequence representing the given range. :param lower_idx: The lower index (including) of the range. :param upper_idx: The upper index (including) of the range. :param represented_number_of_bits: Number of bits represented by new the range. If None, the difference between both indices is used :return: The bit sequence for the range.

set_bit(index: int) → None[source]

Set the bit at the given index to true. :param index: The index of the bit to set.

unset_bit(index: int) → None[source]

Unset the bit at the given index. :param index: The index of the bit to unset.

abstractmethod static create_all_false_bit_sequence(number_of_bits: int = 0) → BitSequence[source]

Creates a bit-sequence where all bits are set to false. :param number_of_bits: The number of bits in the bit-sequence. :return: A bit-sequence of length number_of_bits and all bits set to False.

abstractmethod update_represented_number_of_bits(updated_represented_number_of_bits: int) → None[source]

Updates the number of bits to be represented by this bit-sequence. :param updated_represented_number_of_bits: The number of bits to represent.

abstractmethod intersects(other: BitSequence) → bool[source]

Checks whether bit sequences intersect with each other.

Parameters:

other – The other bit sequence.

Returns:

True, if the bit sequences intersect, False if not.

abstractmethod all_bits_set_to_false() → bool[source]

A predicate checking if all bits in the bit-sequence are set to False. :return: True, if all bits in the bit-sequence are set to False, False if not.

abstractmethod all_bits_set_to_true() → bool[source]

A predicate checking if all bits in the bit-sequence are set to True. :return: True, if all bits in the bit-sequence are set to True, False if not.

abstractmethod get_least_significant_bit() → BitSequence[source]

Returns a bit sequence only containing the least significant bit of this bit sequence. :return: The bit sequence only containing the least significant bit of this bit sequence.

abstractmethod get_most_significant_bit() → BitSequence[source]

Returns a bit sequence only containing the most significant bit of this bit sequence. :return: The bit sequence only containing the most significant bit of this bit sequence.

abstractmethod contains_bit_sequence(other: BitSequence) → bool[source]

Checks whether the other bit sequence is contained in self. :param other: The other bit sequence. :return: True, if other is contained in self, False if not.

abstractmethod bit_count() → int[source]

Returns the number of set bits in the bit sequence.

abstractmethod increase_represented_integer(number: int) → None[source]

Increase the integer represented by the bit sequence by the given number.

abstractmethod get_represented_integer() → int[source]

Returns the integer represented by this bit sequence. :return: The integer represented by this bit sequence.

class SetBitsIterator(bit_sequence: BitSequence)[source]

Bases: ABC, Iterator[int]

An iterator to traverse through all set bits in the given bit-sequence. This iterator returns the integer positions of all bits that are set to True in the bit_sequence.

class SetBitsReverseIterator(bit_sequence: BitSequence)[source]

Bases: ABC, Iterator[int]

An iterator to traverse the set bits in a bit sequence in reverse order, i.e., starting with the most significant bit.

class system.interfaces.bit_sequence.UncompressedBitSequence(represented_number_of_bits: int)[source]

Bases: BitSequence, ABC

Abstract class to represent an uncompressed bit sequence

static create_all_false_bit_sequence(number_of_bits: int = 0) → UncompressedBitSequence[source]

See BitSequence.create_all_false_bit_sequence().

Uncompressed variant: the returned bit-sequence is an UncompressedBitSequence.

class system.interfaces.bit_sequence.CompressedBitSequence(represented_number_of_bits: int)[source]

Bases: BitSequence, ABC

Abstract class to represent compressed bit sequences.

abstractmethod static compress_bit_sequence(bit_sequence: UncompressedBitSequence) → CompressedBitSequence[source]

Compresses the given bit sequence. :param bit_sequence: The bit sequence to compress. :return: The compressed bit sequence.

static create_all_false_bit_sequence(number_of_bits: int = 0) → CompressedBitSequence[source]

See BitSequence.create_all_false_bit_sequence().

Compressed variant: the returned bit-sequence is a CompressedBitSequence.