xref: /haiku/src/system/kernel/util/StringHash.cpp (revision 9a6a20d4689307142a7ed26a1437ba47e244e73f)
1 /*
2  * Copyright 2002-2013, Haiku, Inc. All rights reserved.
3  * Distributed under the terms of the MIT License.
4  *
5  * Copyright 2001, Travis Geiselbrecht. All rights reserved.
6  * Distributed under the terms of the NewOS License.
7  */
8 
9 
10 #include <util/StringHash.h>
11 
12 
13 uint32
14 hash_hash_string(const char* _string)
15 {
16 	const uint8* string = (const uint8*)_string;
17 
18 	uint32 h = 5381;
19 	char c;
20 	while ((c = *string++) != 0)
21 		h = (h * 33) + c;
22 	return h;
23 }
24 
25 
26 uint32
27 hash_hash_string_part(const char* _string, size_t maxLength)
28 {
29 	const uint8* string = (const uint8*)_string;
30 
31 	uint32 h = 5381;
32 	char c;
33 	while (maxLength-- > 0 && (c = *string++) != 0)
34 		h = (h * 33) + c;
35 	return h;
36 }
37