473,789 Members | 2,729 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

hash_map

I need help in hashmaps. Why doesn't this work:

#include <hash_map>

hash_map <int, string> hm1;
typedef pair <int, string> pr;
hm1.insert(str_ pair(1, "Hello"));

It compiles, but crashes at runtime, pointing to something in xhash.

--

Jon Cosby

Please do not reply to this email address.
Jul 22 '05 #1
10 4760
"Jon Cosby" <qw****@abc.net > wrote in message
news:ps******** **********@news read1.news.pas. earthlink.net.. .
I need help in hashmaps. Why doesn't this work:

#include <hash_map>

hash_map <int, string> hm1;
typedef pair <int, string> pr;
hm1.insert(str_ pair(1, "Hello"));

It compiles, but crashes at runtime, pointing to something in xhash.


Depends a lot on what your undocumented str_pair does. It would
be a really good idea for it to return something like:

hash_map<int, string>::value_ type(1, string("Hello") );

P.J. Plauger
Dinkumware, Ltd.
http://www.dinkumware.com
Jul 22 '05 #2
Jon Cosby wrote:
I need help in hashmaps. Why doesn't this work:

#include <hash_map>

hash_map <int, string> hm1;
typedef pair <int, string> pr;
hm1.insert(str_ pair(1, "Hello"));
.... str_pair is not defined here.

It compiles, but crashes at runtime, pointing to something in xhash.


hash_map is not part of the standard, however it is popular, I have no
idea what the "right(TM)" way to get access to it under gcc so I'd check
up on that. I used gcc 3.3.1.

The code below works find for me. Maybe your str_pair() returns a
reference local variable ?

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

using namespace std;
using namespace __gnu_cxx;

int main()
{
hash_map<int, string> hm1;

typedef hash_map<int, string>::value_ type pr;

hm1.insert(pr(1 , "Hello"));

cout << hm1[1] << endl;

}

Jul 22 '05 #3

"P.J. Plauger" <pj*@dinkumware .com> wrote in message
news:c1******** ***********@nwr ddc02.gnilink.n et...
"Jon Cosby" <qw****@abc.net > wrote in message
news:ps******** **********@news read1.news.pas. earthlink.net.. .
I need help in hashmaps. Why doesn't this work:

#include <hash_map>

hash_map <int, string> hm1;
typedef pair <int, string> pr;
hm1.insert(str_ pair(1, "Hello"));

It compiles, but crashes at runtime, pointing to something in xhash.


Depends a lot on what your undocumented str_pair does.


That was a typo. Should be just "pr".
Jon
Jul 22 '05 #4

"Jon Cosby" <qw****@abc.net > wrote in message
news:Qb******** ***********@new sread2.news.pas .earthlink.net. ..

"P.J. Plauger" <pj*@dinkumware .com> wrote in message
news:c1******** ***********@nwr ddc02.gnilink.n et...
"Jon Cosby" <qw****@abc.net > wrote in message
news:ps******** **********@news read1.news.pas. earthlink.net.. .
I need help in hashmaps. Why doesn't this work:

#include <hash_map>

hash_map <int, string> hm1;
typedef pair <int, string> pr;
hm1.insert(str_ pair(1, "Hello"));

It compiles, but crashes at runtime, pointing to something in xhash.


Depends a lot on what your undocumented str_pair does.


That was a typo. Should be just "pr".


Then P.J.'s reply is still essentially the same, but changing
'str_pair' to 'pr'.

BTW 'hash_map' is not part of standard C++ (although provided
as an extension by many implementations ).

-Mike
Jul 22 '05 #5

"Mike Wahler" <mk******@mkwah ler.net> wrote in message
news:JP******** **********@news read2.news.pas. earthlink.net.. .

"Jon Cosby" <qw****@abc.net > wrote in message
news:Qb******** ***********@new sread2.news.pas .earthlink.net. ..

"P.J. Plauger" <pj*@dinkumware .com> wrote in message
news:c1******** ***********@nwr ddc02.gnilink.n et...
"Jon Cosby" <qw****@abc.net > wrote in message
news:ps******** **********@news read1.news.pas. earthlink.net.. .

> I need help in hashmaps. Why doesn't this work:
>
> #include <hash_map>
>
> hash_map <int, string> hm1;
> typedef pair <int, string> pr;
> hm1.insert(str_ pair(1, "Hello"));
>
> It compiles, but crashes at runtime, pointing to something in xhash.

Depends a lot on what your undocumented str_pair does.
That was a typo. Should be just "pr".


Then P.J.'s reply is still essentially the same, but changing
'str_pair' to 'pr'.


Ack! Disregard that, I see you have defined the object 'pr'
above. I didn't read carefully enough. Sorry!

BTW 'hash_map' is not part of standard C++ (although provided
as an extension by many implementations ).


This does remain true.

-Mike
Jul 22 '05 #6

