equal
deleted
inserted
replaced
1 /* |
1 /* |
2 * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. |
7 * published by the Free Software Foundation. |
27 |
27 |
28 #include "memory/allocation.inline.hpp" |
28 #include "memory/allocation.inline.hpp" |
29 #include "utilities/hashtable.hpp" |
29 #include "utilities/hashtable.hpp" |
30 |
30 |
31 // Inline function definitions for hashtable.hpp. |
31 // Inline function definitions for hashtable.hpp. |
32 |
|
33 |
|
34 // -------------------------------------------------------------------------- |
|
35 // Hash function |
|
36 |
|
37 // We originally used hashpjw, but hash P(31) gives just as good results |
|
38 // and is slighly faster. We would like a hash function that looks at every |
|
39 // character, since package names have large common prefixes, and also because |
|
40 // hash_or_fail does error checking while iterating. |
|
41 |
|
42 // hash P(31) from Kernighan & Ritchie |
|
43 |
|
44 inline unsigned int BasicHashtable::hash_symbol(const char* s, int len) { |
|
45 unsigned int h = 0; |
|
46 while (len-- > 0) { |
|
47 h = 31*h + (unsigned) *s; |
|
48 s++; |
|
49 } |
|
50 return h; |
|
51 } |
|
52 |
|
53 |
32 |
54 // -------------------------------------------------------------------------- |
33 // -------------------------------------------------------------------------- |
55 |
34 |
56 // Initialize a table. |
35 // Initialize a table. |
57 |
36 |