Skip to content
This repository has been archived by the owner on Dec 22, 2024. It is now read-only.

Commit

Permalink
Finish migration to stingray::hash_t
Browse files Browse the repository at this point in the history
Not quite sure I want to keep it this way.
  • Loading branch information
Xaymar committed Mar 1, 2024
1 parent 5d6ade2 commit 640ec7f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
6 changes: 3 additions & 3 deletions source/hash_db.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,19 +57,19 @@ hellextractor::hash_db::hash_db(std::filesystem::path db_file) : _strings(), _ha
}

// Everything else gets added.
uint64_t hash = *reinterpret_cast<uint64_t const*>(hasher->hash(line.data(), line.length()).data());
stingray::hash_t hash = *reinterpret_cast<stingray::hash_t const*>(hasher->hash(line.data(), line.length()).data());

_hashes.emplace(line, hash);
_strings.emplace(hash, line);
}
}

std::map<uint64_t, std::string> const& hellextractor::hash_db::strings()
std::map<stingray::hash_t, std::string> const& hellextractor::hash_db::strings()
{
return _strings;
}

std::map<std::string, uint64_t> const& hellextractor::hash_db::hashes()
std::map<std::string, stingray::hash_t> const& hellextractor::hash_db::hashes()
{
return _hashes;
}
9 changes: 5 additions & 4 deletions source/hash_db.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,21 @@
#pragma once
#include <filesystem>
#include <map>
#include "stingray.hpp"

namespace hellextractor {
class hash_db {
std::map<uint64_t, std::string> _strings;
std::map<std::string, uint64_t> _hashes;
std::map<stingray::hash_t, std::string> _strings;
std::map<std::string, stingray::hash_t> _hashes;

public:
~hash_db();
hash_db();
hash_db(std::filesystem::path db_file);

std::map<uint64_t, std::string> const& strings();
std::map<stingray::hash_t, std::string> const& strings();

std::map<std::string, uint64_t> const& hashes();
std::map<std::string, stingray::hash_t> const& hashes();
};

} // namespace hellextractor
6 changes: 3 additions & 3 deletions source/mode_extract.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ int32_t mode_extract(std::vector<std::string> const& args)
auto meta = file.second;
stats_total++;

auto translations = [](uint64_t hash, std::list<hellextractor::hash_db>& primary, std::list<hellextractor::hash_db>& secondary) {
auto translations = [](stingray::hash_t hash, std::list<hellextractor::hash_db>& primary, std::list<hellextractor::hash_db>& secondary) {
std::vector<std::string> translations;

for (auto& db : primary) {
Expand All @@ -295,15 +295,15 @@ int32_t mode_extract(std::vector<std::string> const& args)
};

// Match the name with the name databases.
auto file_names = translations(static_cast<uint64_t>(meta.file.id), namedbs, strings);
auto file_names = translations(meta.file.id, namedbs, strings);
if (file_names.size() > 0) {
++stats_names;
}
file_names.emplace_back(string_printf("%016" PRIx64, (uint64_t)meta.file.id));
file_names.emplace_back(string_printf("%016" PRIx64, bswap64((uint64_t)meta.file.id)));

// Match the type with the type databases.
auto file_types = translations(static_cast<uint64_t>(meta.file.type), typedbs, strings);
auto file_types = translations(meta.file.type, typedbs, strings);
if (file_types.size() > 0) {
++stats_types;
}
Expand Down

0 comments on commit 640ec7f

Please sign in to comment.