Hash+examples

Rik hacked-up a version of the assignment in C... it builds character. 8-) Here's a snippet of code which works for me, and uses function variables: code format="c" 215 includeFunc(int (*funcPtr)(struct StudentRecord *), char *funcName) { 216        maxFunc++; 217         funcArray[maxFunc] = funcPtr; 218         funcNames[maxFunc] = funcName; 219 } 220 221 initializeFuncArray { 222     maxFunc = -1; 223     includeFunc( hash1stLetter,          "1st letter"); 224     includeFunc( hashNumLettersInGivenName,      "|given|"); 225     includeFunc( hashSumGiven,           "sum(given)"); 226     includeFunc( hashSumName,            "sum(name)"); 227     includeFunc( hashSID,                "SID"); 228     includeFunc( hashSIDnon0,            "SID non 0"); 229     includeFunc( hashSIDmod28,           "SID mod 28"); 230     includeFunc( hashSumPhone,           "sum(phone)"); 231     includeFunc( hash1,                  "const 1"); 232     includeFunc( hash7,                  "const 7"); 233    includeFunc( hash11,                 "const 11"); 234    includeFunc( hash35,                 "const 35"); 235 } 236 237 useFuncNumbers(int hash, int rehash){ 238        hashFunc = funcArray[hash]; 239        rehashFunc = funcArray[rehash]; 240        printf("\n===== Hash: %s,   Re-hash: %s  ", funcNames[hash], funcNames[rehash]); 241 } code

And here are some sample results which you are welcome to emulate or reproduce. I commandeered the fields for points to represent, respectively code
 * 1) the hashFunction value for this student
 * 2) the re-hash value for this student
 * 3) the number of comparisons this student used to find a spot

=
Hash: sum(phone),  Re-hash: const 1   < hashKlingons52.txt Failed to insert student #43 Xvcvujp        CSPbvLa          943831513   360-819-1266 141.0  51  24   1  42

