counting frequency of integers take together
I need to count the frequencies of different integers together in a binary file, how can I do this? 开发者_如何转开发I do not wish to convert to string, because that would slow down my program down.. I think...
vector<uint32_t> buf(2);
map<uint32_t, uint32_t> mymap;
if(file.is_open())
{
while (file.read(reinterpret_cast<char*>(&buf[0]), sizeof(uint32_t)*numcols))
{
for(size_t i = 0; i < numcols; ++i)
{
mymap[buf[i]]++; // **---> I need help here**
}
}
}
file.close();
How can I make the key to the map so that it always counts those integers together
Yep.. how many times I see integer pairs consecutively, like how many times (1,2), or (8, 14), or (7,3).
1 2
1 2
7 3
8 14
8 14
8 14
1 2 --> 2 times
7 3 --> 1 time
8 14 --> 3 times
numcols == 2 correct.
One option might be to have the map
use pair<uint32_t, uint32_t>
s as keys. That way you're explicitly mapping from pairs of uint32_t
s to the frequency with which they appear.
精彩评论