JASSv2
Public Types | Public Member Functions | Static Public Member Functions | Static Private Attributes | List of all members
JASS::compress_integer Class Referenceabstract

Compression codexes for integer sequences. More...

#include <compress_integer.h>

Inheritance diagram for JASS::compress_integer:
Inheritance graph
[legend]

Public Types

typedef uint32_t integer
 This class and descendants will work on integers of this size. Do not change without also changing JASS_COMPRESS_INTEGER_BITS_PER_INTEGER.
 

Public Member Functions

 compress_integer ()
 Constructor.
 
virtual ~compress_integer ()
 Destructor.
 
virtual size_t encode (void *encoded, size_t encoded_buffer_length, const integer *source, size_t source_integers)=0
 Encode a sequence of integers returning the number of bytes used for the encoding, or 0 if the encoded sequence doesn't fit in the buffer. More...
 
virtual void decode (integer *decoded, size_t integers_to_decode, const void *source, size_t source_length)=0
 Decode a sequence of integers encoded with this codex. More...
 

Static Public Member Functions

static size_t d1_encode (integer *encoded, const integer *source, size_t source_integers)
 Convert an array of integers into an array of D1 (delta, d-gap) encoded integers. More...
 
static size_t d1_decode (integer *decoded, const integer *source, size_t source_integers)
 Convert a D1 encoded array of integers into an array of integers. More...
 
static size_t dn_encode (integer *encoded, const integer *source, size_t source_integers, size_t n=1)
 Convert an array of integers into an array of Dn (delta, d-gap) encoded integers with a gap of n. More...
 
static size_t dn_decode (integer *decoded, const integer *source, size_t source_integers, size_t n=1)
 Convert a Dn encoded array of integers into an array of integers. More...
 
static void unittest_one (compress_integer &encoder, const std::vector< uint32_t > &sequence)
 Test one sequence to make sure it encodes and decodes to the same thing. Assert if not. More...
 
static void unittest (compress_integer &compressor, uint32_t staring_from=0)
 Unit test this class, assert on failure. More...
 

Static Private Attributes

static constexpr int MAX_D_GAP = 64
 this is the maximum D-ness that this code supports, it can be changes to anything that won't reuslt in stack overflow. It is unlikely to exceed 16 for years (from 2019).
 

Detailed Description

Compression codexes for integer sequences.

To implement a codex you need to subclass this virtual base class and implement two methods, encode() and decode(). As those methods are virtual, an object of the given subclass is needed in order to encode or decode integer sequences.

Member Function Documentation

◆ d1_decode()

static size_t JASS::compress_integer::d1_decode ( integer decoded,
const integer source,
size_t  source_integers 
)
inlinestatic

Convert a D1 encoded array of integers into an array of integers.

Parameters
decoded[out] The decoded integers (can be the same buffer as source). source [in] The D1 encoded integers.
source_integers[in] The number of integers in the list.
Returns
The number of integers encoded.

◆ d1_encode()

static size_t JASS::compress_integer::d1_encode ( integer encoded,
const integer source,
size_t  source_integers 
)
inlinestatic

Convert an array of integers into an array of D1 (delta, d-gap) encoded integers.

Parameters
encoded[out] The d1-encoded result (can be the same buffer as source). source [in] The integers to be D1 encoded.
source_integers[in] The number of integers in the list.
Returns
The number of integers encoded.

◆ decode()

virtual void JASS::compress_integer::decode ( integer decoded,
size_t  integers_to_decode,
const void *  source,
size_t  source_length 
)
pure virtual

◆ dn_decode()

static size_t JASS::compress_integer::dn_decode ( integer decoded,
const integer source,
size_t  source_integers,
size_t  n = 1 
)
inlinestatic

Convert a Dn encoded array of integers into an array of integers.

Parameters
decoded[out] The decoded integers (can be the same buffer as source). source [in] The Dn encoded integers.
source_integers[in] The number of integers in the list.
n[in] The encoding distance (normally 1, but can be any inteter up-to source_integers).
Returns
The number of integers encoded.

◆ dn_encode()

static size_t JASS::compress_integer::dn_encode ( integer encoded,
const integer source,
size_t  source_integers,
size_t  n = 1 
)
inlinestatic

Convert an array of integers into an array of Dn (delta, d-gap) encoded integers with a gap of n.

Parameters
encoded[out] The Dn-encoded result (can be the same buffer as source). source [in] The integers to be Dn encoded.
source_integers[in] The number of integers in the list.
n[in] The encoding distance (normally 1, but can be any inteter up-to MAX_D_GAP).
Returns
The number of integers encoded.

◆ encode()

virtual size_t JASS::compress_integer::encode ( void *  encoded,
size_t  encoded_buffer_length,
const integer source,
size_t  source_integers 
)
pure virtual

Encode a sequence of integers returning the number of bytes used for the encoding, or 0 if the encoded sequence doesn't fit in the buffer.

Parameters
encoded[out] The sequence of bytes that is the encoded sequence.
encoded_buffer_length[in] The length (in bytes) of the output buffer, encoded.
source[in] The sequence of integers to encode.
source_integers[in] The length (in integers) of the source buffer.
Returns
The number of bytes used to encode the integer sequence, or 0 on error (i.e. overflow).

Implemented in JASS::compress_integer_qmx_original, JASS::compress_integer_elias_gamma_bitwise, JASS::compress_integer_simple_9, JASS::compress_integer_carry_8b, JASS::compress_integer_relative_10, JASS::compress_integer_qmx_improved, JASS::compress_integer_elias_delta_bitwise, JASS::compress_integer_simple_16, JASS::compress_integer_simple_8b, JASS::compress_integer_carryover_12, JASS::compress_integer_simple_9_packed, JASS::compress_integer_simple_8b_packed, JASS::compress_integer_elias_delta_simd, JASS::compress_integer_simple_16_packed, JASS::compress_integer_elias_delta_simd, JASS::compress_integer_elias_gamma_simd_vb, JASS::compress_integer_variable_byte, JASS::compress_integer_elias_gamma_simd, JASS::compress_integer_elias_gamma_simd, JASS::compress_integer_bitpack_32_reduced, JASS::compress_integer_qmx_jass_v1, JASS::compress_integer_stream_vbyte, JASS::compress_integer_none, JASS::compress_integer_elias_delta, JASS::compress_integer_elias_gamma, JASS::compress_integer_bitpack_128, JASS::compress_integer_bitpack_256, JASS::compress_integer_bitpack_64, JASS::compress_integer_lyck_16, and JASS::compress_integer_nybble_8.

◆ unittest()

void JASS::compress_integer::unittest ( compress_integer compressor,
uint32_t  staring_from = 0 
)
static

Unit test this class, assert on failure.

Parameters
compressor[in] a compressor
staring_from[in] normally 0. The bitness to start testing from (some schemes cannot encode a 0 (e.g. Elias gama) so use 1 in those cases).

◆ unittest_one()

void JASS::compress_integer::unittest_one ( compress_integer encoder,
const std::vector< uint32_t > &  sequence 
)
static

Test one sequence to make sure it encodes and decodes to the same thing. Assert if not.

Parameters
encoder[in] The integer encoded being tested.
sequence[in] the sequernce to encode.

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