Students: 0: Cvwhnw         Dnh              943838643 18100-245-8919 205.0  93   0   1   0 1: Ubixwn  CvakkvorZpbhvxxSzbhogjv 943746573 18100-185-6937 169.0 205   1   1   0 2: Oyxzgmtdmtncci KVyudgk          943877455 18100-643-9129 152.0  97  38   1   6 3: Yclxway        Gvmveawk         943739970   503-316-4465 170.0 149  19   1  26 4: Uneihaba       AyqnvdTn         943893420   503-442-6219 185.0  94  18   1  28 5: Whmmt          Jcxhscwy         943885887   503-399-4237 120.0   7  27   1  20 6: Lpwjbmdjcxwrfxmu FRtDpfmxe      943814122 18100-824-7421 149.0 149  32   1  16 7: Ftf            Phwmze           943709156   503-380-6883 160.0 157  26   1  23 8: Legrskims      FnbMlgo          943867380   417-361-7025 143.0 334  18   1  32 9: Tkkyncoiwzzg   DksgZkjmqX       943523187   360-344-5020 199.0 199   9   1   0 10: Dsnyz          Orrzqhudk        943633237   360-787-3890 147.0 271  33   1  19 11: Cyesb          RnyBHht          943657045   503-750-6120 200.0  83  11   1   0 12: Jtnf           JoErFokK         943702274   503-016-4803 132.0 137  12   1   0 13: Umls           LpkmqgleUDjkp    943603012   360-413-3613 128.0 250  12   1   1 14: Yujplntsk      FuohlEm          943666097   360-223-0277 124.0 168  14   1   0 15: Fagsysmo       Rbnm             943828475   503-616-1712 170.0  51  14   1   1 16: Zodzndorq      QrSc             943757888   503-315-0278 201.0 317  16   1   0 17: Fwwpexld       Qed              943770226   360-821-4056 149.0 319  17   1   0 18: Bozcmot        FaIcmveKnwjeR    943825375   360-830-0393 194.0   1  17   1   1 19: Mokok          IwcAqnzkdcza     943880183   360-851-3029 173.0 124  19   1   0 20: Kfcjhca        BWhLspm          943795646   503-116-9193 163.0 122  20   1   0 21: Pmokdebkxznldhv Ctd             943819330   417-342-4623 142.0 270  18   1   3 22: Cjoeqyzzqkvjzzaakfxdwf DVTya    943912578   360-062-0918 174.0 296  17   1   5 23: Tvqwphekpcoontctak GuvGJ        943637329   503-169-0737 169.0 244  23   1   0 24: Zlxe           FZHmsJ           943686991   503-171-6657 179.0  58  23   1   1 25: Tyksvtjkt      CTtAmg           943720099   360-476-4508 163.0 256  25   1   0 26: Dtknmduzzg     Wzvp             943585559   417-248-2833 183.0 255  24   1   2 27: Nxjensazi      YDqjOyMzbjmhogoN 943542469   360-452-5591 165.0 285  22   1   5 28: Noe            Eonh             943729213   360-544-8592 144.0 114  28   1   0 29: Uertn          MqLmnubpBqWb     943694152   360-973-8118 129.0  22  28   1   1 30: Oryfk          Qsheuwnq         943554931   360-869-7171 151.0 103  30   1   0 31: Xlfcz          Fftgcd           943610390   360-165-7993 155.0 141  31   1   0 32: Pxwli          NhCVnp           943674560   503-691-7366 159.0 122  28   1   4 33: Rszopgfb       MiV              943681721 18100-112-7841 123.0 328  28   1   5 34: Vlndhjlnz      EowGjkRprwri     943530720   503-608-5597 134.0 170  30   1   4 35: Qdltec         Yvh              943581188 18100-076-9531 139.0 299  35   1   0 36: Keocvoqwibsvk  UVoapzmt         943780549   360-908-5927 159.0  12  31   1   5 37: Avv            BmCs             943855166   417-992-7925 136.0 127  37   1   0 38: Hcoi           OTytLyjl         943547119   503-816-8023 185.0 264  18   1  20 39: Wxvpbzj        LGftBI           943883035   503-097-8852 161.0 262  29   1  10 40: Ccexvkaxi      GqtsdlPTtqf      943597556   360-651-1266 175.0 301  18   1  22 41: Ceuj           WznlrfnavmAlwI   943846207   360-677-9508 189.0  39  33   1   8
 * 1) Students=42  # Comparisons=310

=
Hash: sum(phone),  Re-hash: sum(phone)   < hashKlingons52.txt Failed to insert student #13 Pxwli          NhCVnp           943674560   503-691-7366 159.0 122  28  28   3

Students: 0: Cvwhnw         Dnh              943838643 18100-245-8919 205.0  93   0   0   0 1: Ubixwn  CvakkvorZpbhvxxSzbhogjv 943746573 18100-185-6937 169.0 205   1   1   0 4: Zlxe           FZHmsJ           943686991   503-171-6657 179.0  58  23  23   1 12: Jtnf           JoErFokK         943702274   503-016-4803 132.0 137  12  12   0 14: Uertn          MqLmnubpBqWb     943694152   360-973-8118 129.0  22  28  28   1 19: Mokok          IwcAqnzkdcza     943880183   360-851-3029 173.0 124  19  19   0 20: Kfcjhca        BWhLspm          943795646   503-116-9193 163.0 122  20  20   0 23: Tvqwphekpcoontctak GuvGJ        943637329   503-169-0737 169.0 244  23  23   0 28: Noe            Eonh             943729213   360-544-8592 144.0 114  28  28   0 30: Oryfk          Qsheuwnq         943554931   360-869-7171 151.0 103  30  30   0 31: Xlfcz          Fftgcd           943610390   360-165-7993 155.0 141  31  31   0 37: Avv            BmCs             943855166   417-992-7925 136.0 127  37  37   0
 * 1) Students=12  # Comparisons=5

code The sum(phone #) function makes a decent 1st hash, but as a re-hash, it can run into trouble.

NB: it is easy with my framework to run all 144 (gross) pairings of hash and re-hash functions, and for various input files. Then it's a matter of sifting through for interesting results. There are many interesting results.

Any comments?