home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / comp / sys / atari / st / tech / 5506 < prev    next >
Encoding:
Internet Message Format  |  1992-11-05  |  2.5 KB

  1. Path: sparky!uunet!pipex!warwick!uknet!mcsun!corton!loria!loria.crin.fr!eker
  2. From: eker@loria.crin.fr (Steven Eker)
  3. Newsgroups: comp.sys.atari.st.tech
  4. Subject: Re: Cross Compiling Sozobon 2.0
  5. Keywords: hash function
  6. Message-ID: <567@muller.loria.fr>
  7. Date: 5 Nov 92 17:07:43 GMT
  8. References: <1992Nov2.133525.7992@sol.ctr.columbia.edu> <1992Nov3.140438.19093@news.lrz-muenchen.de>
  9. Sender: news@news.loria.fr
  10. Organization: CRIN (CNRS) Nancy - INRIA Lorraine
  11. Lines: 54
  12.  
  13. In article <1992Nov3.140438.19093@news.lrz-muenchen.de>, HUSFELD@usmv01.usm.uni-muenchen.de (Husfeld, Dirk) writes:
  14. |> In <1992Nov2.133525.7992@sol.ctr.columbia.edu> richard@op.ph.ic.ac.uk writes:
  15.  
  16. [discussion of what hashing is supposed to be deleted]
  17.  
  18. |> > 
  19. |> > hash(s)
  20. |> > unsigned char *s;
  21. |> > {
  22. |> >         unsigned char c;
  23. |> >         register i, n = 0;
  24. |> > 
  25. |> >         for (i=1; i<5; i++) {
  26. |> >                 c = s[i];
  27. |> >                 if (!c)
  28. |> >                         break;
  29. |> >                 n = (n<<1)|c;
  30. |> >         }
  31. |> >         return n & (NHASH-1);       /* NHASH is the max value */
  32. |> > }
  33. |> > 
  34. |> > 
  35. |> > I've spotted that this routine only uses the 1st to fifth letters of
  36.  
  37. Actually 1st -> 4th letters.
  38.  
  39. |> > the name (skipping the first underscore), and that this is the same
  40. |> > for both __initial_stack and __init_signal, but increasing the number
  41. |> > doesn't help - in fact the routine only seems to return hash values
  42. |> > of 46,61,62,63 whatever is passed through to it when it uses seven
  43. |> > characters.
  44.  
  45. This is a truly _awful_ hash function; simply ORing and shifting is
  46. going to produce a heavy bias towards hash values with lots of ones -
  47. especially in the more significant bits:
  48. 46=%101110, 61=%111101, 62=%111110, 63=%111111
  49. (one can guess that NHASH=64)
  50.  
  51. Replace the OR (|) with addition (+) or exclusive-OR (^) for some improvement.
  52.  
  53. |> >
  54. |> One might argue over the sensibility of a hash function that only looks
  55. |> at the first characters of a name.  It is often a bad approach because
  56. |> some programmers enumerate their variables (like file1, file2,...;
  57. |> not recommended), others use a verb-object template for their function
  58. |> names (get_this(), get_that(), get_next()...).  Nevertheless, a bad hash
  59. |> function only slows down the calling code because it has to do more work
  60. |> to solve the name clash.
  61.  
  62. Agreed. I believe the Sozobug loader only deals the first 8 characters
  63. of a name so I'd hash on 1 thu 7 (starting at zero!);
  64. i.e. replace the 5 with an 8 in the above code.
  65.  
  66. Steven
  67.