Gamp v0.0.7-54-gccdc599
Gamp: Graphics, Audio, Multimedia and Processing
Loading...
Searching...
No Matches
jau::bitheap Class Reference

Simple dynamically heap-sized bitheap for efficient bit storage access. 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 jau::nsize_t 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.

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

Implementations utilizes a dynamic heap std::vector<jau::nsize_t> StorageType.

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

See also
jau::bitfield
jau::nsize_t

Definition at line 50 of file bitheap.hpp.

Member Typedef Documentation

◆ unit_type

Unit data type.

Definition at line 52 of file bitheap.hpp.

◆ size_type

typedef size_t jau::bitheap::size_type

size_t data type, bit position and count

Definition at line 53 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 79 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 91 of file bitheap.hpp.

Member Function Documentation

◆ size()

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

Returns storage size in bits.

Definition at line 59 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 73 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 74 of file bitheap.hpp.

◆ resize()

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

Definition at line 102 of file bitheap.hpp.

◆ clear()

void jau::bitheap::clear ( )
inlineconstexprnoexcept

Definition at line 109 of file bitheap.hpp.

Here is the caller graph for this function:

◆ reset() [1/2]

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

Definition at line 113 of file bitheap.hpp.

◆ operator[]()

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

Definition at line 119 of file bitheap.hpp.

◆ get()

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

Definition at line 122 of file bitheap.hpp.

Here is the caller graph for this function:

◆ put() [1/3]

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

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

Returns
true on sucess, otherwise false

Definition at line 134 of file bitheap.hpp.

Here is the caller graph for this function:

◆ flip() [1/2]

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

Flips the bit value at position bitpos in this storage.

Returns
true on sucess, otherwise false

Definition at line 152 of file bitheap.hpp.

◆ flip() [2/2]

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

Definition at line 167 of file bitheap.hpp.

◆ reverse()

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

Definition at line 177 of file bitheap.hpp.

Here is the caller graph for this function:

◆ set() [1/2]

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

Sets the bit at position bitpos of this storage.

Returns
true on sucess, otherwise false

Definition at line 203 of file bitheap.hpp.

Here is the caller graph for this function:

◆ clr()

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

Clear the bit at position bitpos of this storage.

Returns
true on sucess, otherwise false

Definition at line 208 of file bitheap.hpp.

◆ reset() [2/2]

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

Clear the bit at position bitpos of this storage.

Returns
true on sucess, otherwise false

Definition at line 213 of file bitheap.hpp.

◆ copy()

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

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

Returns
true on sucess, otherwise false

Definition at line 219 of file bitheap.hpp.

◆ getUnit()

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

Definition at line 224 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 )
inlinenoexcept

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 254 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 )
inlinenoexcept

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 290 of file bitheap.hpp.

◆ set() [2/2]

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

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

Returns
true on sucess, otherwise false

Definition at line 316 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 354 of file bitheap.hpp.

◆ copyUnit()

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

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

Returns
true on sucess, otherwise false

Definition at line 363 of file bitheap.hpp.

◆ count()

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

Definition at line 368 of file bitheap.hpp.

◆ operator==()

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

Definition at line 375 of file bitheap.hpp.

◆ put() [3/3]

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

Definition at line 389 of file bitheap.hpp.

◆ subbits()

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

Definition at line 420 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 451 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 480 of file bitheap.hpp.

◆ infoString()

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

Definition at line 484 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 54 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 55 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 56 of file bitheap.hpp.


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