Register Blogs FAQ Members List Today's Posts Search Today's Posts Mark Forums Read

 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.

#1
07-10-2010, 04:13 PM
 moslem Junior Member Join Date: Dec 2009 Posts: 20

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;
}
why we multiply by 31 the hash every time is this for making weighting for the characters or any thing else?
#2
07-13-2010, 01:15 AM
 Harrington Banned Join Date: Dec 2009 Location: London Posts: 86

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

http://www.partow.net/programming/ha...FormsOfHashing

 The Following User Says Thank You to Harrington For This Useful Post: moslem (07-13-2010)
#3
07-13-2010, 01:58 PM
 Papabravo Senior Member Join Date: Feb 2006 Location: Michigan, USA (GMT-5) Posts: 5,850

Notice that 31 is a Mersenne prime

http://en.wikipedia.org/wiki/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.

http://en.wikipedia.org/wiki/Linear_...tial_generator
__________________
We never have time to do it right,
But we always have time to do it over.
 The Following User Says Thank You to Papabravo For This Useful Post: moslem (07-13-2010)

 Tags bout, function, hash, question, string

 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 someonesdad General Electronics Chat 16 08-05-2009 04:29 AM studiot Physics 56 06-28-2009 10:28 AM mentaaal General Electronics Chat 9 03-27-2009 04:54 PM FUNJOKE Programmer's Corner 1 02-21-2009 03:03 AM blazedaces Homework Help 3 12-10-2008 01:33 AM

 Thread Tools Display Modes Linear Mode

 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 Rules
 Forum Jump User Control Panel Private Messages Subscriptions Who's Online Search Forums Forums Home Electronics Forums     General Electronics Chat     The Projects Forum     Homework Help     Electronics Resources Software, Microcomputing, and Communications Forums     Programmer's Corner     Embedded Systems and Microcontrollers     Computing and Networks     Radio and Communications Circuits and Projects     The Completed Projects Collection Abstract Forums     Math     Physics     General Science All About Circuits Commmunity Forums     Off-Topic     The Flea Market     Feedback and Suggestions

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