Chaning the key of a hash_map entry

This is a discussion on Chaning the key of a hash_map entry within the C++ Programming forums, part of the General Programming Boards category; Hi, I have a hash_map and I need to change a hash_map's key to another. The keys in this case ...

  1. #1
    Registered User
    Join Date
    Jun 2002
    Posts
    132

    Chaning the key of a hash_map entry

    Hi,
    I have a hash_map and I need to change a hash_map's key to another. The keys in this case are std:: strings. Say I have 2 objects registered, "obj1", "obj2". I want to rename the hash entry "obj1" to, say, "obj3". I hope this is possible..
    Thanks
    Y3K Network http://www.y3knetwork.com
    Bringing the software of the future on the net.

  2. #2
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,645
    Remove "obj1" then add "obj3".

    gg

  3. #3
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >I have a hash_map and I need to change a hash_map's key to another.
    Hashing relies on the value of the key to directly determine location. If the key changes but the location doesn't change, you've broken the data structure in a subtle way. The only way to change the key in a hash table is to remove the record completely and rehash it (add it again) with a different key.
    My best code is written with the delete key.

  4. #4
    Registered User
    Join Date
    Jun 2002
    Posts
    132
    Ok, it works. thanks
    Y3K Network http://www.y3knetwork.com
    Bringing the software of the future on the net.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 16
    Last Post: 11-23-2007, 12:48 PM
  2. Virtual keys
    By Arkanos in forum Windows Programming
    Replies: 4
    Last Post: 12-12-2005, 09:00 AM
  3. Directional Keys - Useing in Console
    By RoD in forum C++ Programming
    Replies: 38
    Last Post: 10-06-2002, 04:42 PM
  4. FAQ: Directional Keys - Useing in Console
    By RoD in forum FAQ Board
    Replies: 38
    Last Post: 10-06-2002, 04:42 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21