473,406 Members | 2,707 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Modifying elements of hash_set.

Hi,
I was wondering if I have a hash_set, can I modify its elements using an
iterator: given the fact that the changes I make will not change the
position or the key of the object that the iterator points to?

Or do I need to necessarily use hash_map ?

Thanks,
--a.

Mar 5 '07 #1
5 2856
On Mar 5, 5:51 pm, Amit Bhatia <amit.bhatia.nos...@nospam.comwrote:
I was wondering if I have a hash_set, can I modify its elements using an
iterator: given the fact that the changes I make will not change the
position or the key of the object that the iterator points to?

Or do I need to necessarily use hash_map ?
Standard C++ doesn't have anything called a hash_set or hash_map -
those are extensions that some implementations have added. The next
version of C++ will have what is now designated as
std::tr1::unordered_set and std::tr1::unordered_map, which fill a
similar purpose, but have slightly different syntax. For more
information about unordered_set and unordered_map, take a look at
section 6.3 of this:

http://www.open-std.org/jtc1/sc22/wg...2005/n1836.pdf

Or take a look at Pete Becker's new book on tr1.

Best regards,

Tom
Mar 6 '07 #2
"Thomas Tutone" <Th***********@yahoo.comwrote in message
news:11*********************@j27g2000cwj.googlegro ups.com...
On Mar 5, 5:51 pm, Amit Bhatia <amit.bhatia.nos...@nospam.comwrote:
> I was wondering if I have a hash_set, can I modify its elements using an
iterator: given the fact that the changes I make will not change the
position or the key of the object that the iterator points to?

Or do I need to necessarily use hash_map ?

Standard C++ doesn't have anything called a hash_set or hash_map -
those are extensions that some implementations have added. The next
version of C++ will have what is now designated as
std::tr1::unordered_set and std::tr1::unordered_map, which fill a
similar purpose, but have slightly different syntax. For more
information about unordered_set and unordered_map, take a look at
section 6.3 of this:

http://www.open-std.org/jtc1/sc22/wg...2005/n1836.pdf

Or take a look at Pete Becker's new book on tr1.
That's the officious answer. The useful answer is that hash_set
is just like (unordered_)set in this regard -- if you do contrive to
alter the stored key you risk destroying the integrity of the
container. Erase the old value and insert the new value instead.

P.J. Plauger
Dinkumware, Ltd.
http://www.dinkumware.com
Mar 6 '07 #3
P.J. Plauger wrote:
"Thomas Tutone" <Th***********@yahoo.comwrote in message
news:11*********************@j27g2000cwj.googlegro ups.com...
>On Mar 5, 5:51 pm, Amit Bhatia <amit.bhatia.nos...@nospam.comwrote:
>> I was wondering if I have a hash_set, can I modify its elements using an
iterator: given the fact that the changes I make will not change the
position or the key of the object that the iterator points to?

Or do I need to necessarily use hash_map ?
Standard C++ doesn't have anything called a hash_set or hash_map -
those are extensions that some implementations have added. The next
version of C++ will have what is now designated as
std::tr1::unordered_set and std::tr1::unordered_map, which fill a
similar purpose, but have slightly different syntax. For more
information about unordered_set and unordered_map, take a look at
section 6.3 of this:

http://www.open-std.org/jtc1/sc22/wg...2005/n1836.pdf

Or take a look at Pete Becker's new book on tr1.

That's the officious answer. The useful answer is that hash_set
is just like (unordered_)set in this regard -- if you do contrive to
alter the stored key you risk destroying the integrity of the
container. Erase the old value and insert the new value instead.
Thanks. But let's say each object in the hash_set has a boolean, and a
vector of integers, whose value(s) do not affect the key for sure (I
supply the hash function): then won't this method of copying-erasing-
changing-inserting result in substantial speed slow up? I just might
want to change boolean variable in the class object and still I have to
copy the whole thing first..

thanks,
--a.
Mar 6 '07 #4
On 3ÔÂ6ÈÕ, ÏÂÎç1ʱ22·Ö, Amit Bhatia <abha...@nospam..nospam.comwrote:
P.J. Plauger wrote:
"Thomas Tutone" <Thomas8675...@yahoo.comwrote in message
news:11*********************@j27g2000cwj.googlegro ups.com...
On Mar 5, 5:51 pm, Amit Bhatia <amit.bhatia.nos...@nospam.comwrote:
> I was wondering if I have a hash_set, can I modify its elements using an
iterator: given the fact that the changes I make will not change the
position or the key of the object that the iterator points to?
>Or do I need to necessarily use hash_map ?
Standard C++ doesn't have anything called a hash_set or hash_map -
those are extensions that some implementations have added. The next
version of C++ will have what is now designated as
std::tr1::unordered_set and std::tr1::unordered_map, which fill a
similar purpose, but have slightly different syntax. For more
information about unordered_set and unordered_map, take a look at
section 6.3 of this:
>http://www.open-std.org/jtc1/sc22/wg...2005/n1836.pdf
Or take a look at Pete Becker's new book on tr1.
That's the officious answer. The useful answer is that hash_set
is just like (unordered_)set in this regard -- if you do contrive to
alter the stored key you risk destroying the integrity of the
container. Erase the old value and insert the new value instead.

