Skip to content

Commit

Permalink
refactor: file_order -> fragment_order
Browse files Browse the repository at this point in the history
  • Loading branch information
mhx committed Aug 14, 2024
1 parent eba567c commit bb23511
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 84 deletions.
2 changes: 1 addition & 1 deletion cmake/libdwarfs.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ add_library(
src/writer/compression_metadata_requirements.cpp
src/writer/console_writer.cpp
src/writer/entry_factory.cpp
src/writer/file_order_options.cpp
src/writer/fragment_order_options.cpp
src/writer/filesystem_block_category_resolver.cpp
src/writer/filesystem_writer.cpp
src/writer/filter_debug.cpp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,18 @@
namespace dwarfs::writer {

// TODO: rename? -> inode_order_mode / fragment_order_mode
enum class file_order_mode { NONE, PATH, REVPATH, SIMILARITY, NILSIMSA };
enum class fragment_order_mode { NONE, PATH, REVPATH, SIMILARITY, NILSIMSA };

// TODO: rename? -> inode_order_options / fragment_order_options
struct file_order_options {
struct fragment_order_options {
static constexpr int const kDefaultNilsimsaMaxChildren{16384};
static constexpr int const kDefaultNilsimsaMaxClusterSize{16384};

file_order_mode mode{file_order_mode::NONE};
fragment_order_mode mode{fragment_order_mode::NONE};
int nilsimsa_max_children{kDefaultNilsimsaMaxChildren};
int nilsimsa_max_cluster_size{kDefaultNilsimsaMaxClusterSize};
};

std::ostream& operator<<(std::ostream& os, file_order_mode mode);
std::ostream& operator<<(std::ostream& os, fragment_order_mode mode);

} // namespace dwarfs::writer
6 changes: 3 additions & 3 deletions include/dwarfs/writer/fragment_order_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,16 @@
#include <string>
#include <string_view>

#include <dwarfs/writer/file_order_options.h>
#include <dwarfs/writer/fragment_order_options.h>

namespace dwarfs::writer {

struct fragment_order_parser {
public:
static std::string choices();

file_order_options parse(std::string_view arg) const;
std::string to_string(file_order_options const& opts) const;
fragment_order_options parse(std::string_view arg) const;
std::string to_string(fragment_order_options const& opts) const;
};

} // namespace dwarfs::writer
6 changes: 3 additions & 3 deletions include/dwarfs/writer/inode_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#include <string>

#include <dwarfs/writer/categorized_option.h>
#include <dwarfs/writer/file_order_options.h>
#include <dwarfs/writer/fragment_order_options.h>

namespace dwarfs::writer {

Expand All @@ -36,8 +36,8 @@ class categorizer_manager;
struct inode_options {
std::optional<size_t> max_similarity_scan_size;
std::shared_ptr<writer::categorizer_manager> categorizer_mgr;
writer::categorized_option<file_order_options> fragment_order{
file_order_options()};
writer::categorized_option<fragment_order_options> fragment_order{
fragment_order_options()};
};

} // namespace dwarfs::writer
Original file line number Diff line number Diff line change
Expand Up @@ -25,27 +25,27 @@
#include <fmt/format.h>

#include <dwarfs/error.h>
#include <dwarfs/writer/file_order_options.h>
#include <dwarfs/writer/fragment_order_options.h>

namespace dwarfs::writer {

std::ostream& operator<<(std::ostream& os, file_order_mode mode) {
std::ostream& operator<<(std::ostream& os, fragment_order_mode mode) {
std::string modestr{"unknown"};

switch (mode) {
case file_order_mode::NONE:
case fragment_order_mode::NONE:
modestr = "none";
break;
case file_order_mode::PATH:
case fragment_order_mode::PATH:
modestr = "path";
break;
case file_order_mode::REVPATH:
case fragment_order_mode::REVPATH:
modestr = "revpath";
break;
case file_order_mode::SIMILARITY:
case fragment_order_mode::SIMILARITY:
modestr = "similarity";
break;
case file_order_mode::NILSIMSA:
case fragment_order_mode::NILSIMSA:
modestr = "nilsimsa";
break;
}
Expand Down
35 changes: 18 additions & 17 deletions src/writer/fragment_order_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ namespace dwarfs::writer {

namespace {

const std::map<std::string_view, file_order_mode> order_choices{
{"none", file_order_mode::NONE},
{"path", file_order_mode::PATH},
{"revpath", file_order_mode::REVPATH},
{"similarity", file_order_mode::SIMILARITY},
{"nilsimsa", file_order_mode::NILSIMSA},
const std::map<std::string_view, fragment_order_mode> order_choices{
{"none", fragment_order_mode::NONE},
{"path", fragment_order_mode::PATH},
{"revpath", fragment_order_mode::REVPATH},
{"similarity", fragment_order_mode::SIMILARITY},
{"nilsimsa", fragment_order_mode::NILSIMSA},
};

} // namespace
Expand All @@ -53,8 +53,9 @@ std::string fragment_order_parser::choices() {

// TODO: find a common syntax for these options so we don't need
// complex parsers like this one
file_order_options fragment_order_parser::parse(std::string_view arg) const {
file_order_options rv;
fragment_order_options
fragment_order_parser::parse(std::string_view arg) const {
fragment_order_options rv;

option_map om(arg);
auto algo = om.choice();
Expand All @@ -67,12 +68,12 @@ file_order_options fragment_order_parser::parse(std::string_view arg) const {

if (om.has_options()) {
switch (rv.mode) {
case file_order_mode::NILSIMSA:
case fragment_order_mode::NILSIMSA:
rv.nilsimsa_max_children = om.get_size(
"max-children", file_order_options::kDefaultNilsimsaMaxChildren);
"max-children", fragment_order_options::kDefaultNilsimsaMaxChildren);
rv.nilsimsa_max_cluster_size =
om.get_size("max-cluster-size",
file_order_options::kDefaultNilsimsaMaxClusterSize);
fragment_order_options::kDefaultNilsimsaMaxClusterSize);

if (rv.nilsimsa_max_children < 1) {
throw std::runtime_error(fmt::format("invalid max-children value: {}",
Expand All @@ -98,21 +99,21 @@ file_order_options fragment_order_parser::parse(std::string_view arg) const {
}

std::string
fragment_order_parser::to_string(file_order_options const& opts) const {
fragment_order_parser::to_string(fragment_order_options const& opts) const {
switch (opts.mode) {
case file_order_mode::NONE:
case fragment_order_mode::NONE:
return "none";

case file_order_mode::PATH:
case fragment_order_mode::PATH:
return "path";

case file_order_mode::REVPATH:
case fragment_order_mode::REVPATH:
return "revpath";

case file_order_mode::SIMILARITY:
case fragment_order_mode::SIMILARITY:
return "similarity";

case file_order_mode::NILSIMSA:
case fragment_order_mode::NILSIMSA:
return fmt::format("nilsimsa:max_children={}:max_cluster_size={}",
opts.nilsimsa_max_children,
opts.nilsimsa_max_cluster_size);
Expand Down
34 changes: 17 additions & 17 deletions src/writer/internal/inode_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -420,14 +420,14 @@ class inode_ : public inode {
}

switch (opts.fragment_order.get(cat).mode) {
case file_order_mode::NONE:
case file_order_mode::PATH:
case file_order_mode::REVPATH:
case fragment_order_mode::NONE:
case fragment_order_mode::PATH:
case fragment_order_mode::REVPATH:
break;
case file_order_mode::SIMILARITY:
case fragment_order_mode::SIMILARITY:
sc.try_emplace(cat);
break;
case file_order_mode::NILSIMSA:
case fragment_order_mode::NILSIMSA:
nc.try_emplace(cat);
break;
}
Expand Down Expand Up @@ -483,20 +483,20 @@ class inode_ : public inode {
: opts.fragment_order.get(fragments_.get_single_category()).mode;

switch (order_mode) {
case file_order_mode::NONE:
case file_order_mode::PATH:
case file_order_mode::REVPATH:
case fragment_order_mode::NONE:
case fragment_order_mode::PATH:
case fragment_order_mode::REVPATH:
break;

case file_order_mode::SIMILARITY: {
case fragment_order_mode::SIMILARITY: {
similarity sc;
if (mm) {
scan_range(mm, sprog, chunk_size, sc);
}
similarity_.emplace<uint32_t>(sc.finalize());
} break;

case file_order_mode::NILSIMSA: {
case fragment_order_mode::NILSIMSA: {
nilsimsa nc;
if (mm) {
scan_range(mm, sprog, chunk_size, nc);
Expand Down Expand Up @@ -642,8 +642,8 @@ class inode_manager_ final : public inode_manager::impl {
}

return opts.fragment_order.any_is([](auto const& order) {
return order.mode == file_order_mode::SIMILARITY ||
order.mode == file_order_mode::NILSIMSA;
return order.mode == fragment_order_mode::SIMILARITY ||
order.mode == fragment_order_mode::NILSIMSA;
});
}

Expand Down Expand Up @@ -765,11 +765,11 @@ auto inode_manager_<LoggerPolicy>::ordered_span(
inode_ordering order(LOG_GET_LOGGER, prog_, opts_);

switch (opts.mode) {
case file_order_mode::NONE:
case fragment_order_mode::NONE:
LOG_VERBOSE << prefix << "keeping inode order";
break;

case file_order_mode::PATH: {
case fragment_order_mode::PATH: {
LOG_VERBOSE << prefix << "ordering " << span.size()
<< " inodes by path name...";
auto tv = LOG_CPU_TIMED_VERBOSE;
Expand All @@ -778,7 +778,7 @@ auto inode_manager_<LoggerPolicy>::ordered_span(
break;
}

case file_order_mode::REVPATH: {
case fragment_order_mode::REVPATH: {
LOG_VERBOSE << prefix << "ordering " << span.size()
<< " inodes by reverse path name...";
auto tv = LOG_CPU_TIMED_VERBOSE;
Expand All @@ -787,7 +787,7 @@ auto inode_manager_<LoggerPolicy>::ordered_span(
break;
}

case file_order_mode::SIMILARITY: {
case fragment_order_mode::SIMILARITY: {
LOG_VERBOSE << prefix << "ordering " << span.size()
<< " inodes by similarity...";
auto tv = LOG_CPU_TIMED_VERBOSE;
Expand All @@ -796,7 +796,7 @@ auto inode_manager_<LoggerPolicy>::ordered_span(
break;
}

case file_order_mode::NILSIMSA: {
case fragment_order_mode::NILSIMSA: {
LOG_VERBOSE << prefix << "ordering " << span.size()
<< " inodes using nilsimsa similarity...";
similarity_ordering_options soo;
Expand Down
Loading

0 comments on commit bb23511

Please sign in to comment.