Last active
May 12, 2017 16:14
-
-
Save deque-blog/3e71ac622a6434532db3496ae1061057 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 Value, size_t N> | |
constexpr std::array<int, N> frequency_map(std::array<Value, N> const& values) | |
{ | |
std::map<Value, int> freq_map; | |
for (int i = 0; i < N; ++i) | |
freq_map[values[i]] += 1; // Count each occurence using a std::map | |
std::array<int, N> freqs {}; // Reconstruct a std::array from our std::map | |
for (int i = 0; i < N; ++i) | |
freqs[i] = freq_map[values[i]]; | |
return freqs; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment