8#ifndef HPP_ALIB_BITBUFFER_AC_V1_ALGOS
9#define HPP_ALIB_BITBUFFER_AC_V1_ALGOS 1
11#if !defined(HPP_ALIB_MONOMEM_DETAIL_ARRAY_COMPRESSION_ALLOW)
12# error "ALib sources with ending '.inl' must not be included from outside."
17namespace alib {
namespace bitbuffer {
namespace ac_v1 {
27 using TUI=
typename std::make_unsigned<TI>::type;
34 for(
size_t i= 0; i < data.
length(); ++i)
36 TUI val= data.
get( i );
37 int bytes=
sizeof(TUI);
55 for(
size_t i= 0; i < data.
length(); ++i)
57 TUI val= data.
get( i );
62 he.
Write(uint8_t (val >> bits ) );
77 using TUI=
typename std::make_unsigned<TI>::type;
82 for(
size_t i= 0; i < data.
length(); ++i)
85 int bytes=
sizeof(TUI);
108 for(
size_t i= 0; i < data.
length(); ++i)
122 using TUI=
typename std::make_unsigned<TI>::type;
123 for(
size_t i= 0; i < data.
length(); ++i)
134 using TUI=
typename std::make_unsigned<TI>::type;
148 for(
size_t i= 0; i < data.
length(); ++i )
159 using TUI=
typename std::make_unsigned<TI>::type;
161 TUI min = br.
Read<TUI>();
165 for(
size_t i= 0; i < data.
length(); ++i)
169 for(
size_t i= 0; i < data.
length(); ++i)
170 data.
set(i, br.
Read<TUI>( bitCnt ) + min );
182 using TUI=
typename std::make_unsigned<TI>::type;
183 TUI first= data.
get(0);
185 for(
size_t i= 1; i < data.
length(); ++i)
187 TUI second= data.
get(i);
208 using TUI=
typename std::make_unsigned<TI>::type;
209 auto prevVal= br.
Read<TUI>();
210 data.
set(0, prevVal);
211 for(
size_t i= 1; i < data.
length(); ++i)
212 data.
set(i, prevVal= br.
Read<1>() ? prevVal
223 using TUI=
typename std::make_unsigned<TI>::type;
233 auto maxSegLen = (std::numeric_limits<size_t>::min)();
236 for(
int pass= 0 ; pass < 2 ; ++ pass )
239 TUI val = data.
get(0);
245 size_t segEnd= segStart + 1;
249 if( segEnd == data.
length() )
255 val= data.
get(segEnd);
257 sparse= (prevVal == val);
260 while( ( (prevVal == val) == sparse )
261 && ++segEnd < data.
length())
264 val = data.
get(segEnd);
272 maxSegLen= (std::max)( maxSegLen, segEnd - segStart );
279 bw.
Write( bitCntRep +1, (segEnd - segStart) << 1 );
280 bw.
Write( bitCntVal , TUI(prevVal - data.
min ) );
284 bw.
Write( bitCntRep +1, ((segEnd - segStart) << 1) | 1 );
285 for(
size_t j= segStart; j < segEnd; ++j)
286 bw.
Write( bitCntVal, TUI(data.
get(j) - data.
min ) );
293 while( segStart < data.
length() );
303 | bitCntVal << (lang::Log2OfSize<uint32_t>()+1) );
316 using TUI=
typename std::make_unsigned<TI>::type;
317 if( !data.
length() )
return;
323 TUI minVal = br.
Read<TUI>();
326 while( segStart < data.
length() )
328 size_t cntRep= br.
Read<
size_t>( bitCntRep + 1 );
329 size_t segEnd= segStart + (cntRep >> 1);
330 if( (cntRep & 1) == 0 )
332 TUI val = br.
Read<TUI>( bitCntVal ) + minVal;
333 for(
size_t i= segStart ; i < segEnd ; ++i )
338 for(
size_t i= segStart ; i < segEnd ; ++i )
339 data.
set(i, br.
Read<TUI>( bitCntVal ) + minVal);
355 using TUI=
typename std::make_unsigned<TI>::type;
374 TUI first= data.
get(0);
376 for(
size_t i= 1; i < data.
length(); ++i)
380 TUI second= data.
get(i);
386 bool posNeg= second >= first;
388 bw.
Write(posNeg ? bitCntPos : bitCntNeg,
389 posNeg ? TUI( second - first - data.
minInc )
390 : TUI( first - second - data.
minDec ) );
406 using TUI=
typename std::make_unsigned<TI>::type;
416 auto minDiffPos= br.
Read<TUI>();
417 auto minDiffNeg= br.
Read<TUI>();
418 auto prevVal = br.
Read<TUI>();
419 data.
set(0, prevVal);
420 for(
size_t i= 1; i < data.
length(); ++i)
427 bool posNeg= br.
Read<1>();
428 TUI diff = br.
Read<TUI>( posNeg ? bitCntPos : bitCntNeg );
429 val = posNeg ? TUI( prevVal + minDiffPos + diff )
430 : TUI( prevVal - minDiffNeg - diff );
432 data.
set(i, prevVal= val);
Reads bits from a BitBufferBase.
Writes bits into a BitBufferBase.
void Write(TIntegral value)
TUI minDec
Minimum decrease between two adjacent values.
TUI minInc
Minimum increase between two adjacent values.
TUI maxInc
Maximum increase between two adjacent values.
TUI maxDec
Maximum decrease between two adjacent values.
ALIB_FORCE_INLINE size_t length() const
ALIB_FORCE_INLINE TUI get(size_t idx) const
TUI min
Maximum value (when zig-zag encoded)
TUI max
Maximum value (when zig-zag encoded)
ALIB_FORCE_INLINE void set(size_t idx, TUI value)
ALIB_API void Generate()
Generates the huffman encoding table and writes this information to the bit writer.
void Write(uint8_t symbol)
ALIB_FORCE_INLINE void CountSymbol(uint8_t symbol)
#define ALIB_WARNINGS_RESTORE
#define ALIB_WARNINGS_ALLOW_SHIFT_COUNT_OVERFLOW
void writeHuffman(BitWriter &bw, ArrayCompressor::Array< TI > &data)
void readSparse(BitReader &br, ArrayCompressor::Array< TI > &data)
void writeSparse(BitWriter &bw, ArrayCompressor::Array< TI > &data)
void readUncompressed(BitReader &br, ArrayCompressor::Array< TI > &data)
void readIncremental(BitReader &br, ArrayCompressor::Array< TI > &data)
void writeIncremental(BitWriter &bw, ArrayCompressor::Array< TI > &data)
void readVerySparse(BitReader &br, ArrayCompressor::Array< TI > &data)
void readMinMax(BitReader &br, ArrayCompressor::Array< TI > &data)
void writeUncompressed(BitWriter &bw, ArrayCompressor::Array< TI > &data)
void writeMinMax(BitWriter &bw, ArrayCompressor::Array< TI > &data)
void writeVerySparse(BitWriter &bw, ArrayCompressor::Array< TI > &data)
void readHuffman(BitReader &br, ArrayCompressor::Array< TI > &data)
constexpr TIntegral LowerMask()
constexpr int MSB0(TIntegral value)
constexpr int Log2OfSize()
constexpr int MSB(TIntegral value)
int ShiftOpRHS
Type alias in namespace alib.