From f2afa2a421e2b53561624ddea484cdc247061b36 Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Sun, 6 Dec 2020 08:48:20 +1000 Subject: [PATCH] analyse: move default chunk params into params header --- emory/chunk/params.hpp | 6 ++++++ tools/analyse.cpp | 29 ++++++++++++----------------- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/emory/chunk/params.hpp b/emory/chunk/params.hpp index f0bfed6..2dd4e06 100644 --- a/emory/chunk/params.hpp +++ b/emory/chunk/params.hpp @@ -19,4 +19,10 @@ namespace emory::chunk { /// The minimum number of bytes for a matching region. std::ptrdiff_t minimum; }; + + constexpr params DEFAULT_PARAMS { + .bits = 12, + .window = 8, + .minimum = 4096, + }; } diff --git a/tools/analyse.cpp b/tools/analyse.cpp index 98a3140..ce15b64 100644 --- a/tools/analyse.cpp +++ b/tools/analyse.cpp @@ -69,32 +69,27 @@ enum { }; -static constexpr std::size_t DEFAULT_BITS = 12; -static constexpr std::size_t DEFAULT_WINDOW = 4; -static constexpr std::ptrdiff_t DEFAULT_MINIMUM = 512; - - //----------------------------------------------------------------------------- int main (int argc, char const **argv) { if (argc < NUM_ARGS_REQUIRED) { std::cerr << "usage: " << argv[ARG_SELF] << " [bits] [window] [minimum]\n" - << "default bits = " << DEFAULT_BITS << '\n' - << "default window = " << DEFAULT_WINDOW << '\n' - << "default minimum = " << DEFAULT_MINIMUM << '\n'; + << "default bits = " << emory::chunk::DEFAULT_PARAMS.bits << '\n' + << "default window = " << emory::chunk::DEFAULT_PARAMS.window << '\n' + << "default minimum = " << emory::chunk::DEFAULT_PARAMS.minimum << '\n'; return EXIT_FAILURE; } - #define PARSE_DEFAULT(NAME, TYPE) \ - argc > ARG_##NAME \ - ? cruft::parse::from_string (argv[ARG_##NAME]) \ - : DEFAULT_##NAME + emory::chunk::params p = emory::chunk::DEFAULT_PARAMS; + if (argc > ARG_BITS) + p.window = cruft::parse::from_string (argv[ARG_WINDOW]); + if (argc > ARG_WINDOW) + p.window = cruft::parse::from_string (argv[ARG_BITS]); + if (argc > ARG_BITS) + p.minimum = cruft::parse::from_string (argv[ARG_MINIMUM]); + + std::cerr << p << '\n'; - emory::chunk::params const p { - .bits = PARSE_DEFAULT (BITS, std::size_t), - .window = PARSE_DEFAULT (WINDOW, std::size_t), - .minimum = PARSE_DEFAULT (MINIMUM, std::ptrdiff_t), - }; cruft::mapped_file data (argv[ARGS_INPUT]); std::cout << "size: " << data.size () << '\n';