All About Circuits Forum  

Go Back   All About Circuits Forum > Software, Microcomputing, and Communications Forums > Programmer's Corner


Programmer's Corner Discussion forum for all aspects of programming and software engineering. Any software programming language welcome: C, C++, C#, Fortran, Java, Matlab, etc.

Reply   Post New Thread
Thread Tools Display Modes
Old 07-10-2010, 04:13 PM
moslem moslem is offline
Junior Member
Join Date: Dec 2009
Posts: 20
Default question about string hash function

Hello every one,
i've a string hash function it's performace is already good but there is some things that happens inside it and idon't know why
the hash function:
unsigned int table::hash(const string &word)
int hash = 0;
int n=word.length();
for(int i=0;i<n;i++)
hash = 31*hash+word[i];
return hash % MAX_TABLE;
my questions about it
why we multiply by 31 the hash every time is this for making weighting for the characters or any thing else?
thanks inadvance.
Reply With Quote
Old 07-13-2010, 01:15 AM
Harrington Harrington is offline
Join Date: Dec 2009
Location: London
Posts: 86

Stack of information can be obtained from here Hashing algorythms and examples , explanations

Should help you on this extensive subject
Reply With Quote
The Following User Says Thank You to Harrington For This Useful Post:
moslem (07-13-2010)
Old 07-13-2010, 01:58 PM
Papabravo's Avatar
Papabravo Papabravo is offline
Senior Member
Join Date: Feb 2006
Location: Michigan, USA (GMT-5)
Posts: 5,850

Notice that 31 is a Mersenne prime

and the algorithm is related to the Linear Congruential Random Number Generator. Good random number generators seem to have desirable features for a hashing algorithm.
We never have time to do it right,
But we always have time to do it over.
Reply With Quote
The Following User Says Thank You to Papabravo For This Useful Post:
moslem (07-13-2010)
Reply   Post New Thread

, , , ,

Related Site Pages
Section Title
Worksheet Basic algebra and graphing for electric circuits
Worksheet Mixed-frequency signals
Worksheet Phasor mathematics
Textbook Introduction : Shift Registers
Textbook Synchronous counters : Sequential Circuits Counters
Textbook Special-purpose diodes : Diodes And Rectifiers
Textbook Quantum physics : Solid-state Device Theory
Textbook Decimal versus binary numeration : Numeration Systems

Similar Threads
Thread Thread Starter Forum Replies Last Post
Function Generator Applications someonesdad General Electronics Chat 16 08-05-2009 04:29 AM
A Thanksgiving Question studiot Physics 56 06-28-2009 10:28 AM
Butterworth filter transfer function calculation mentaaal General Electronics Chat 9 03-27-2009 04:54 PM
recursive function FUNJOKE Programmer's Corner 1 02-21-2009 03:03 AM
Question I didn't get on my exam on controllability of a system... blazedaces Homework Help 3 12-10-2008 01:33 AM

Thread Tools
Display Modes

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

Forum Jump

All times are GMT. The time now is 03:05 AM.

User-posted content, unless source quoted, is licensed under a Creative Commons Public Domain License.
Powered by vBulletin
Copyright ©2000 - 2014, vBulletin Solutions, Inc.