From edd9cb61cca248e27396492ff2d3d4d844cba52a Mon Sep 17 00:00:00 2001 From: clyne Date: Sun, 27 Dec 2020 21:31:59 -0500 Subject: [PATCH] Add usize_t, now obeys -pedantic --- consteval_huffman.hpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/consteval_huffman.hpp b/consteval_huffman.hpp index a1517ec..0ca7aae 100644 --- a/consteval_huffman.hpp +++ b/consteval_huffman.hpp @@ -22,6 +22,7 @@ template::length(dat class huffman_compress { using size_t = long int; + using usize_t = decltype(data_length); // Note: class internals need to be defined before the public interface. private: @@ -46,7 +47,7 @@ private: auto list = std::span(new node[256] {}, 256); for (int i = 0; i < 256; i++) list[i].value = i; - for (size_t i = 0; i < data_length; i++) + for (usize_t i = 0; i < data_length; i++) list[data[i]].freq++; std::sort(list.begin(), list.end(), @@ -141,7 +142,7 @@ private: auto tree = build_node_tree(); size_t bytes = 1, bits = 0; - for (size_t i = 0; i < data_length; i++) { + for (usize_t i = 0; i < data_length; i++) { auto leaf = std::find_if(tree.begin(), tree.end(), [c = data[i]](const auto& n) { return n.value == c; }); @@ -197,11 +198,11 @@ private: consteval void build_decode_tree() { auto tree = build_node_tree(); - for (size_t i = 0; i < tree_count(); i++) { + for (usize_t i = 0; i < tree_count(); i++) { // Only store node value if it represents a data value decode_tree[i * 3] = tree[i].value <= 0xFF ? tree[i].value : 0; - size_t j; + usize_t j; // Find the left child of this node for (j = i + 1; j < tree_count(); j++) { if (tree[i].left == tree[j].value) @@ -327,4 +328,3 @@ private: }; #endif // TCSULLIVAN_CONSTEVAL_HUFFMAN_HPP_ -