Skip to content

Commit

Permalink
0.6.2 A huge (~1000 times) improvement in the filename collision test.
Browse files Browse the repository at this point in the history
  • Loading branch information
ANGulchenko committed Jul 14, 2022
1 parent ac2e201 commit 6185d59
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 26 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG
Original file line number Original file line Diff line number Diff line change
@@ -1,3 +1,9 @@
─────────────────┨ 0.6.2 ┠─────────────────
1) Significant improvement (~1000 times faster) of the collision test.
This test checks for the identical result filenames. While moving
identical names will cause data loss. Test run with ~21k filenames
decreased it's runtime from ~18 seconds to ~20k microseconds!

─────────────────┨ 0.6.1 ┠───────────────── ─────────────────┨ 0.6.1 ┠─────────────────
1) Fixed bug in RuleDir for a top level files. 1) Fixed bug in RuleDir for a top level files.


Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Original file line Diff line number Diff line change
@@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 3.5) cmake_minimum_required(VERSION 3.5)


project(nomenus-rex project(nomenus-rex
VERSION 0.6.1 VERSION 0.6.2
HOMEPAGE_URL "https://github.com/ANGulchenko/nomenus-rex" HOMEPAGE_URL "https://github.com/ANGulchenko/nomenus-rex"
DESCRIPTION "Nomenus-rex is a CLI utility for the file mass-renaming.") DESCRIPTION "Nomenus-rex is a CLI utility for the file mass-renaming.")


Expand Down
42 changes: 19 additions & 23 deletions renamer.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -46,42 +46,42 @@ void Renamer::setSortMode(SortMode mode)


void Renamer::addDateRule(const std::string& format) void Renamer::addDateRule(const std::string& format)
{ {
rules.push_back(unique_ptr<RuleBase>(new RuleDate(format))); rules.push_back(std::unique_ptr<RuleBase>(new RuleDate(format)));
} }


void Renamer::addTextRule(const std::string& text) void Renamer::addTextRule(const std::string& text)
{ {
rules.push_back(unique_ptr<RuleBase>(new RuleText(text))); rules.push_back(std::unique_ptr<RuleBase>(new RuleText(text)));
} }


void Renamer::addDirRule(RuleDir::Mode mode, const std::string& separator) void Renamer::addDirRule(RuleDir::Mode mode, const std::string& separator)
{ {
rules.push_back(unique_ptr<RuleBase>(new RuleDir(mode, separator))); rules.push_back(std::unique_ptr<RuleBase>(new RuleDir(mode, separator)));
} }


void Renamer::addIntegerRule(RuleInteger::Mode mode, int start, int step, int padding) void Renamer::addIntegerRule(RuleInteger::Mode mode, int start, int step, int padding)
{ {
rules.push_back(unique_ptr<RuleBase>(new RuleInteger(mode, start, step, padding))); rules.push_back(std::unique_ptr<RuleBase>(new RuleInteger(mode, start, step, padding)));
} }


void Renamer::addExtensionRule(RuleExtension::Mode mode, const std::string& ext) void Renamer::addExtensionRule(RuleExtension::Mode mode, const std::string& ext)
{ {
rules.push_back(unique_ptr<RuleBase>(new RuleExtension(mode, ext))); rules.push_back(std::unique_ptr<RuleBase>(new RuleExtension(mode, ext)));
} }


void Renamer::addFilenameRule(RuleFilename::Mode mode) void Renamer::addFilenameRule(RuleFilename::Mode mode)
{ {
rules.push_back(unique_ptr<RuleBase>(new RuleFilename(mode))); rules.push_back(std::unique_ptr<RuleBase>(new RuleFilename(mode)));
} }


void Renamer::addFilesizeRule(RuleFilesize::Dimension dimention, bool show_dimention, const std::string& decimal_separator) void Renamer::addFilesizeRule(RuleFilesize::Dimension dimention, bool show_dimention, const std::string& decimal_separator)
{ {
rules.push_back(unique_ptr<RuleBase>(new RuleFilesize(dimention, decimal_separator, show_dimention))); rules.push_back(std::unique_ptr<RuleBase>(new RuleFilesize(dimention, decimal_separator, show_dimention)));
} }


void Renamer::addReplaceRule(const std::string& what, const std::string& to) void Renamer::addReplaceRule(const std::string& what, const std::string& to)
{ {
rules.push_back(unique_ptr<RuleBase>(new RuleReplace(what, to))); rules.push_back(std::unique_ptr<RuleBase>(new RuleReplace(what, to)));
} }




Expand All @@ -90,7 +90,7 @@ fs::path Renamer::applyRulesToOneFilename(const fs::path& _relative_path)
{ {
std::string new_filename; std::string new_filename;


for (unique_ptr<RuleBase>& rule: rules) for (std::unique_ptr<RuleBase>& rule: rules)
{ {
RuleBase* tempBasePtr = rule.get(); RuleBase* tempBasePtr = rule.get();


Expand Down Expand Up @@ -172,23 +172,20 @@ void Renamer::createRenameBijection()


void Renamer::testRenameBijection() const void Renamer::testRenameBijection() const
{ {

std::map<fs::path, fs::path> result; std::map<fs::path, fs::path> result;
auto starting_point = rename_vector.begin(); std::set<std::string> new_names;
auto runner = starting_point;
while (starting_point != rename_vector.end()) size_t new_names_prev_size = 0;
for (auto& pair: rename_vector)
{ {
runner = starting_point; new_names.insert(pair.second);
runner++; if (new_names.size() == new_names_prev_size)
while (runner != rename_vector.end())
{ {
if ((*runner).second == (*starting_point).second) // Insertion did nothing, so there was this name already;
{ result[pair.first] = pair.second;
result[(*runner).first] = (*runner).second;
}
runner++;
} }

new_names_prev_size = new_names.size();
starting_point++;
} }


if (result.size() > 0) if (result.size() > 0)
Expand All @@ -201,7 +198,6 @@ void Renamer::testRenameBijection() const
} }
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }

} }


void Renamer::executeRenameBijection() void Renamer::executeRenameBijection()
Expand Down
3 changes: 1 addition & 2 deletions renamer.h
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include <memory> #include <memory>


#include "Rules/rules.h" #include "Rules/rules.h"
using std::unique_ptr;


namespace fs = std::filesystem; namespace fs = std::filesystem;


Expand Down Expand Up @@ -49,7 +48,7 @@ class Renamer
bool keep_dir_structure; bool keep_dir_structure;
CopyOrRename copy_or_rename; CopyOrRename copy_or_rename;
SortMode sort_mode; SortMode sort_mode;
std::vector<unique_ptr<RuleBase>> rules; std::vector<std::unique_ptr<RuleBase>> rules;
std::vector<std::pair<fs::path, fs::path>> rename_vector; std::vector<std::pair<fs::path, fs::path>> rename_vector;


void getSourceFilenames(std::vector<std::pair<fs::path, fs::path>>& rename_vector, const fs::path& source_dir); void getSourceFilenames(std::vector<std::pair<fs::path, fs::path>>& rename_vector, const fs::path& source_dir);
Expand Down

0 comments on commit 6185d59

Please sign in to comment.