diff --git a/czi-format/czi-parser/compression/benchmark.cpp b/czi-format/czi-parser/compression/benchmark.cpp index 2ac45f2681b7c05ba378f6917dbbcf5f171e967f..cd9529e72d1ae874cd0cf8801ad8e771b840265d 100644 --- a/czi-format/czi-parser/compression/benchmark.cpp +++ b/czi-format/czi-parser/compression/benchmark.cpp @@ -1,5 +1,18 @@ #include "benchmark.h" +template <typename T> +void save_histogram(const std::map<T, size_t> &histogram, const char *fileName) +{ + std::ofstream oStream = std::ofstream(fileName, std::ios::out); + + for (const std::pair<T, size_t> &pair : histogram) + { + oStream << pair.first << ";" << pair.second << std::endl; + } + oStream.flush(); + oStream.close(); +} + static void write_compression_report(const std::vector<BaseBenchmarkRecord> &results, const std::string &reportFile) { std::ofstream csvFile = std::ofstream(reportFile, std::ios::out); diff --git a/czi-format/czi-parser/main.cpp b/czi-format/czi-parser/main.cpp index b73ea25677605e1be627d0c96009b7127f3f6436..b1c207506c129f84c10eceeaa2109bfb9e51dbc2 100644 --- a/czi-format/czi-parser/main.cpp +++ b/czi-format/czi-parser/main.cpp @@ -29,6 +29,10 @@ void show_version() int main(int argc, char **argv) { + ByteArray ba = {10, 10, 10, 25, 65, 23, 59, 100, 23, 100, 25, 10}; + auto histo = vecUtil::create_histogram(ba); + save_histogram(histo, "histogram.csv"); + args::ArgumentParser argParser("CZI file tools", "Optional arguments are in `[]` necessary in `<>`."); // Groups args::Group cziFileGroup(argParser, "CZI file input - necessary.", args::Group::Validators::All); diff --git a/czi-format/czi-parser/utilities/vector_utilities.h b/czi-format/czi-parser/utilities/vector_utilities.h index 81edd9ef24a50819010c7ec29a8bf9d522fb1528..7e9a507d24e8d16c1d3990399699e1403f8df859 100644 --- a/czi-format/czi-parser/utilities/vector_utilities.h +++ b/czi-format/czi-parser/utilities/vector_utilities.h @@ -2,6 +2,7 @@ #include <vector> #include <algorithm> #include <limits> +#include <map> template <typename T> struct MinMax @@ -117,4 +118,25 @@ MinMax<T> find_min_max(const std::vector<T> &data) } return result; } + +template <typename T> +std::map<T, size_t> create_histogram(const std::vector<T> &data) +{ + std::map<T, size_t> histogram; + + T value; + for (size_t i = 0; i < data.size(); i++) + { + value = data[i]; + + if (histogram.count(value) == 0) + { + histogram[value] = 0; + } + + ++histogram[value]; + } + return histogram; +} + }; // namespace vecUtil