Thread: Hash implementations

  1. #1
    Registered User
    Join Date
    Feb 2005
    Posts
    30

    Hash implementations

    Hi all,

    I am looking for a hash written in C that meets the following needs:

    * the size of the hash, n, is known and fixed before initialization, and n is large;
    * only init_hash(), hash_add() and hash_get() are needed;
    * keys are char pointers and values and struct pointers;
    * the hash table takes up small number of memory size.

    My most important requirement is that the hash table does not take up a lot of memory, in the case that a lot of extra memory are allocated.

    Do you have any pointer to such hash implementation?

    Thank you!
    Last edited by SoFarAway; 07-23-2007 at 04:48 AM.

  2. #2
    Registered User kroiz's Avatar
    Join Date
    Jun 2007
    Posts
    116
    Isn't STL got some hash. (-:

  3. #3
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    STL is for C++, not C.

  4. #4
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    You don't feel like writing your own?

    The Wikipedia article for "hash table" lists a few hash implementations.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  5. #5
    Registered User
    Join Date
    Feb 2005
    Posts
    30
    Quote Originally Posted by dwks View Post
    You don't feel like writing your own?
    If there are codes that can be reused, why don't use them? hehe..

    Thanks for the useful link!

  6. #6
    Registered User
    Join Date
    Feb 2005
    Posts
    30
    Just to share with you some hash implementations that I found on the Web:

    * http://www.burtleburtle.net/bob/hash/doobs.html by Bob Jenkins,
    * http://www.zentus.com/c/hash.html by David Crawshaw.

  7. #7
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    Quote Originally Posted by SoFarAway View Post
    Hi all,
    My most important requirement is that the hash table does not take up a lot of memory, in the case that a lot of extra memory are allocated.
    You can make the hash table size any size you want. It's purely a tradeoff between memory usage and speed. However if you don't use seperate chaining then your hash table must be big enough to hold all items, and ideally capable of holding perhaps twice as many items.

    I personally swear by the use of CRC as the preferred hashing algorithm in every circumstance.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem with unaligned intrinsics
    By The Wazaa in forum C++ Programming
    Replies: 4
    Last Post: 02-18-2009, 12:36 PM
  2. Bernstein hash?
    By audinue in forum C Programming
    Replies: 0
    Last Post: 01-07-2009, 07:24 AM
  3. Group Project Help/Volunteer
    By DarkDot in forum C++ Programming
    Replies: 3
    Last Post: 04-24-2007, 11:36 PM
  4. Hash table creation and insertion
    By tgshah in forum C Programming
    Replies: 1
    Last Post: 01-23-2006, 07:54 PM
  5. Not sure on hash table memory allocations
    By Thumper333 in forum C Programming
    Replies: 3
    Last Post: 09-27-2004, 09:00 PM