Thread: Hash table with C structures

  1. #16
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by anya
    But my thoughts was how to change hash_function in uthash header
    The thing is, rather than looking for a solution to this problem (storage of packet structures or pointers thereof with constant time access by id), you seem to have a solution (hash table) that's looking for a problem.

    A solution like uthash is designed for cases where you need a hash table. You don't need a hash table.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  2. #17
    Registered User migf1's Avatar
    Join Date
    May 2013
    Location
    Athens, Greece
    Posts
    385
    Actually, a more detailed description of the problem would be more enlightening for us. Are you really supposed to hash the packet.id, or are you supposed to hash the packet.buffer?

    All the discussion so far, assumed that the key to be hashed is the packet.id... is that so?

  3. #18
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Well, the requirement stated in post #1 does say: "search the packet in hash table by id and to delete it"
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  4. #19
    Registered User migf1's Avatar
    Join Date
    May 2013
    Location
    Athens, Greece
    Posts
    385
    Quote Originally Posted by laserlight View Post
    Well, the requirement stated in post #1 does say: "search the packet in hash table by id and to delete it"
    Yes, that's why I also assumed that the id is the hash key. But I also noticed that anya has marked the buffer as "value" in his/her original post. At first I thought it could be due to anya's inadequate understanding of hash-tables, but it was itching me if he/she is indeed supposed to use the buffer as the hash key.

    Using the buffer for hasing and then using the id for retrieving, would be a bit odd and it would complicate a little bit the code, but I thought I should ask anyway.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. hash table in c++
    By baxy in forum C++ Programming
    Replies: 7
    Last Post: 12-07-2012, 12:53 PM
  2. Hash table help
    By lemon-ice-tea in forum C++ Programming
    Replies: 1
    Last Post: 05-18-2011, 09:31 AM
  3. What is a Hash Table?
    By rip1968 in forum C++ Programming
    Replies: 3
    Last Post: 06-18-2002, 08:57 PM
  4. Hash Table
    By ihsir in forum C++ Programming
    Replies: 0
    Last Post: 04-13-2002, 12:08 AM
  5. Hash table
    By Unregistered in forum C Programming
    Replies: 3
    Last Post: 01-14-2002, 07:06 PM

Tags for this Thread