hash_set : need the location /index where stored .

Discussion in 'C++' started by Abhijit Ray, Apr 27, 2004.

  1. Abhijit Ray

    Abhijit Ray Guest

    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/
    Abhijit Ray, Apr 27, 2004
    #1
    1. Advertising

  2. "Abhijit Ray" <> wrote in message
    news:...
    > 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
    John Harrison, Apr 27, 2004
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Vasileios
    Replies:
    4
    Views:
    459
    Rolf Magnus
    Nov 4, 2003
  2. Alex Gerdemann

    Performance of hash_set vs. Java

    Alex Gerdemann, Oct 11, 2004, in forum: C++
    Replies:
    10
    Views:
    2,251
    Tom Widmer
    Oct 13, 2004
  3. Bart Blommerde

    using hash_set in gcc3.3

    Bart Blommerde, Oct 13, 2004, in forum: C++
    Replies:
    5
    Views:
    506
    John Harrison
    Oct 13, 2004
  4. eric
    Replies:
    3
    Views:
    1,285
    Michael DOUBEZ
    Jul 12, 2011
  5. Tomasz Chmielewski

    sorting index-15, index-9, index-110 "the human way"?

    Tomasz Chmielewski, Mar 4, 2008, in forum: Perl Misc
    Replies:
    4
    Views:
    256
    Tomasz Chmielewski
    Mar 4, 2008
Loading...

Share This Page