22 #ifndef CPC_COMPRESSOR_HPP_
23 #define CPC_COMPRESSOR_HPP_
25 #include "cpc_common.hpp"
39 template<
typename A>
class cpc_sketch_alloc;
40 template<
typename A>
class cpc_compressor;
45 inline cpc_compressor<A>& get_compressor();
48 class cpc_compressor {
50 using vector_bytes = std::vector<uint8_t, typename std::allocator_traits<A>::template rebind_alloc<uint8_t>>;
51 using vector_u32 = std::vector<uint32_t, typename std::allocator_traits<A>::template rebind_alloc<uint32_t>>;
53 void compress(
const cpc_sketch_alloc<A>& source, compressed_state<A>& target)
const;
54 void uncompress(
const compressed_state<A>& source, uncompressed_state<A>& target, uint8_t lg_k, uint32_t num_coupons)
const;
60 uint32_t low_level_compress_bytes(
61 const uint8_t* byte_array,
62 uint32_t num_bytes_to_encode,
63 const uint16_t* encoding_table,
64 uint32_t* compressed_words
67 void low_level_uncompress_bytes(
69 uint32_t num_bytes_to_decode,
70 const uint16_t* decoding_table,
71 const uint32_t* compressed_words,
72 uint32_t num_compressed_words
79 uint32_t low_level_compress_pairs(
80 const uint32_t* pair_array,
81 uint32_t num_pairs_to_encode,
82 uint8_t num_base_bits,
83 uint32_t* compressed_words
86 void low_level_uncompress_pairs(
88 uint32_t num_pairs_to_decode,
89 uint8_t num_base_bits,
90 const uint32_t* compressed_words,
91 uint32_t num_compressed_words
96 uint16_t* decoding_tables_for_high_entropy_byte[22] = {
98 NULL, NULL, NULL, NULL,
99 NULL, NULL, NULL, NULL,
100 NULL, NULL, NULL, NULL,
101 NULL, NULL, NULL, NULL,
103 NULL, NULL, NULL, NULL, NULL, NULL
105 uint16_t* length_limited_unary_decoding_table65;
106 uint8_t* column_permutations_for_decoding[16] = {
107 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
108 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
112 template<
typename T>
friend cpc_compressor<T>& get_compressor();
115 void make_decoding_tables();
116 void free_decoding_tables();
118 void compress_sparse_flavor(
const cpc_sketch_alloc<A>& source, compressed_state<A>& target)
const;
119 void compress_hybrid_flavor(
const cpc_sketch_alloc<A>& source, compressed_state<A>& target)
const;
120 void compress_pinned_flavor(
const cpc_sketch_alloc<A>& source, compressed_state<A>& target)
const;
121 void compress_sliding_flavor(
const cpc_sketch_alloc<A>& source, compressed_state<A>& target)
const;
123 void uncompress_sparse_flavor(
const compressed_state<A>& source, uncompressed_state<A>& target, uint8_t lg_k)
const;
124 void uncompress_hybrid_flavor(
const compressed_state<A>& source, uncompressed_state<A>& target, uint8_t lg_k)
const;
125 void uncompress_pinned_flavor(
const compressed_state<A>& source, uncompressed_state<A>& target, uint8_t lg_k, uint32_t num_coupons)
const;
126 void uncompress_sliding_flavor(
const compressed_state<A>& source, uncompressed_state<A>& target, uint8_t lg_k, uint32_t num_coupons)
const;
128 uint8_t* make_inverse_permutation(
const uint8_t* permu,
unsigned length);
129 uint16_t* make_decoding_table(
const uint16_t* encoding_table,
unsigned num_byte_values);
130 void validate_decoding_table(
const uint16_t* decoding_table,
const uint16_t* encoding_table)
const;
132 void compress_surprising_values(
const vector_u32& pairs, uint8_t lg_k, compressed_state<A>& result)
const;
133 void compress_sliding_window(
const uint8_t* window, uint8_t lg_k, uint32_t num_coupons, compressed_state<A>& target)
const;
135 vector_u32 uncompress_surprising_values(
const uint32_t* data, uint32_t data_words, uint32_t num_pairs, uint8_t lg_k,
const A& allocator)
const;
136 void uncompress_sliding_window(
const uint32_t* data, uint32_t data_words, vector_bytes& window, uint8_t lg_k, uint32_t num_coupons)
const;
138 static size_t safe_length_for_compressed_pair_buf(uint32_t k, uint32_t num_pairs, uint8_t num_base_bits);
139 static size_t safe_length_for_compressed_window_buf(uint32_t k);
140 static uint8_t determine_pseudo_phase(uint8_t lg_k, uint32_t c);
142 static inline vector_u32 tricky_get_pairs_from_window(
const uint8_t* window, uint32_t k, uint32_t num_pairs_to_get, uint32_t empty_space,
const A& allocator);
143 static inline uint8_t golomb_choose_number_of_base_bits(uint32_t k, uint64_t count);
148 #include "cpc_compressor_impl.hpp"
DataSketches namespace.
Definition: binomial_bounds.hpp:38