Skip to content

Commit

Permalink
Expand transparent hashing
Browse files Browse the repository at this point in the history
  • Loading branch information
wichtounet committed Sep 27, 2023
1 parent 69b9ada commit 519d663
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 16 deletions.
2 changes: 1 addition & 1 deletion include/cpp_utils
Submodule cpp_utils updated 1 files
+48 −0 hash.hpp
17 changes: 2 additions & 15 deletions src/overview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

#include "cpp_utils/assert.hpp"

#include "cpp_utils/hash.hpp"
#include "overview.hpp"
#include "console.hpp"
#include "data_cache.hpp"
Expand Down Expand Up @@ -266,21 +267,7 @@ void add_values_column(budget::month month,
add_recap_line(contents, title, total);
}

struct icompare_str {
bool operator()(const std::string& lhs, const std::string& rhs) const {
// Note: This is very fast, but not very good for locale
return strcasecmp(lhs.c_str(), rhs.c_str()) == 0;
}

size_t operator()(const std::string& value) const {
auto l_value = value;
std::transform(l_value.begin(), l_value.end(), l_value.begin(), ::tolower);
const std::hash<std::string> hasher;
return hasher(l_value);
}
};

using acc_data_t = std::unordered_map<std::string, std::unordered_map<std::string, budget::money, icompare_str, icompare_str>>;
using acc_data_t = cpp::string_hash_map<cpp::istring_hash_map<budget::money>>;

template<typename Data, typename Functor>
std::pair<budget::money, acc_data_t> aggregate(const Data & data, bool full, bool disable_groups, const std::string& separator, Functor&& func){
Expand Down

0 comments on commit 519d663

Please sign in to comment.