ptable.cc 797 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /* Copyright (C) 1989, 1990, 1991, 1992 Free Software Foundation, Inc.
  2. Written by James Clark (jjc@jclark.com) */
  3. #include "ptable.h"
  4. #include "errarg.h"
  5. #include "error.h"
  6. unsigned long
  7. hash_string(const char *s)
  8. {
  9. assert(s != 0);
  10. unsigned long h = 0, g;
  11. while (*s != 0)
  12. {
  13. h <<= 4;
  14. h += *s++;
  15. if ((g = h & 0xf0000000) != 0)
  16. {
  17. h ^= g >> 24;
  18. h ^= g;
  19. }
  20. }
  21. return h;
  22. }
  23. static const unsigned table_sizes[] = {
  24. 101, 503, 1009, 2003, 3001, 4001, 5003, 10007, 20011, 40009,
  25. 80021, 160001, 500009, 1000003, 2000003, 4000037, 8000009,
  26. 16000057, 32000011, 64000031, 128000003, 0
  27. };
  28. unsigned
  29. next_ptable_size(unsigned n)
  30. {
  31. const unsigned *p;
  32. for (p = table_sizes; *p <= n; p++)
  33. if (*p == 0)
  34. fatal("cannot expand table");
  35. return *p;
  36. }