![]() |
|
|||||||
| 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. |
|
|
|
Thread Tools | Display Modes |
|
#1
|
|||
|
|||
|
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. |
|
#2
|
|||
|
|||
|
Stack of information can be obtained from here Hashing algorythms and examples , explanations
http://www.partow.net/programming/ha...FormsOfHashing Should help you on this extensive subject |
| The Following User Says Thank You to Harrington For This Useful Post: | ||
moslem (07-13-2010) | ||
|
#3
|
||||
|
||||
|
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 |
| 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 | |
|
|