12fdd1d9eSIngo Weinhold /* 22fdd1d9eSIngo Weinhold * Copyright 2002-2013, Haiku, Inc. All rights reserved. 32fdd1d9eSIngo Weinhold * Distributed under the terms of the MIT License. 42fdd1d9eSIngo Weinhold * 52fdd1d9eSIngo Weinhold * Copyright 2001, Travis Geiselbrecht. All rights reserved. 62fdd1d9eSIngo Weinhold * Distributed under the terms of the NewOS License. 72fdd1d9eSIngo Weinhold */ 82fdd1d9eSIngo Weinhold 92fdd1d9eSIngo Weinhold 102fdd1d9eSIngo Weinhold #include <util/StringHash.h> 112fdd1d9eSIngo Weinhold 122fdd1d9eSIngo Weinhold 132fdd1d9eSIngo Weinhold uint32 hash_hash_string(const char * _string)14*006c9018SAugustin Cavalierhash_hash_string(const char* _string) 152fdd1d9eSIngo Weinhold { 16*006c9018SAugustin Cavalier const uint8* string = (const uint8*)_string; 17*006c9018SAugustin Cavalier 18*006c9018SAugustin Cavalier uint32 h = 5381; 192fdd1d9eSIngo Weinhold char c; 20*006c9018SAugustin Cavalier while ((c = *string++) != 0) 21*006c9018SAugustin Cavalier h = (h * 33) + c; 22*006c9018SAugustin Cavalier return h; 232fdd1d9eSIngo Weinhold } 242fdd1d9eSIngo Weinhold 252fdd1d9eSIngo Weinhold 262fdd1d9eSIngo Weinhold uint32 hash_hash_string_part(const char * _string,size_t maxLength)27*006c9018SAugustin Cavalierhash_hash_string_part(const char* _string, size_t maxLength) 282fdd1d9eSIngo Weinhold { 29*006c9018SAugustin Cavalier const uint8* string = (const uint8*)_string; 30*006c9018SAugustin Cavalier 31*006c9018SAugustin Cavalier uint32 h = 5381; 322fdd1d9eSIngo Weinhold char c; 33*006c9018SAugustin Cavalier while (maxLength-- > 0 && (c = *string++) != 0) 34*006c9018SAugustin Cavalier h = (h * 33) + c; 35*006c9018SAugustin Cavalier return h; 362fdd1d9eSIngo Weinhold } 37