jaulib v1.4.0-2-g788cf73
Jau Support Library (C++, Java, ..)
Loading...
Searching...
No Matches
jau::bitheap Class Reference

Simple dynamically heap-sized bitheap for efficient bit storage access in O(1). More...

#include <bitheap.hpp>

Collaboration diagram for jau::bitheap:

Public Types

typedef size_t size_type
 size_t data type, bit position and count
 
typedef unsigned long unit_type
 Unit data type.
 

Public Member Functions

constexpr bitheap (size_type bitSize) noexcept
 Constructs an empty bitheap instance.
 
 bitheap (std::string_view bitstr)
 Constructs a bitheap instance, initialized with bitstr msb bit-pattern.
 
constexpr void clear () noexcept
 
constexpr bool clr (size_type bitpos) noexcept
 Clear the bit at position bitpos of this storage.
 
bool copy (size_type srcBitpos, size_type dstBitpos) noexcept
 Copies the bit at position srcBitpos to position dstBitpos, returning the copied bit-value.
 
bool copyUnit (size_type srcBitpos, size_type dstBitpos, size_type length) noexcept
 Copies length bits at position srcBitpos to position dstBitpos, returning the copied bits.
 
size_type count () const noexcept
 
constexpr bitheapflip () noexcept
 
constexpr bool flip (size_type bitpos) noexcept
 Flips the bit value at position bitpos in this storage.
 
constexpr bool get (size_type bitpos) const noexcept
 
unit_type getUnit (size_type bitpos, size_type length) const noexcept
 
constexpr bool in_range (size_type bitpos) const noexcept
 
constexpr bool in_range (size_type bitpos, size_type length) const noexcept
 
std::string infoString () const noexcept
 
constexpr bool operator== (const bitheap &rhs) const noexcept
 
constexpr bool operator[] (size_type bitpos) const noexcept
 
bool put (size_t bitpos, const bitheap &o)
 
constexpr bool put (size_type bitpos, bool v) noexcept
 Writes the bit value v to position bitpos into this storage.
 
bool put (size_type bitpos, std::string_view bitstr) noexcept
 Writes bitstr msb bit-pattern into this storage, starting with the lowest bit from the storage position bitpos.
 
bool putUnit (size_type bitpos, size_type length, unit_type data) noexcept
 Writes length bits of given data into this storage, starting with the lowest bit from the storage position bitpos.
 
constexpr bitheapreset () noexcept
 
constexpr bool reset (size_type bitpos) noexcept
 Clear the bit at position bitpos of this storage.
 
void resize (size_t new_bit_size)
 
constexpr bitheapreverse () noexcept
 
constexpr bool set (size_type bitpos) noexcept
 Sets the bit at position bitpos of this storage.
 
bool set (size_type bitpos, size_type length, bool bit) noexcept
 Set length bits starting at bitpos of this bitfield to the given value bit.
 
bitheapsetAll (bool bit) noexcept
 Set all bits of this bitfield to the given value bit.
 
constexpr size_type size () const noexcept
 Returns storage size in bits.
 
std::pair< bitheap, bool > subbits (size_type bitpos, size_type length) const noexcept
 
std::string toString (PrefixOpt prefix=PrefixOpt::none) const noexcept
 
std::string toString (size_type bitpos, size_type length, PrefixOpt prefix=PrefixOpt::none) const noexcept
 

Static Public Attributes

static constexpr size_type unit_bit_size = unit_byte_size * CHAR_BIT
 One unit size in bits.
 
static constexpr size_type unit_byte_size = sizeof(unit_type)
 One unit size in bytes.
 
static constexpr size_type unit_shift = jau::log2_byteshift(unit_byte_size)
 One unit shift amount.
 

Detailed Description

Simple dynamically heap-sized bitheap for efficient bit storage access in O(1).

Bit-position and bit-order are in least-significant-bits (lsb) first.

Implementations utilizes a dynamic heap std::vector<unsigned long> StorageType.

Similar to std::bitset, but utilizing dynamic runtime heapsize and providing custom methods.

See also
jau::bitfield

Definition at line 49 of file bitheap.hpp.

Member Typedef Documentation

◆ unit_type

