473,688 Members | 3,241 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 4745
"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
9978
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
11879
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
8617
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
3840
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
9389
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
4276
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
3403
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
3368
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
8130
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
8590
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, weíll explore What is ONU, What Is Router, ONU & Routerís main usage, and What is the difference between ONU and Router. Letís take a closer look ! Part I. Meaning of...
0
9072
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8947
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...
0
8786
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
5807
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4547
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2964
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
2215
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
1950
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.