My Project
Loading...
Searching...
No Matches
Code Class Reference

Represents a binary code as a stack of bits. More...

#include <Code.h>

Public Member Functions

 Code ()
 Default constructor. Initializes an empty code.
bool empty () const
 Checks if the code stack is empty.
bool full () const
 Checks if the code stack has reached its maximum capacity.
bool push_bit (uint8_t bit)
 Gets the current number of bits in the code.
bool pop_bit (uint8_t &bit)
 Pops the last bit off the code stack.
uint8_t get_bit (uint32_t index) const
 Retrieves a bit at a specific index without removing it.

Detailed Description

Represents a binary code as a stack of bits.

  • This class is used to dynamically build the binary path (0s and 1s) while traversing the Huffman tree.

Member Function Documentation

◆ empty()

bool Code::empty ( ) const

Checks if the code stack is empty.

Returns
True if empty, false otherwise.

◆ full()

bool Code::full ( ) const

Checks if the code stack has reached its maximum capacity.

Returns
True if full, false otherwise.

◆ get_bit()

uint8_t Code::get_bit ( uint32_t index) const

Retrieves a bit at a specific index without removing it.

Parameters
indexThe position of the bit to retrieve.
Returns
The bit at the specified index, or 0 if out of bounds.

◆ pop_bit()

bool Code::pop_bit ( uint8_t & bit)

Pops the last bit off the code stack.

Parameters
bitReference to a variable where the popped bit will be stored.
Returns
True if successful, false if the stack is empty.

◆ push_bit()

bool Code::push_bit ( uint8_t bit)

Gets the current number of bits in the code.

Returns
The size of the code sequence.

Pushes a single bit (0 or 1) onto the code stack.

Parameters
bitThe bit to add.
Returns
True if successful, false if the stack is full.

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