1114402Sru/* Copyright (C) 1989, 1990, 1991, 1992 Free Software Foundation, Inc. 2114402Sru Written by James Clark (jjc@jclark.com) 3114402Sru 4114402SruThis file is part of groff. 5114402Sru 6114402Srugroff is free software; you can redistribute it and/or modify it under 7114402Sruthe terms of the GNU General Public License as published by the Free 8114402SruSoftware Foundation; either version 2, or (at your option) any later 9114402Sruversion. 10114402Sru 11114402Srugroff is distributed in the hope that it will be useful, but WITHOUT ANY 12114402SruWARRANTY; without even the implied warranty of MERCHANTABILITY or 13114402SruFITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14114402Srufor more details. 15114402Sru 16114402SruYou should have received a copy of the GNU General Public License along 17114402Sruwith groff; see the file COPYING. If not, write to the Free Software 18151497SruFoundation, 51 Franklin St - Fifth Floor, Boston, MA 02110-1301, USA. */ 19114402Sru 20114402Sru#include "ptable.h" 21114402Sru#include "errarg.h" 22114402Sru#include "error.h" 23114402Sru 24114402Sruunsigned long hash_string(const char *s) 25114402Sru{ 26114402Sru assert(s != 0); 27114402Sru unsigned long h = 0, g; 28114402Sru while (*s != 0) { 29114402Sru h <<= 4; 30114402Sru h += *s++; 31114402Sru if ((g = h & 0xf0000000) != 0) { 32114402Sru h ^= g >> 24; 33114402Sru h ^= g; 34114402Sru } 35114402Sru } 36114402Sru return h; 37114402Sru} 38114402Sru 39114402Srustatic const unsigned table_sizes[] = { 40114402Sru101, 503, 1009, 2003, 3001, 4001, 5003, 10007, 20011, 40009, 41114402Sru80021, 160001, 500009, 1000003, 2000003, 4000037, 8000009, 42114402Sru16000057, 32000011, 64000031, 128000003, 0 43114402Sru}; 44114402Sru 45114402Sruunsigned next_ptable_size(unsigned n) 46114402Sru{ 47114402Sru const unsigned *p; 48114402Sru for (p = table_sizes; *p <= n; p++) 49114402Sru if (*p == 0) 50114402Sru fatal("cannot expand table"); 51114402Sru return *p; 52114402Sru} 53