Deleted Added
full compact
hash.cc (58551) hash.cc (67064)
1/*
1/*
2Copyright (C) 1990 Free Software Foundation
2Copyright (C) 1990, 2000 Free Software Foundation
3 written by Doug Lea (dl@rocky.oswego.edu)
3 written by Doug Lea (dl@rocky.oswego.edu)
4
5This file is part of the GNU C++ Library. This library is free
6software; you can redistribute it and/or modify it under the terms of
7the GNU Library General Public License as published by the Free
8Software Foundation; either version 2 of the License, or (at your
9option) any later version. This library is distributed in the hope
10that it will be useful, but WITHOUT ANY WARRANTY; without even the
11implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12PURPOSE. See the GNU Library General Public License for more details.
13You should have received a copy of the GNU Library General Public
14License along with this library; if not, write to the Free Software
15Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16*/
17
18#include <hash.h>
19
20/*
4*/
5
6#include <hash.h>
7
8/*
21 some useful hash functions
9 Some useful hash function.
10 It's not a particularly good hash function (<< 5 would be better than << 4),
11 but people believe in it because it comes from Dragon book.
22*/
23
12*/
13
24unsigned int hashpjw (const char* x) // From Dragon book, p436
14unsigned int
15hashpjw (const char *x, unsigned int len) // From Dragon book, p436
25{
26 unsigned int h = 0;
27 unsigned int g;
28
16{
17 unsigned int h = 0;
18 unsigned int g;
19
29 while (*x != 0)
30 {
31 h = (h << 4) + (unsigned char) *x++;
32 if ((g = h & 0xf0000000) != 0)
33 h = (h ^ (g >> 24)) ^ g;
34 }
20 for (; len > 0; len--)
21 {
22 h = (h << 4) + (unsigned char) *x++;
23 if ((g = h & 0xf0000000) != 0)
24 h = (h ^ (g >> 24)) ^ g;
25 }
35 return h;
36}
26 return h;
27}