Last active
April 9, 2017 12:49
-
-
Save deque-blog/1157da99e5ee033e770befe84c539764 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
template < | |
typename LhsForwardIterator, | |
typename RhsForwardIterator, | |
typename Equal = std::equal_to<typename LhsForwardIterator::value_type>, | |
typename Hash = std::hash<typename LhsForwardIterator::value_type> | |
> | |
bool is_permutation_hash( | |
LhsForwardIterator lhs_first, LhsForwardIterator lhs_last, | |
RhsForwardIterator rhs_first, RhsForwardIterator rhs_last, | |
Equal equal = Equal(), | |
Hash hash = Hash()) | |
{ | |
using value_type = typename LhsForwardIterator::value_type; | |
std::unordered_map<value_type, int, Hash, Equal> frequencies; | |
for (; lhs_first != lhs_last; ++lhs_first) frequencies[*lhs_first] += 1; | |
for (; rhs_first != rhs_last; ++rhs_first) frequencies[*rhs_first] -= 1; | |
return std::all_of(begin(frequencies), end(frequencies), | |
[](auto const& p) { return p.second == 0; }); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment