public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* Bug ? in hash_map template
@ 2004-08-25 20:45 Patrick Percot
  0 siblings, 0 replies; only message in thread
From: Patrick Percot @ 2004-08-25 20:45 UTC (permalink / raw)
  To: gcc-help

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@amessage.de
GPG fingerprint = 1A4F E154 3D2C A20E E4CA  A543 7951 C5C2 E44A A0B5

Patrick Percot.

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2004-08-24 18:27 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-08-25 20:45 Bug ? in hash_map template Patrick Percot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).