/contrib/groff/src/libs/libgroff/ptable.cpp

https://bitbucket.org/freebsd/freebsd-head/ · C++ · 52 lines · 30 code · 4 blank · 18 comment · 8 complexity · 79c9e4143ef9ad2200c19e7eebfb9951 MD5 · raw file

  1. /* Copyright (C) 1989, 1990, 1991, 1992 Free Software Foundation, Inc.
  2. Written by James Clark (jjc@jclark.com)
  3. This file is part of groff.
  4. groff is free software; you can redistribute it and/or modify it under
  5. the terms of the GNU General Public License as published by the Free
  6. Software Foundation; either version 2, or (at your option) any later
  7. version.
  8. groff is distributed in the hope that it will be useful, but WITHOUT ANY
  9. WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10. FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  11. for more details.
  12. You should have received a copy of the GNU General Public License along
  13. with groff; see the file COPYING. If not, write to the Free Software
  14. Foundation, 51 Franklin St - Fifth Floor, Boston, MA 02110-1301, USA. */
  15. #include "ptable.h"
  16. #include "errarg.h"
  17. #include "error.h"
  18. unsigned long hash_string(const char *s)
  19. {
  20. assert(s != 0);
  21. unsigned long h = 0, g;
  22. while (*s != 0) {
  23. h <<= 4;
  24. h += *s++;
  25. if ((g = h & 0xf0000000) != 0) {
  26. h ^= g >> 24;
  27. h ^= g;
  28. }
  29. }
  30. return h;
  31. }
  32. static const unsigned table_sizes[] = {
  33. 101, 503, 1009, 2003, 3001, 4001, 5003, 10007, 20011, 40009,
  34. 80021, 160001, 500009, 1000003, 2000003, 4000037, 8000009,
  35. 16000057, 32000011, 64000031, 128000003, 0
  36. };
  37. unsigned next_ptable_size(unsigned n)
  38. {
  39. const unsigned *p;
  40. for (p = table_sizes; *p <= n; p++)
  41. if (*p == 0)
  42. fatal("cannot expand table");
  43. return *p;
  44. }