Take the result sequence as a base 26 value example

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: racters of key string into a short. char const *key ="John"; short b= 0; memcpy (&b, &(key[2]), 2); Or use casting to avoid a memcopy char const *key ="John"; short *b = (short *) & (key[2]); 38 Hashing algorithms Randomizing hash functions follow three basic steps: 1. represent the key in numerical form 2. apply a routine to change the bits of the key 3. map the resulting value to the address space by dividing the number of slots. Generally use divide by a prime number. Often the value 2**k -1 will work well. 39 Hashing Function A function with more randomness? Fold and add E.g. key = 17207359, address = 7500 1720 7359 1720 + 7359 = 9078 9078 x 0.75 = 6809 Other variation (172, 073, 59) => 271+073+950=1294x0.75=971 Divide-by-a-prime E.g. key = 767987697676323232323232, address = 20000 (7679 + 8769 + 7676 + 3232 + 3232 + 3232) mod 19937 = address 40 Note: 19937 is a prime closed to 20000 Hashing Function (Cont.) Mid-square E.g. Key: 6-digit integer, address 7500 => (123456)2 = 015241383936 => 4138 x 0.75 = 3104 (address) Radix transformation E.g. radix = 11, key = 326 3 x 112 + 2 x 111 + 6 x 110 = 391 Truncation x x mod 10n E.g. 1001322 mod 103 = 322 Digit-analysis method (refer Horrowitz) 41 Predicting the Distribution of Records If there exists n addresses in a file...
View Full Document

Ask a homework question - tutors are online