Figured out class organization

pull/1/head
Clyne 5 years ago committed by GitHub
parent bb8510a962
commit c4a598007b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -9,25 +9,13 @@
* @tparam data Expected to be a null-terminated `char` of data to be compressed.
*/
template<auto data>
struct huffman_compress
class huffman_compress
{
using size_t = unsigned long int;
// Contains the compressed data.
unsigned char output[size()] = {};
// Contains a 'tree' that can be used to decompress the data.
unsigned char decode_tree[3 * tree_count()] = {};
// Returns the size of the compressed data, in bytes.
consteval static auto size() { return output_size().first; }
// Returns how many of the bits in the last byte of `output` are actually part of the data.
consteval static auto lastbitscount() { return output_size().second; }
consteval huffman_compress() {
build_decode_tree();
compress();
}
// The internals for this class needed to be defined before they're used in
// the public interface. Scroll to the next `public` section for usable variables/functions.
private:
// Node structure used for tree-building.
struct node {
int value = 0;
@ -160,6 +148,22 @@ struct huffman_compress
}
delete[] tree.data();
}
public:
// Returns the size of the compressed data, in bytes.
consteval static auto size() { return output_size().first; }
// Returns how many of the bits in the last byte of `output` are actually part of the data.
consteval static auto lastbitscount() { return output_size().second; }
// Contains the compressed data.
unsigned char output[size()] = {};
// Contains a 'tree' that can be used to decompress the data.
unsigned char decode_tree[3 * tree_count()] = {};
consteval huffman_compress() {
build_decode_tree();
compress();
}
};
#endif // TCSULLIVAN_CONSTEVAL_HUFFMAN_HPP_

Loading…
Cancel
Save