hash_set : need the location /index where stored .

A

Abhijit Ray

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 object is stored under that key.
I would like to have the index value. I want to iterate over all the
objects stored in the hash_set and get all the objects and their
index. )
The aim is to display the hash_set graphically, so that we can
visually see how the objects are stored and are they distributed
evenly or there is high collision and we arent getting much benifit
out of using hash_set as compared to using a list.

Also for classes created by us , we have to define our own hash
functions and in that case we can calculate it from the object itself.
BUt what if we just have a pointer to the hash_set object and have no
idea what the hash function is ?


second problem is when we define a hash_set
hash_set(size_type n) Creates an empty hash_set with at least n
buckets.

this creates a hash_set with _at least_ n buckets . Is there any way
we can make sure that exactly n buckets are created. cos if our custom
hash function returns a value from 0 to n-1 i dont see any use of
creating a hash_set with more than n buckets.


Phew I hope I was clear enough :)

/abhijit/
 
J

John Harrison

Abhijit Ray said:
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 object is stored under that key.
I would like to have the index value. I want to iterate over all the
objects stored in the hash_set and get all the objects and their
index. )
The aim is to display the hash_set graphically, so that we can
visually see how the objects are stored and are they distributed
evenly or there is high collision and we arent getting much benifit
out of using hash_set as compared to using a list.

Also for classes created by us , we have to define our own hash
functions and in that case we can calculate it from the object itself.
BUt what if we just have a pointer to the hash_set object and have no
idea what the hash function is ?

gcc define a method that returns the hash_set's hash function, can't
remember what its called (hash_funct I think), look it up.
second problem is when we define a hash_set
hash_set(size_type n) Creates an empty hash_set with at least n
buckets.

this creates a hash_set with _at least_ n buckets . Is there any way
we can make sure that exactly n buckets are created. cos if our custom
hash function returns a value from 0 to n-1 i dont see any use of
creating a hash_set with more than n buckets.

Write a better hash function I think. IIIRC gcc's hash_set rounds up the
number of buckets to a prime number, so no I don't think there is any way to
do what you are asking.

Since you seem to have very specific requirements why not write your own
hash set, its prerty easy to do.

john
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top