1
0
Fork 0
mirror of https://github.com/KingDuckZ/dindexer.git synced 2025-08-17 15:19:48 +00:00

Implement SSE2 Tiger hashing.

This commit is contained in:
King_DuckZ 2015-11-09 16:50:56 +00:00
parent d07dc9a7da
commit 1dee8e0f83
8 changed files with 1695 additions and 28 deletions

View file

@ -17,46 +17,118 @@
#include "indexer.hpp"
#include "pathname.hpp"
#include "tiger.hpp"
#include <algorithm>
#include <vector>
#include <string>
#include <atomic>
#include <cstdint>
#include <ciso646>
#if !defined(NDEBUG)
# include <iostream>
#endif
namespace din {
bool Indexer::add_path (const char* parPath, int parLevel, bool parIsDir, bool) {
if (parLevel > 0) {
PathLists& path_lists = (parIsDir ? m_directories : m_files);
const auto size = static_cast<std::size_t>(parLevel);
typedef TigerHash HashType;
if (size > path_lists.size()) {
path_lists.resize(size);
struct FileEntry {
FileEntry ( const char* parPath, int parLevel, bool parIsDir, bool parIsSymLink) :
path(parPath),
hash {},
level(static_cast<uint16_t>(parLevel)),
is_dir(parIsDir),
is_symlink(parIsSymLink)
{
}
FileEntry ( const FileEntry& ) = delete;
FileEntry ( FileEntry&& ) = default;
FileEntry& operator= ( const FileEntry& ) = delete;
FileEntry& operator= ( FileEntry&& ) = default;
bool operator< ( const FileEntry& parOther ) const;
std::string path;
HashType hash;
uint16_t level;
bool is_dir;
bool is_symlink;
};
struct Indexer::LocalData {
typedef std::vector<FileEntry> PathList;
PathList paths;
std::string base_path;
std::atomic<std::size_t> done_count;
std::size_t file_count;
};
bool FileEntry::operator< (const FileEntry& parOther) const {
return (this->level < parOther.level)
or (this->level == parOther.level and this->path < parOther.path);
}
Indexer::Indexer() :
m_local_data(new LocalData)
{
m_local_data->done_count = 0;
m_local_data->file_count = 0;
}
Indexer::~Indexer() {
}
std::size_t Indexer::total_items() const {
return m_local_data->file_count;
}
std::size_t Indexer::processed_items() const {
return m_local_data->done_count;
}
void Indexer::calculate_hash() {
std::sort(m_local_data->paths.begin(), m_local_data->paths.end());
HashType dir_hash;
tiger_init_hash(dir_hash);
for (auto& cur_itm : m_local_data->paths) {
if (not cur_itm.is_dir) {
std::cout << "Hashing " << cur_itm.path << "...";
tiger_init_hash(cur_itm.hash);
tiger_file(cur_itm.path, cur_itm.hash, dir_hash);
std::cout << " --> " << tiger_to_string(cur_itm.hash) << '\n';
}
}
}
std::string path(parPath);
auto insert_point = std::lower_bound(path_lists[size - 1].begin(), path_lists[size - 1].end(), path);
path_lists[size - 1].insert(insert_point, std::move(path));
bool Indexer::add_path (const char* parPath, int parLevel, bool parIsDir, bool parIsSymLink) {
if (parLevel > 0) {
m_local_data->paths.push_back(FileEntry(parPath, parLevel, parIsDir, parIsSymLink));
if (not parIsDir) {
++m_local_data->file_count;
}
} else {
m_base_path = parPath;
m_local_data->base_path = parPath;
}
return true;
}
#if !defined(NDEBUG)
void Indexer::dump() const {
PathName base_path(m_base_path);
PathName base_path(m_local_data->base_path);
std::cout << "---------------- FILE LIST ----------------\n";
for (const auto& cur_list : m_files) {
for (const auto& cur_itm : cur_list) {
PathName cur_path(cur_itm);
for (const auto& cur_itm : m_local_data->paths) {
if (not cur_itm.is_dir) {
PathName cur_path(cur_itm.path);
std::cout << make_relative_path(base_path, cur_path).path() << '\n';
}
}
std::cout << "---------------- DIRECTORY LIST ----------------\n";
for (const auto& cur_list : m_directories) {
for (const auto& cur_itm : cur_list) {
PathName cur_path(cur_itm);
for (const auto& cur_itm : m_local_data->paths) {
if (cur_itm.is_dir) {
PathName cur_path(cur_itm.path);
std::cout << make_relative_path(base_path, cur_path).path() << '\n';
}
}