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();
49 void destroy_compressor();
52 class cpc_compressor {
54 using vector_bytes = std::vector<uint8_t, typename std::allocator_traits<A>::template rebind_alloc<uint8_t>>;
55 using vector_u32 = std::vector<uint32_t, typename std::allocator_traits<A>::template rebind_alloc<uint32_t>>;
57 void compress(
const cpc_sketch_alloc<A>& source, compressed_state<A>& target)
const;
58 void uncompress(
const compressed_state<A>& source, uncompressed_state<A>& target, uint8_t lg_k, uint32_t num_coupons)
const;
64 uint32_t low_level_compress_bytes(
65 const uint8_t* byte_array,
66 uint32_t num_bytes_to_encode,
67 const uint16_t* encoding_table,
68 uint32_t* compressed_words
71 void low_level_uncompress_bytes(
73 uint32_t num_bytes_to_decode,
74 const uint16_t* decoding_table,
75 const uint32_t* compressed_words,
76 uint32_t num_compressed_words
83 uint32_t low_level_compress_pairs(
84 const uint32_t* pair_array,
85 uint32_t num_pairs_to_encode,
86 uint8_t num_base_bits,
87 uint32_t* compressed_words
90 void low_level_uncompress_pairs(
92 uint32_t num_pairs_to_decode,
93 uint8_t num_base_bits,
94 const uint32_t* compressed_words,
95 uint32_t num_compressed_words
100 uint16_t* decoding_tables_for_high_entropy_byte[22] = {
102 NULL, NULL, NULL, NULL,
103 NULL, NULL, NULL, NULL,
104 NULL, NULL, NULL, NULL,
105 NULL, NULL, NULL, NULL,
107 NULL, NULL, NULL, NULL, NULL, NULL
109 uint16_t* length_limited_unary_decoding_table65;
110 uint8_t* column_permutations_for_decoding[16] = {
111 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
112 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
116 friend cpc_compressor& get_compressor<A>();
119 friend void destroy_compressor<A>();
121 void make_decoding_tables();
122 void free_decoding_tables();
124 void compress_sparse_flavor(
const cpc_sketch_alloc<A>& source, compressed_state<A>& target)
const;
125 void compress_hybrid_flavor(
const cpc_sketch_alloc<A>& source, compressed_state<A>& target)
const;
126 void compress_pinned_flavor(
const cpc_sketch_alloc<A>& source, compressed_state<A>& target)
const;
127 void compress_sliding_flavor(
const cpc_sketch_alloc<A>& source, compressed_state<A>& target)
const;
129 void uncompress_sparse_flavor(
const compressed_state<A>& source, uncompressed_state<A>& target, uint8_t lg_k)
const;
130 void uncompress_hybrid_flavor(
const compressed_state<A>& source, uncompressed_state<A>& target, uint8_t lg_k)
const;
131 void uncompress_pinned_flavor(
const compressed_state<A>& source, uncompressed_state<A>& target, uint8_t lg_k, uint32_t num_coupons)
const;
132 void uncompress_sliding_flavor(
const compressed_state<A>& source, uncompressed_state<A>& target, uint8_t lg_k, uint32_t num_coupons)
const;
134 uint8_t* make_inverse_permutation(
const uint8_t* permu,
unsigned length);
135 uint16_t* make_decoding_table(
const uint16_t* encoding_table,
unsigned num_byte_values);
136 void validate_decoding_table(
const uint16_t* decoding_table,
const uint16_t* encoding_table)
const;
138 void compress_surprising_values(
const vector_u32& pairs, uint8_t lg_k, compressed_state<A>& result)
const;
139 void compress_sliding_window(
const uint8_t* window, uint8_t lg_k, uint32_t num_coupons, compressed_state<A>& target)
const;
141 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;
142 void uncompress_sliding_window(
const uint32_t* data, uint32_t data_words, vector_bytes& window, uint8_t lg_k, uint32_t num_coupons)
const;
144 static size_t safe_length_for_compressed_pair_buf(uint32_t k, uint32_t num_pairs, uint8_t num_base_bits);
145 static size_t safe_length_for_compressed_window_buf(uint32_t k);
146 static uint8_t determine_pseudo_phase(uint8_t lg_k, uint32_t c);
148 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);
149 static inline uint8_t golomb_choose_number_of_base_bits(uint32_t k, uint64_t count);
154 #include "cpc_compressor_impl.hpp"
DataSketches namespace.
Definition: binomial_bounds.hpp:38