File: inlines.cc

package info (click to toggle)
apachetop 0.19.7-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 324 kB
  • sloc: cpp: 3,005; makefile: 25; sh: 1
file content (44 lines) | stat: -rw-r--r-- 855 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include "apachetop.h"

#define THREE_QUARTERS  24
#define ONE_EIGHTH      4
#define HIGH_BITS       (~((unsigned int)(~0) >> ONE_EIGHTH))

inline unsigned int StringHash(register const char *str)
{
	register unsigned int val;
	register unsigned int i;

	for (val = 0; *str; str++)
	{
		val = (val << ONE_EIGHTH) + *str;

		if ((i = val & HIGH_BITS) != 0)
			val = (val ^ (i >> THREE_QUARTERS)) & ~HIGH_BITS;
	}
	return val;
}

inline unsigned int QuickHash(register const char *str)
{
	register unsigned int val, tmp;

	for(val = 0 ; *str ; str++)
	{
		val = (val << 4) + *str;
		if ((tmp = (val & 0xf0000000)))
			val = (val ^ (tmp >> 24)) ^ tmp;
	}
	return val;
}

inline unsigned long TTHash(register const char *str)
{
	unsigned long hash = 5381;
	int c;

	while ((c = *str++))
		hash = ((hash << 5) + hash) + c; /* hash * 33 + c */

	return hash;
}