typedef unsigned long jau::bitheap::unit_type

Unit data type.

Definition at line 51 of file bitheap.hpp.

◆ size_type

typedef size_t jau::bitheap::size_type

size_t data type, bit position and count

Definition at line 52 of file bitheap.hpp.

Constructor & Destructor Documentation

◆ bitheap() [1/2]

jau::bitheap::bitheap ( size_type bitSize)
inlineconstexprnoexcept

Constructs an empty bitheap instance.

Definition at line 78 of file bitheap.hpp.

Here is the caller graph for this function:

◆ bitheap() [2/2]

jau::bitheap::bitheap ( std::string_view bitstr)
inline

Constructs a bitheap instance, initialized with bitstr msb bit-pattern.

Parameters
bitstrmost-significat (msb) bit string pattern
Exceptions
jau::IllegalArgumentErrorif bitstr put failed
See also
put(std::string_view)

Definition at line 90 of file bitheap.hpp.

Member Function Documentation

◆ size()

size_type jau::bitheap::size ( ) const
inlineconstexprnoexcept

Returns storage size in bits.

Definition at line 58 of file bitheap.hpp.

Here is the caller graph for this function:

◆ in_range() [1/2]

bool jau::bitheap::in_range ( size_type bitpos) const
inlineconstexprnoexcept

Definition at line 72 of file bitheap.hpp.

Here is the caller graph for this function:

◆ in_range() [2/2]

bool jau::bitheap::in_range ( size_type bitpos,
size_type length ) const
inlineconstexprnoexcept

Definition at line 73 of file bitheap.hpp.

◆ resize()

void jau::bitheap::resize ( size_t new_bit_size)
inline

Definition at line 101 of file bitheap.hpp.

◆ clear()

void jau::bitheap::clear ( )
inlineconstexprnoexcept

Definition at line 108 of file bitheap.hpp.

Here is the caller graph for this function:

◆ reset() [1/2]

bitheap & jau::bitheap::reset ( )
inlineconstexprnoexcept

Definition at line 112 of file bitheap.hpp.

◆ operator[]()

bool jau::bitheap::operator[] ( size_type bitpos) const
inlineconstexprnoexcept

Definition at line 118 of file bitheap.hpp.

◆ get()

bool jau::bitheap::get ( size_type bitpos) const
inlineconstexprnoexcept

Definition at line 121 of file bitheap.hpp.

Here is the caller graph for this function:

◆ put() [1/3]

bool jau::bitheap::put ( size_type bitpos,
bool v )
inlinenodiscardconstexprnoexcept

Writes the bit value v to position bitpos into this storage.

Returns
true on sucess, otherwise false

Definition at line 133 of file bitheap.hpp.

Here is the caller graph for this function:

◆ flip() [1/2]

bool jau::bitheap::flip ( size_type bitpos)
inlinenodiscardconstexprnoexcept

Flips the bit value at position bitpos in this storage.

Returns
true on sucess, otherwise false

Definition at line 151 of file bitheap.hpp.

◆ flip() [2/2]

bitheap & jau::bitheap::flip ( )
inlineconstexprnoexcept

Definition at line 166 of file bitheap.hpp.

◆ reverse()

bitheap & jau::bitheap::reverse ( )
inlineconstexprnoexcept

Definition at line 176 of file bitheap.hpp.

Here is the caller graph for this function:

◆ set() [1/2]

bool jau::bitheap::set ( size_type bitpos)
inlinenodiscardconstexprnoexcept

Sets the bit at position bitpos of this storage.

Returns
true on sucess, otherwise false

Definition at line 202 of file bitheap.hpp.

Here is the caller graph for this function:

◆ clr()

bool jau::bitheap::clr ( size_type bitpos)
inlinenodiscardconstexprnoexcept

Clear the bit at position bitpos of this storage.

Returns
true on sucess, otherwise false

Definition at line 207 of file bitheap.hpp.

◆ reset() [2/2]

bool jau::bitheap::reset ( size_type bitpos)
inlinenodiscardconstexprnoexcept

Clear the bit at position bitpos of this storage.

Returns
true on sucess, otherwise false

Definition at line 212 of file bitheap.hpp.

◆ copy()

