Data structure for Counter frequence of Pairs

J

Jianli Shen

to count the frequence of each pair like <A,B> <A2,C2> in the following.
eg. <<A, B>, 6>
<<A, B1>, 8>
<<A, B2>, 4>
<<A2, C2>, 10>
<<A3, D2>, 16>
I try to use
typedef std::pair<long, long> AddrPair;
typedef HASH_MAP<AddrPair,int> PairCount;
AddrPair addrPair;
PariCount pairCount;

then use it like:
addrPair.first = 100;
addrPair.sencond = 200; //upto here it compiles ok.

PairCount::iterator pit=pairCount.find(addrPair);
it complains like:

no match for call to '(const __gnu_cxx::hash<std::pair<PAddr, PAddr> >)
(const std::pair<PAddr, PAddr>&)'

Does anybody know what's wrong here, or any suggestion to build a data
structure to solve the problem?

Thanks.
 
J

Jianli Shen

Solved!
need to define a hashfunction for the hash map.


class hashfunction {
public:
size_t operator()(const AddrPair *v) const {
size_t val = (size_t)v;
return val>>2;
}
};
typedef HASH_MAP<AddrPair*,int, hashfunction> PairCount;
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top