Bug ? in hash_map template

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

I  made some tests  with g++  3.2.3 and  g++ 3.3.1  on GNU/Linux  and on
cygwin g++ 3.3.1. And I got the  same results : when I run this program,
when  inserting "key20" to  "key24" the  size of  the hash_map  does not
evolve.

When I  try to  get the results  back, "key15"  to "key19" all  give the
result 20. 

I noticed something when debugging the code, in the function resize, the
current size is compared to _M_bucket.size() that allways returns 193. 

Does someone noticed the same behavior ?


#include <ext/hash_map>
#include <iostream>

using namespace std;
using namespace __gnu_cxx;

struct eqstr
{
  bool operator()(const char* s1, const char* s2) const
  {
    return strcmp(s1, s2) == 0;
  }
};



int
main()
{
  char str[128];
  hash_map<const char*, int, hash<const char*>, eqstr> h;

  cout << "hash size = " << h.size() << '\n';

  for (int i = 0; i < 31; ++i) {
    sprintf(str, "key%d", i);
    h[str] = i;
    cout << "size = " << h.size() << " str = " << str << '\n';
  }

  for (int i = 0; i < 31; ++i) {
    sprintf(str, "key%d", i);
    cout << str << " = " << h[str] << '\n';
  }
}

À+
PP
-- 
Groupe Morbihannais d'Utilisateurs de Logiciels Libres http://www.tuxbihan.org
Identifiant Jabber: pp@xxxxxxxxxxx
GPG fingerprint = 1A4F E154 3D2C A20E E4CA  A543 7951 C5C2 E44A A0B5

Patrick Percot.


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux