#include <CompressedArray.hh>
Public Member Functions | |
CompressedArray () | |
CompressedArray (const Array &array) | |
CompressedArray (const CompressedArray &array) | |
CompressedArray (u64 num_elems, unsigned int bits_per_elem) | |
Create an array with initial size. | |
~CompressedArray () | |
CompressedArray & | operator= (const CompressedArray &array) |
bool | is_compressed () const |
Return true if compressed. | |
u64 | num_elems () const |
Return the number of elements stored in the compressed array. | |
unsigned int | shift () const |
Return the number bits used in the compression. | |
u64 | compressed_size () const |
Return the number of bytes required to store the possibly recursively compressed array. | |
void | resize (u64 num_elems) |
Change the number of elements in the array. | |
void | set_width (int bits_per_elem) |
Change the width of the elements to given width. | |
void | set (u64 elem, u32 value) |
Set the value of an element. | |
void | set_grow (u64 elem, u32 value) |
Set the value of an element growing the buffer if necessary. | |
void | set_grow_widen (u64 elem, u32 value) |
Set the value of an element growing and widening the buffer if necessary. | |
u32 | get (u64 elem) const |
Return value of an element. | |
void | compress (unsigned int shift) |
Compress the array. | |
void | optimal_compress () |
Compress the array once with the optimal compression width. | |
void | recursive_optimal_compress () |
Compress the array and the resulting arrays recursively with the optimal compression width. | |
void | uncompress () |
Uncompress the array. | |
u64 | last_leq (u32 value) |
Find the largest index that has a equal or smaller value than specified. | |
std::string | debug_str (int indent=0) const |
Return a debug string displaying the contents of the compressed array. | |
void | write (FILE *file) const |
Write the array in file. | |
void | read (FILE *file) |
Read the array from file. | |
Static Public Member Functions | |
template<class A> | |
static A | inverse (const A &array) |
template<class A> | |
static A | shift_array (const A &array, int k) |
template<class A> | |
static A | mask (const A &array, unsigned int k) |
Static Public Attributes | |
static const u64 | constant_size_cost = 5 |
Constant cost for storing shift value and pointer to inverse array to avoid compressing with small gain. | |
Private Attributes | |
Array | m_array |
The masked part of the compressed array. | |
CompressedArray * | m_inv_array |
The inverse part of the compressed array. | |
unsigned int | m_shift |
The amount of shift used in array compression. |
After the array is compressed, all write operations throw bit::invalid_call.
|
|
|
|
|
|
|
Create an array with initial size. The initial elements are guaranteed to be zero.
|
|
|
|
Compress the array.
Note that if
|
|
Return the number of bytes required to store the possibly recursively compressed array.
|
|
Return a debug string displaying the contents of the compressed array.
|
|
Return value of an element.
|
|
|
|
Return true if compressed.
|
|
Find the largest index that has a equal or smaller value than specified. This function is a specialized version of the general bit::last_leq() as described in Raj and Whittaker (2003).
|
|
|
|
Return the number of elements stored in the compressed array.
|
|
|
|
Compress the array once with the optimal compression width.
|
|
Read the array from file.
|
|
Compress the array and the resulting arrays recursively with the optimal compression width.
|
|
Change the number of elements in the array. The values of the possible new elements are guaranteed to be zero ONLY if the array has never been resized smaller.
|
|
Set the value of an element.
|
|
Set the value of an element growing the buffer if necessary. If the current capacity is not enough, the capacity is doubled (set to one from zero), and if that is not enough, the capacity is set to (elem+1).
|
|
Set the value of an element growing and widening the buffer if necessary. See set_grow() for info how capacity is handled and warnings about exceptions.
|
|
Change the width of the elements to given width. All elements must fit in the given width or bit::invalid_argument will be thrown and the array is guaranteed to be left in the original state.
|
|
Return the number bits used in the compression.
|
|
|
|
Uncompress the array. It is safe to call this for uncompressed array. |
|
Write the array in file.
|
|
Constant cost for storing shift value and pointer to inverse array to avoid compressing with small gain. This is computed as 1 byte for shift and 4 bytes for the pointer regardless of the machine architecture. |
|
The masked part of the compressed array.
|
|
The inverse part of the compressed array. If NULL, then the array is uncompressed, m_array contains the array, and m_shift is not defined. |
|
The amount of shift used in array compression.
|