001/* 002 * This file is part of the Jikes RVM project (http://jikesrvm.org). 003 * 004 * This file is licensed to You under the Eclipse Public License (EPL); 005 * You may not use this file except in compliance with the License. You 006 * may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/eclipse-1.0.php 009 * 010 * See the COPYRIGHT.txt file distributed with this work for information 011 * regarding copyright ownership. 012 */ 013package org.jikesrvm.util; 014 015/** 016 * Stripped down implementation of HashMap data structure for use 017 * by core parts of the JikesRVM runtime. Consider the use of 018 * {@link ImmutableEntryHashMapRVM} when the use of the HashMap 019 * methods is limited. 020 */ 021public final class HashMapRVM<K, V> extends AbstractHashMapRVM<K, V> { 022 023 static final class Bucket<K, V> extends AbstractBucket<K,V> { 024 private AbstractBucket<K, V> next; 025 private final K key; 026 private V value; 027 028 Bucket(K k, V v, AbstractBucket<K, V> n) { 029 key = k; 030 value = v; 031 next = n; 032 } 033 034 @Override 035 AbstractBucket<K, V> getNext() { 036 return next; 037 } 038 039 @Override 040 AbstractBucket<K, V> setNext(AbstractBucket<K, V> n) { 041 next = n; 042 return this; 043 } 044 045 @Override 046 K getKey() { 047 return key; 048 } 049 050 @Override 051 V getValue() { 052 return value; 053 } 054 055 @Override 056 void setValue(V v) { 057 value = v; 058 } 059 } 060 061 @Override 062 AbstractBucket<K,V> createNewBucket(K key, V value, AbstractBucket<K, V> next) { 063 return new Bucket<K,V>(key, value, next); 064 } 065 066 public HashMapRVM() { 067 super(DEFAULT_SIZE); 068 } 069 070 public HashMapRVM(int size) { 071 super(size); 072 } 073 074 @Override 075 protected boolean same(K k1, K k2) { 076 return k1.equals(k2); 077 } 078 079 @Override 080 protected int hashTheKey(K key) { 081 return key.hashCode(); 082 } 083}