aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorclyne <clyne@bitgloo.com>2020-07-01 17:21:59 -0400
committerGitHub <noreply@github.com>2020-07-01 17:21:59 -0400
commitc4a598007b33f9d6f678822633845bfe1de467ef (patch)
tree1f9c94fcf52756abe515bca46b60c8d27654c533
parentbb8510a962aceb4efd630832005f4e61fa346ee1 (diff)
Figured out class organization
-rw-r--r--consteval_huffman.hpp36
1 files changed, 20 insertions, 16 deletions
diff --git a/consteval_huffman.hpp b/consteval_huffman.hpp
index 9dde53a..b7ea819 100644
--- a/consteval_huffman.hpp
+++ b/consteval_huffman.hpp
@@ -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_