std::unordered_multimap::bucket_size=0

Hi friends.
I want to ask if somebody can help me in this situation :
I do following code :
<code>
unordered_multimap<SetPartition,int> sparts;
//fill this sparts with elements
for(auto asp : sparts) {
const SetPartition& sp = asp.first;
//if (used.find(sp)!=used.end()) continue;
//used.insert(sp);
int bucketI = sparts.bucket(sp);
int bucketSize = sparts.bucket_size(bucketI);
auto range = sparts.equal_range(sp);
for(auto v = range.first; v!=range.second;++v) {
//...
}
//...
}
</code>
For my sorprise it never enter this second loop. I think it must have at least one element, if not why why we have asp ? Also, bucketSize=0. I believed it need to be =1.
Somebody can explain me why i not found nothing with a key, or explain me what is wrong ?

greatings, Daniel
You declare your variable sparts as an empty unordered_multimap. It will not have any elements upfront (thus the size will be zero). Your first for loop is a range-based for loop. Since there's nothing in the map, it won't even execute.

If your loop does execute, there's probably something you aren't showing us in your code (probably the initialization of the map).
Thanks for your answer.
I put in comments :
//fill this sparts with elements
This mean i use "insert" many times there, its only i not show it explicitily.
I also say, it enter the first loop, but not enter the second loop.
So , in this case, you know why not ?
Between first "for" and second "for" i not erase any element.
Daniel
Hi,
i want to tell you that i already found my error.
Hash function of SetPartition is :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
namespace std {
  template <>
  struct hash<SetPartition>
  {
    std::size_t operator()(const SetPartition& sp) const
    {
      size_t seed;
      boost::hash_combine(seed,sp.s);
      boost::hash_combine(seed,sp.base.hash);
      boost::hash_combine(seed,sp.var.hash);
      return seed;
    }
  };
}

3 variables are of type :
1
2
3
    int s;
    Subset base;
    Subset var;

and Subset have a member variable hash a integer which is calculated in construction time :
 
    size_t hash;

In time in which i insert a {SetPartition,int} into this Hash, its ok, but later it is invalidatet because i forget to put hash member in copy function and copy constructor.
Now, this is in order.
Thanks for you try.
Daniel
Topic archived. No new replies allowed.