WvStreams
utils
wvhash.cc
1
#include "wvhash.h"
2
3
// Note: this hash function is case-insensitive since it ignores the
4
// bit in ASCII that defines case. You may want to take advantage of this.
5
unsigned
int
WvHash(
const
char
*s)
6
{
7
unsigned
hash = 0, slide, andval;
8
if
(!s)
return
0;
9
10
slide =
sizeof
(hash)*8 - 5;
11
andval = 0x1F << slide;
12
13
while
(*s)
14
hash = (hash<<4) ^ (*(s++) & 0x1F) ^ ((hash & andval) >> slide);
15
16
return
hash;
17
}
18
19
unsigned
WvHash(
WvStringParm
s)
20
{
21
return
!s ? 0 : WvHash((
const
char
*)s);
22
}
23
24
// FIXME: does this suck?
25
unsigned
WvHash(
const
int
&i)
26
{
27
return
i;
28
}
29
30
31
unsigned
WvHash(
const
void
*p)
32
{
33
return
reinterpret_cast<
unsigned
long
>
(p);
34
}
35
WvFastString
A WvFastString acts exactly like a WvString, but can take (const char *) strings without needing to a...
Definition:
wvstring.h:94
Generated by
1.8.18