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
015import org.jikesrvm.runtime.Magic;
016import org.jikesrvm.util.HashMapRVM.Bucket;
017
018/**
019 * The same as {@link HashMapRVM} except object identities determine equality
020 * not the equals method.
021 */
022public final class IdentityHashMapRVM<K, V> extends AbstractHashMapRVM<K, V> {
023  @Override
024  boolean same(K k1, K k2) {
025    return k1 == k2;
026  }
027
028  @Override
029  protected int hashTheKey(K key) {
030    if (!org.jikesrvm.VM.runningVM) {
031      return Magic.bootImageIdentityHashCode(key);
032    } else {
033      return System.identityHashCode(key);
034    }
035  }
036
037  @Override
038  AbstractBucket<K,V> createNewBucket(K key, V value, AbstractBucket<K, V> next) {
039    return new Bucket<K,V>(key, value, next);
040  }
041
042  public IdentityHashMapRVM() {
043    super(DEFAULT_SIZE);
044  }
045
046  public IdentityHashMapRVM(int size) {
047    super(size);
048  }
049}