"Mike Wahler" <mk******@mkwah ler.net> wrote in message
news:JP******** **********@news read2.news.pas. earthlink.net.. .
BTW 'hash_map' is not part of standard C++ (although provided
as an extension by many implementations ).

-Mike


Are you sure? VC lists it in the Standard C++ Library.

Jon
Jul 22 '05 #7
Jon Cosby wrote:

"Mike Wahler" <mk******@mkwah ler.net> wrote in message
news:JP******** **********@news read2.news.pas. earthlink.net.. .
BTW 'hash_map' is not part of standard C++ (although provided
as an extension by many implementations ).

-Mike


Are you sure? VC lists it in the Standard C++ Library.


He's sure. And he's right.

--

Pete Becker
Dinkumware, Ltd. (http://www.dinkumware.com)
Jul 22 '05 #8

"Jon Cosby" <qw****@abc.net > wrote in message
news:Sh******** **********@news read1.news.pas. earthlink.net.. .

"Mike Wahler" <mk******@mkwah ler.net> wrote in message
news:JP******** **********@news read2.news.pas. earthlink.net.. .
BTW 'hash_map' is not part of standard C++ (although provided
as an extension by many implementations ).

-Mike
Are you sure?


Yes.
VC lists it in the Standard C++ Library.


VC does not define the C++ language.

Also, I find no reference at all to 'hash_map' in
my VC++6.0 documentation. Perhaps version 7 has
such an animal, but it's still not standard.

-Mike
Jul 22 '05 #9
"Jon Cosby" <qw****@abc.net > wrote:
"Mike Wahler" <mk******@mkwah ler.net> wrote in message
news:JP******** **********@news read2.news.pas. earthlink.net.. .
BTW 'hash_map' is not part of standard C++ (although provided
as an extension by many implementations ).

-Mike


Are you sure? VC lists it in the Standard C++ Library.


The STL Tutorial and Reference Guide (2nd ed) says on page 161:

"Ideally, both sorted and hashed associated containers should be in the C++
Standard Library, but only sorted associated containers are included
(unofficial STL-based hash table specifications and implementations are
available)"

BTW a reason given for this (on p.161) is that hash tables can be order (N)
in the worst case, but that implies the use of linked lists at each hash
node ... surely a binary tree, etc. could be used instead. Anyone know if
std::maps and sets have been permitted to be implemented as hash tables
since this book was written (2001) ?

David F
Jul 22 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
9986
by: Florian Liefers | last post by:
"Hello World\n", i get error C2143 (Syntaxerror, missing ';' before '<') using the following code: #include <hash_map> struct eqstr { bool operator()(const char* s1, const char* s2) const
3
11881
by: Mark | last post by:
Hi, I'm trying to use hash_map (gcc 3.2.2) with a std::string as the key. It will compile if I use <map> but I get a bunch of template compile errors when I change it to hash_map. Any suggestions? My program and the errors are below... #include <ext/hash_map> #include <string>
5
8625
by: peter_k | last post by:
Hi I've defined hash_map in my code using this: ------------------------------------------- #include <string> #include <hash_map.h> & namespace __gnu_cxx {
3
3844
by: kony | last post by:
Hi there, I would much appreciate your help with the following problem. Below is the code that uses a hash_map. I want to release all the memory occupied by the hash_map for other use. Apparently clear() function is not working and the trick with swap() is half working. Does anybody know how to deallocate the hash_map? Thanks in advance. Kon #include <functional>
1
9402
by: jayesah | last post by:
Hi All, I am developing my code with Apache stdcxx. I am bound to use STL of Apache only. Now today I need hash_map in code but as I learned, it is not available in Apache since it is not standard c++. Though it is available with GNU STL. The code module where I use hash_map will generate separate object file during compilation. This code module is also using STL string.
2
4282
by: Amit Bhatia | last post by:
Hi, I am trying to use hash maps from STL on gcc 3.3 as follows: #ifndef NODE_H #define NODE_H #include <ext/hash_map> #include "node_hasher.h" class Node; typedef hash_map<pair<int,int>, Node, Node_HasherLoc_Tree;
4
3415
by: James Kanze | last post by:
On Jul 16, 10:53 pm, Mirco Wahab <wa...@chemie.uni-halle.dewrote: It depends. You might like to have a look at my "Hashing.hh" header (in the code at kanze.james.neuf.fr/code-en.html---the Hashing component is in the Basic section). Or for a discussion and some benchmarks, http://kanze.james.neuf.fr/code/Docs/html/Hashcode.html. (That article is a little out of date now, as I've tried quite a few more hashing algorithms. But the...
5
3374
by: frankw | last post by:
Hi, I have a hash_map with string as key and an object pointer as value. the object is like class{ public: float a; float b; ...
2
8146
by: marek.vondrak | last post by:
Hi, I am wondering if there are any functional differences between SGI's hash_map and tr1's unordered_map. Can these two containers be interchanged? What would it take to switch from hash_map to unordered_map? Thank you. -Marek
0
9511
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10199
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10139
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9983
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5417
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5551
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4092
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3700
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2909
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.