Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > hash function

Reply
Thread Tools

hash function

 
 
Lars Tackmann
Guest
Posts: n/a
 
      12-19-2003
Hi i need a hash function for some large strings (upto 1024 chars in the
array) the following is not very good for these large strings:

int string_hash(int hash_size, const char *key)
{
unsigned long n = 0;

const char *p;
for (p = key; *p != '\0'; p++)
n = ((n << + n) ^ (unsigned long)(*p);
printf("n er: %i", n);
return (n % hash_size);
}

Any ideas -
 
Reply With Quote
 
 
 
 
CBFalconer
Guest
Posts: n/a
 
      12-19-2003
Lars Tackmann wrote:
>
> Hi i need a hash function for some large strings (upto 1024 chars in
> the array) the following is not very good for these large strings:


hashlib.zip contains some string hashing utility functions,
together with some URL references to others. See:

<http://cbfalconer.home.att.net/download/>

--
Chuck F ((E-Mail Removed)) ((E-Mail Removed))
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net> USE worldnet address!


 
Reply With Quote
 
 
 
 
osmium
Guest
Posts: n/a
 
      12-19-2003
Lars Tackmann writes:

> Hi i need a hash function for some large strings (upto 1024 chars in the
> array) the following is not very good for these large strings:
>
> int string_hash(int hash_size, const char *key)
> {
> unsigned long n = 0;
>
> const char *p;
> for (p = key; *p != '\0'; p++)
> n = ((n << + n) ^ (unsigned long)(*p);
> printf("n er: %i", n);
> return (n % hash_size);
> }


What is it that you don't like about what you already have? I have the
impression that MD5 is the _ne plus ultra_ of hash functions if you aren't
concerned about speed.


 
Reply With Quote
 
glen herrmannsfeldt
Guest
Posts: n/a
 
      12-20-2003
Lars Tackmann wrote:

> Hi i need a hash function for some large strings (upto 1024 chars in the
> array) the following is not very good for these large strings:
>
> int string_hash(int hash_size, const char *key)
> {
> unsigned long n = 0;
>
> const char *p;
> for (p = key; *p != '\0'; p++)
> n = ((n << + n) ^ (unsigned long)(*p);
> printf("n er: %i", n);
> return (n % hash_size);
> }


I would use CRC32, and there is already a thread discussing it.

-- glen

 
Reply With Quote
 
Paul Hsieh
Guest
Posts: n/a
 
      12-21-2003
http://www.velocityreviews.com/forums/(E-Mail Removed) says...
> Hi i need a hash function for some large strings (upto 1024 chars in the
> array) the following is not very good for these large strings:
>
> int string_hash(int hash_size, const char *key)
> {
> unsigned long n = 0;
>
> const char *p;
> for (p = key; *p != '\0'; p++)
> n = ((n << + n) ^ (unsigned long)(*p);
> printf("n er: %i", n);
> return (n % hash_size);
> }


I belive that you will find the state of the art in hash functions here:

http://www.isthe.com/chongo/tech/comp/fnv/

--
Paul Hsieh
http://www.pobox.com/~qed/
http://bstring.sf.net/
 
Reply With Quote
 
August Derleth
Guest
Posts: n/a
 
      12-22-2003
"osmium" <(E-Mail Removed)> wrote in
news:brv2hd$7sc26$(E-Mail Removed)-berlin.de on Fri 19 Dec 2003
09:38:17a:

> I have the
> impression that MD5 is the _ne plus ultra_ of hash functions if you
> aren't concerned about speed.
>
>


What about SHA? I think SHA is slowly replacing MD5 in most arenas.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
hash of hash of hash of hash in c++ rp C++ 1 11-10-2011 04:45 PM
Hash#select returns an array but Hash#reject returns a hash... Srijayanth Sridhar Ruby 19 07-02-2008 12:49 PM
In 'HashMap.put', "if (e.hash == hash && eq(k, e.key))" ? Red Orchid Java 3 01-30-2006 07:04 PM
write a function such that when ever i call this function in some other function .it should give me tha data type and value of calling function parameter komal C++ 6 01-25-2005 11:13 AM
standard library for hash table storage and hash algorithm Pieter Claassen C Programming 1 08-04-2004 03:11 AM



Advertisments