Thanks. But let's say each object in the hash_set has a boolean, and a
vector of integers, whose value(s) do not affect the key for sure (I
supply the hash function): then won't this method of copying-erasing-
changing-inserting result in substantial speed slow up? I just might
want to change boolean variable in the class object and still I have to
copy the whole thing first..

thanks,
--a.- Òþ²Ø±»ÒýÓÃÎÄ×Ö -

- ÏÔʾÒýÓõÄÎÄ×Ö -
Maybe you could take the boolean value out and associate it with with
each object by using hash_map.
Or you could just use const_cast, which is evil.

Mar 6 '07 #5
"mimi" <ca**************@gmail.comwrote in message
news:11**********************@p10g2000cwp.googlegr oups.com...

On 3ÔÂ6ÈÕ, ÏÂÎç1ʱ22·Ö, Amit Bhatia <abha...@nospam.nospam.comwrote:
P.J. Plauger wrote:
"Thomas Tutone" <Thomas8675...@yahoo.comwrote in message
news:11*********************@j27g2000cwj.googlegro ups.com...
On Mar 5, 5:51 pm, Amit Bhatia <amit.bhatia.nos...@nospam.comwrote:
> I was wondering if I have a hash_set, can I modify its elements using
an
iterator: given the fact that the changes I make will not change the
position or the key of the object that the iterator points to?
>Or do I need to necessarily use hash_map ?
Standard C++ doesn't have anything called a hash_set or hash_map -
those are extensions that some implementations have added. The next
version of C++ will have what is now designated as
std::tr1::unordered_set and std::tr1::unordered_map, which fill a
similar purpose, but have slightly different syntax. For more
information about unordered_set and unordered_map, take a look at
section 6.3 of this:
>http://www.open-std.org/jtc1/sc22/wg...2005/n1836.pdf
Or take a look at Pete Becker's new book on tr1.
That's the officious answer. The useful answer is that hash_set
is just like (unordered_)set in this regard -- if you do contrive to
alter the stored key you risk destroying the integrity of the
container. Erase the old value and insert the new value instead.

Thanks. But let's say each object in the hash_set has a boolean, and a
vector of integers, whose value(s) do not affect the key for sure (I
supply the hash function): then won't this method of copying-erasing-
changing-inserting result in substantial speed slow up? I just might
want to change boolean variable in the class object and still I have to
copy the whole thing first..

thanks,
--a.- Òþ²Ø±»ÒýÓÃÎÄ×Ö -

- ÏÔʾÒýÓõÄÎÄ×Ö -
Maybe you could take the boolean value out and associate it with with
each object by using hash_map.

[pjp] Right. If your "key" really has components that don't participate in
the
ordering, then you really have a map masquerading as a set. And if
on top of that the non-ordering components are heavyweight, then
you're really being perverse in not separating them out as the
"mapped" part of a (key, mapped) pair stored in a map.

Or you could just use const_cast, which is evil.

[pjp] Indeed.

P.J. Plauger
Dinkumware, Ltd.
http://www.dinkumware.com
Mar 6 '07 #6

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

Similar topics

1
by: Abhijit Ray | last post by:
I am using hash_set which is available from gcc ( and which i presume is not part of the C++ standard yet ) okay , In hash tables the key is used by a hash function to calculate a index and the...
10
by: Alex Gerdemann | last post by:
Hello, I have spent a bunch of time converting a Java program I wrote to C++ in order to improve performance, and have found that it is not necessarily faster. Specifically, I'm writing a...
5
by: Bart Blommerde | last post by:
Hi, My question is about the STL extensions hash_set and hash_map, especially the SGI versions of these templates. When defining a class like this : #include <hash_set> class MyClass : public...
1
by: Timo Qvist | last post by:
Hi, I'm a bit new to STL and really new to SGI's hash_set implementation and I've having problem instantiating a hash_set with a custom hash function, I could really use some help sifting through...
3
by: Markus Dehmann | last post by:
I have a class "Data" and I store Data pointers in an STL set. But I have millions of inserts and many more lookups, and my profiler found that they cost a lot of runtime. Therefore, I want to...
5
by: jian | last post by:
I am trying to use the hash_set, but cannot get it work. Here's my code: // file name: hash1.cpp #include <hash_set> int main() { hash_set<int> h; } When I type:
1
by: zs | last post by:
Hi! I get warning message shown below in VS.NET 2k3. Is this deprecated by microsoft or by standard? I need hash_set to store and search small strings (<20 chars long). I'll have less then 300...
2
by: Pierre Couderc | last post by:
Generally, is there somewhere a good tutorial and examplefor the use of SGI STL hash_set? I am lost in SGI documentation. More specifically, i am trying to use hat I need that a hash_set : ...
0
by: Amit Bhatia | last post by:
Hi, I was wondering if I have a hash_set, can I modify its elements using an iterator: given the fact that the changes I make will not change the position or the key of the object that the...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.