bool jau::bitheap::copy ( size_type srcBitpos,
size_type dstBitpos )
inlinenodiscardnoexcept

Copies the bit at position srcBitpos to position dstBitpos, returning the copied bit-value.

Returns
true on sucess, otherwise false

Definition at line 218 of file bitheap.hpp.

◆ getUnit()

unit_type jau::bitheap::getUnit ( size_type bitpos,
size_type length ) const
inlinenoexcept

Definition at line 223 of file bitheap.hpp.

Here is the caller graph for this function:

◆ putUnit()

bool jau::bitheap::putUnit ( size_type bitpos,
size_type length,
unit_type data )
inlinenodiscardnoexcept

Writes length bits of given data into this storage, starting with the lowest bit from the storage position bitpos.

Returns
true on sucess, otherwise false

Definition at line 253 of file bitheap.hpp.

Here is the caller graph for this function:

◆ put() [2/3]

bool jau::bitheap::put ( size_type bitpos,
std::string_view bitstr )
inlinenodiscardnoexcept

Writes bitstr msb bit-pattern into this storage, starting with the lowest bit from the storage position bitpos.

Parameters
bitposbit position to insert
bitstrmost-significat (msb) bit string pattern
Returns
true on sucess, otherwise false

Definition at line 289 of file bitheap.hpp.

◆ set() [2/2]

bool jau::bitheap::set ( size_type bitpos,
size_type length,
bool bit )
inlinenodiscardnoexcept

Set length bits starting at bitpos of this bitfield to the given value bit.

Returns
true on sucess, otherwise false

Definition at line 315 of file bitheap.hpp.

◆ setAll()

bitheap & jau::bitheap::setAll ( bool bit)
inlinenoexcept

Set all bits of this bitfield to the given value bit.

Definition at line 353 of file bitheap.hpp.

◆ copyUnit()

bool jau::bitheap::copyUnit ( size_type srcBitpos,
size_type dstBitpos,
size_type length )
inlinenodiscardnoexcept

Copies length bits at position srcBitpos to position dstBitpos, returning the copied bits.

Returns
true on sucess, otherwise false

Definition at line 362 of file bitheap.hpp.

◆ count()

size_type jau::bitheap::count ( ) const
inlinenoexcept

Definition at line 367 of file bitheap.hpp.

◆ operator==()

bool jau::bitheap::operator== ( const bitheap & rhs) const
inlineconstexprnoexcept

Definition at line 374 of file bitheap.hpp.

◆ put() [3/3]

bool jau::bitheap::put ( size_t bitpos,
const bitheap & o )
inlinenodiscard

Definition at line 388 of file bitheap.hpp.

◆ subbits()

std::pair< bitheap, bool > jau::bitheap::subbits ( size_type bitpos,
size_type length ) const
inlinenodiscardnoexcept

Definition at line 419 of file bitheap.hpp.

Here is the caller graph for this function:

◆ toString() [1/2]

std::string jau::bitheap::toString ( size_type bitpos,
size_type length,
PrefixOpt prefix = PrefixOpt::none ) const
inlinenoexcept

Definition at line 450 of file bitheap.hpp.

Here is the caller graph for this function:

◆ toString() [2/2]

std::string jau::bitheap::toString ( PrefixOpt prefix = PrefixOpt::none) const
inlinenoexcept

Definition at line 479 of file bitheap.hpp.

◆ infoString()

std::string jau::bitheap::infoString ( ) const
inlinenoexcept

Definition at line 483 of file bitheap.hpp.

Member Data Documentation

◆ unit_byte_size

size_type jau::bitheap::unit_byte_size = sizeof(unit_type)
staticconstexpr

One unit size in bytes.

Definition at line 53 of file bitheap.hpp.

◆ unit_bit_size

size_type jau::bitheap::unit_bit_size = unit_byte_size * CHAR_BIT
staticconstexpr

One unit size in bits.

Definition at line 54 of file bitheap.hpp.

◆ unit_shift

size_type jau::bitheap::unit_shift = jau::log2_byteshift(unit_byte_size)
staticconstexpr

One unit shift amount.

Definition at line 55 of file bitheap.hpp.


The documentation for this class was generated from the following file: