Mercurial > hg > truffle
comparison graal/com.oracle.max.base/src/com/sun/max/collect/HashEntryChainedHashMapping.java @ 3733:e233f5660da4
Added Java files from Maxine project.
author | Thomas Wuerthinger <thomas.wuerthinger@oracle.com> |
---|---|
date | Sat, 17 Dec 2011 19:59:18 +0100 |
parents | |
children | bc8527f3071c |
comparison
equal
deleted
inserted
replaced
3732:3e2e8b8abdaf | 3733:e233f5660da4 |
---|---|
1 /* | |
2 * Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved. | |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | |
4 * | |
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 | |
7 * published by the Free Software Foundation. | |
8 * | |
9 * This code is distributed in the hope that it will be useful, but WITHOUT | |
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
12 * version 2 for more details (a copy is included in the LICENSE file that | |
13 * accompanied this code). | |
14 * | |
15 * You should have received a copy of the GNU General Public License version | |
16 * 2 along with this work; if not, write to the Free Software Foundation, | |
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
18 * | |
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | |
20 * or visit www.oracle.com if you need additional information or have any | |
21 * questions. | |
22 */ | |
23 package com.sun.max.collect; | |
24 | |
25 /** | |
26 * A chained hash table whose {@linkplain HashEntry entries} record the hash of the key. This can provide better | |
27 * performance improvement when the cost of computing the key's hash code is high. | |
28 */ | |
29 public class HashEntryChainedHashMapping<K, V> extends ChainedHashMapping<K, V> { | |
30 | |
31 public static class HashEntry<K, V> extends DefaultEntry<K, V> { | |
32 | |
33 final int hashOfKey; | |
34 | |
35 public HashEntry(int hashOfKey, K key, V value, Entry<K, V> next) { | |
36 super(key, value, next); | |
37 this.hashOfKey = hashOfKey; | |
38 } | |
39 } | |
40 | |
41 /** | |
42 * Creates a chained hash table whose entries record the hash of the key. | |
43 * | |
44 * @param equivalence | |
45 * the semantics of key comparison and hashing. If {@code null}, then {@link HashEquality} is used. | |
46 * @param initialCapacity | |
47 * the initial capacity of the table | |
48 */ | |
49 public HashEntryChainedHashMapping(HashEquivalence<K> equivalence, int initialCapacity) { | |
50 super(equivalence, initialCapacity); | |
51 } | |
52 | |
53 /** | |
54 * Creates a chained hash table with {@linkplain HashEquality equality} key semantics whose entries record the hash | |
55 * of the key. | |
56 * | |
57 * @param initialCapacity | |
58 * the initial capacity of the table | |
59 */ | |
60 public HashEntryChainedHashMapping(int initialCapacity) { | |
61 super(initialCapacity); | |
62 } | |
63 | |
64 /** | |
65 * Creates a chained hash table with an initial capacity of {@value ChainedHashMapping#DEFAULT_INITIAL_CAPACITY} | |
66 * whose entries record the hash of the key. | |
67 * | |
68 * @param equivalence | |
69 * the semantics of key comparison and hashing. If {@code null}, then {@link HashEquality} is used. | |
70 */ | |
71 public HashEntryChainedHashMapping(HashEquivalence<K> equivalence) { | |
72 super(equivalence); | |
73 } | |
74 | |
75 /** | |
76 * Creates a chained hash table with {@linkplain HashEquality equality} key semantics and an initial capacity of | |
77 * {@value ChainedHashMapping#DEFAULT_INITIAL_CAPACITY} whose entries record the hash of the key. | |
78 */ | |
79 public HashEntryChainedHashMapping() { | |
80 super(); | |
81 } | |
82 | |
83 @Override | |
84 protected Entry<K, V> createEntry(int hashOfKey, K key, V value, Entry<K, V> next) { | |
85 return new HashEntryChainedHashMapping.HashEntry<K, V>(hashOfKey, key, value, next); | |
86 } | |
87 | |
88 @Override | |
89 protected boolean matches(Entry<K, V> entry, K key, int hashForKey) { | |
90 final K entryKey = entry.key(); | |
91 return entryKey == key || (hashForKey == ((HashEntryChainedHashMapping.HashEntry) entry).hashOfKey && key.equals(entryKey)); | |
92 } | |
93 } |