mirror of
https://github.com/mhx/dwarfs.git
synced 2025-09-16 07:46:27 -04:00
Clean up inode manager
This commit is contained in:
parent
63c9e9a3c3
commit
e3bbeac5d6
@ -161,7 +161,72 @@ class inode_manager_ : public inode_manager::impl {
|
||||
|
||||
void order_inodes(std::shared_ptr<script> scr, file_order_mode file_order,
|
||||
uint32_t first_inode,
|
||||
inode_manager::inode_cb const& fn) override {
|
||||
inode_manager::inode_cb const& fn) override;
|
||||
|
||||
void
|
||||
for_each_inode(std::function<void(std::shared_ptr<inode> const&)> const& fn)
|
||||
const override {
|
||||
for (const auto& ino : inodes_) {
|
||||
fn(ino);
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
void order_inodes_by_path() {
|
||||
std::vector<std::string> paths;
|
||||
std::vector<size_t> index(inodes_.size());
|
||||
|
||||
paths.reserve(inodes_.size());
|
||||
|
||||
for (auto const& ino : inodes_) {
|
||||
paths.emplace_back(ino->any()->path());
|
||||
}
|
||||
|
||||
std::iota(index.begin(), index.end(), size_t(0));
|
||||
|
||||
std::sort(index.begin(), index.end(),
|
||||
[&](size_t a, size_t b) { return paths[a] < paths[b]; });
|
||||
|
||||
std::vector<std::shared_ptr<inode>> tmp;
|
||||
tmp.reserve(inodes_.size());
|
||||
|
||||
for (size_t ix : index) {
|
||||
tmp.emplace_back(inodes_[ix]);
|
||||
}
|
||||
|
||||
inodes_.swap(tmp);
|
||||
}
|
||||
|
||||
void order_inodes_by_similarity() {
|
||||
std::sort(
|
||||
inodes_.begin(), inodes_.end(),
|
||||
[](const std::shared_ptr<inode>& a, const std::shared_ptr<inode>& b) {
|
||||
auto ash = a->similarity_hash();
|
||||
auto bsh = b->similarity_hash();
|
||||
return ash < bsh ||
|
||||
(ash == bsh && (a->size() > b->size() ||
|
||||
(a->size() == b->size() &&
|
||||
a->any()->path() < b->any()->path())));
|
||||
});
|
||||
}
|
||||
|
||||
void order_inodes_by_nilsimsa(inode_manager::inode_cb const& fn,
|
||||
uint32_t inode_no);
|
||||
|
||||
void number_inodes(size_t first_no) {
|
||||
for (auto& i : inodes_) {
|
||||
i->set_num(first_no++);
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<std::shared_ptr<inode>> inodes_;
|
||||
log_proxy<LoggerPolicy> log_;
|
||||
};
|
||||
|
||||
template <typename LoggerPolicy>
|
||||
void inode_manager_<LoggerPolicy>::order_inodes(
|
||||
std::shared_ptr<script> scr, file_order_mode file_order,
|
||||
uint32_t first_inode, inode_manager::inode_cb const& fn) {
|
||||
switch (file_order) {
|
||||
case file_order_mode::NONE:
|
||||
log_.info() << "keeping inode order";
|
||||
@ -211,46 +276,9 @@ class inode_manager_ : public inode_manager::impl {
|
||||
}
|
||||
}
|
||||
|
||||
void order_inodes_by_path() {
|
||||
std::vector<std::string> paths;
|
||||
std::vector<size_t> index(inodes_.size());
|
||||
|
||||
paths.reserve(inodes_.size());
|
||||
|
||||
for (auto const& ino : inodes_) {
|
||||
paths.emplace_back(ino->any()->path());
|
||||
}
|
||||
|
||||
std::iota(index.begin(), index.end(), size_t(0));
|
||||
|
||||
std::sort(index.begin(), index.end(),
|
||||
[&](size_t a, size_t b) { return paths[a] < paths[b]; });
|
||||
|
||||
std::vector<std::shared_ptr<inode>> tmp;
|
||||
tmp.reserve(inodes_.size());
|
||||
|
||||
for (size_t ix : index) {
|
||||
tmp.emplace_back(inodes_[ix]);
|
||||
}
|
||||
|
||||
inodes_.swap(tmp);
|
||||
}
|
||||
|
||||
void order_inodes_by_similarity() {
|
||||
std::sort(
|
||||
inodes_.begin(), inodes_.end(),
|
||||
[](const std::shared_ptr<inode>& a, const std::shared_ptr<inode>& b) {
|
||||
auto ash = a->similarity_hash();
|
||||
auto bsh = b->similarity_hash();
|
||||
return ash < bsh ||
|
||||
(ash == bsh && (a->size() > b->size() ||
|
||||
(a->size() == b->size() &&
|
||||
a->any()->path() < b->any()->path())));
|
||||
});
|
||||
}
|
||||
|
||||
void order_inodes_by_nilsimsa(inode_manager::inode_cb const& fn,
|
||||
uint32_t inode_no) {
|
||||
template <typename LoggerPolicy>
|
||||
void inode_manager_<LoggerPolicy>::order_inodes_by_nilsimsa(
|
||||
inode_manager::inode_cb const& fn, uint32_t inode_no) {
|
||||
auto finalize_inode = [&](auto& ino) {
|
||||
ino->set_num(inode_no++);
|
||||
fn(ino);
|
||||
@ -302,8 +330,7 @@ class inode_manager_ : public inode_manager::impl {
|
||||
auto& db = cache[b];
|
||||
return da.similarity > db.similarity ||
|
||||
(da.similarity == db.similarity &&
|
||||
(da.size > db.size ||
|
||||
(da.size == db.size && da.path < db.path)));
|
||||
(da.size > db.size || (da.size == db.size && da.path < db.path)));
|
||||
};
|
||||
|
||||
size_t depth = 0;
|
||||
@ -316,8 +343,7 @@ class inode_manager_ : public inode_manager::impl {
|
||||
if (index.size() > max_depth) {
|
||||
while (depth < max_depth && depth + depth_step < index.size()) {
|
||||
std::partial_sort(index.begin() + depth,
|
||||
index.begin() + depth + depth_step, index.end(),
|
||||
cmp);
|
||||
index.begin() + depth + depth_step, index.end(), cmp);
|
||||
depth += depth_step;
|
||||
if (cache[index[0]].similarity - cache[index[depth - 1]].similarity >
|
||||
sim_thresh_depth) {
|
||||
@ -373,25 +399,6 @@ class inode_manager_ : public inode_manager::impl {
|
||||
}
|
||||
}
|
||||
|
||||
void number_inodes(size_t first_no) {
|
||||
for (auto& i : inodes_) {
|
||||
i->set_num(first_no++);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
for_each_inode(std::function<void(std::shared_ptr<inode> const&)> const& fn)
|
||||
const override {
|
||||
for (const auto& ino : inodes_) {
|
||||
fn(ino);
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
std::vector<std::shared_ptr<inode>> inodes_;
|
||||
log_proxy<LoggerPolicy> log_;
|
||||
};
|
||||
|
||||
inode_manager::inode_manager(logger& lgr)
|
||||
: impl_(make_unique_logging_object<impl, inode_manager_, logger_policies>(
|
||||
lgr)) {}
|
||||
|
Loading…
x
Reference in New Issue
Block a user