Like Tree2Likes

How to use string hash function

This is a discussion on How to use string hash function within the C++ Programming forums, part of the General Programming Boards category; Let me rephrase that, then: Don't mod the hashvalue unless you want to destroy the uniqueness distribution of the has ...

  1. #16
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    23,029
    Let me rephrase that, then:
    Don't mod the hashvalue unless you want to destroy the uniqueness distribution of the has function, or if it is acceptable to do so, or you have no other choice.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  2. #17
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,308
    Quote Originally Posted by Elysia View Post
    Let me rephrase that, then:
    Don't mod the hashvalue unless you want to destroy the uniqueness distribution of the has function, or if it is acceptable to do so, or you have no other choice.
    Of course you mod (or mask) the hash value, that's what you do when implementing a hash table. What next, don't use a screwdriver to screw in a screw?!

    Not everyone has > 4GB spare for an array of pointers!
    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"

  3. #18
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,308
    Quote Originally Posted by monkey_c_monkey View Post
    Now it compiles, but it still outputs a large value like 205991382. I did manually use standard c++0x so: g++ -std=c++0x -o hash_tables hash_tables.cpp.
    That's normal, now you need to do mod size_1 as you thought earlier.
    The parameters to use are corrrect according to the official site @ http://www.isthe.com/chongo/tech/comp/fnv/
    That's because that site's example is for old C code, but you are using C++. Adding the const was the correct thing to do to port it to modern C++.
    ... I'll look around for other string hash functions and try to resolve this...
    That's not necessary. FNV-1a is very good, and the problem was with how you were trying to use it. Any other hashing function will behave the same, and if you can't use this one right, you wont be able to use any other right either.
    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"

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Hash function to hash key into geographic coordinate
    By dominic_tran201 in forum C++ Programming
    Replies: 2
    Last Post: 02-11-2011, 10:03 AM
  2. hash function - int to char string + vice versa
    By kerrymaid in forum C Programming
    Replies: 2
    Last Post: 05-29-2010, 12:01 PM
  3. String input looping my hash function
    By iAmFedor in forum C++ Programming
    Replies: 6
    Last Post: 04-25-2008, 05:20 PM
  4. Need help with string hash function
    By pityocamptes in forum C Programming
    Replies: 1
    Last Post: 04-21-2006, 11:23 PM
  5. Performing a SHA-512 hash on a string
    By mjt in forum C Programming
    Replies: 8
    Last Post: 10-23-2005, 01:19 AM

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