FileDocCategorySizeDatePackage
LongHashMap.javaAPI DocGlassfish v2 API7453Fri May 04 22:33:00 BST 2007com.sun.ejb.containers.util

LongHashMap

public class LongHashMap extends Object

Fields Summary
protected static final int
DEFAULT_CAPACITY
protected static final float
DEFAULT_LOAD_FACTOR
protected static final int
MAXIMUM_CAPACITY
protected static boolean
debug
protected transient Entry[]
table
protected float
loadFactor
protected transient int
size
protected int
bucketmask
protected int
capacity
protected int
threshold
Constructors Summary
public LongHashMap()


      
        this(DEFAULT_CAPACITY, DEFAULT_LOAD_FACTOR);
    
public LongHashMap(int initialCapacity)

       this(initialCapacity, DEFAULT_LOAD_FACTOR);
    
public LongHashMap(int initialCapacity, float loadFactor)

        if (initialCapacity > MAXIMUM_CAPACITY) {
            initialCapacity = MAXIMUM_CAPACITY;
        }
        if (loadFactor <= 0 || Float.isNaN(loadFactor)) {
            throw new IllegalArgumentException("Illegal load factor: "
                                               + loadFactor);
        }

        // Find a power of 2 >= initialCapacity
        capacity = 1;
        
        while (capacity < initialCapacity) {
            capacity <<= 1;
        }
        this.loadFactor = loadFactor;
        this.threshold = (int)(capacity * loadFactor);
        this.table = new Entry[capacity];
        this.bucketmask = capacity - 1;
    
Methods Summary
public booleancontains(long key)

        int index = ((int) key) & bucketmask;
        for (Entry e = table[index]; e != null; e = e.next) {
            if (e.key == key) {
                return true;
            }
        }
        return false;
    
public java.util.Enumerationelements()

        Vector keyList = new Vector();
        for (int index=0; index<capacity; index++) {
            for (Entry e = table[index]; e != null; e = e.next) {
                keyList.addElement(e.value);                   
            }
        }
        
        return keyList.elements();
    
public java.lang.Objectget(long key)

        int index = ((int) key) & bucketmask;
        for (Entry e = table[index]; e != null; e = e.next) {
            if (e.key == key) {
                return e.value;
            }
        }
        return null;
    
public java.util.Iteratorkeys()

        ArrayList keyList = new ArrayList();
        for (int index=0; index<capacity; index++) {
            for (Entry e = table[index]; e != null; e = e.next) {
                keyList.add(new Long(e.key));
            }
        }
        
        return keyList.iterator();
    
public java.lang.Objectput(long key, java.lang.Object value)

        int index = ((int) key) & bucketmask;
        
        for (Entry e = table[index]; e != null; e = e.next) {
            if (e.key == key) {
                Object oldValue = e.value;
                e.value = value;
                return oldValue;
            }
        }
        
        table[index] = new Entry(key, value, table[index]);
        if (size++ >= threshold) {
            int newCapacity = 2 * capacity;
            Entry[] newTable = new Entry[newCapacity];
            transfer(newTable);
            table = newTable;
            capacity = newCapacity;
            threshold = (int)(newCapacity * loadFactor);
            bucketmask = capacity-1;
        }
        return null;
    
public java.lang.Objectremove(long key)

        int index = ((int) key) & bucketmask;
        Entry prev = table[index];
        Entry e = prev;
        
        while (e != null) {
            Entry next = e.next;
            if (e.key == key) {
                size--;
                if (prev == e)  {
                    table[index] = next;
                } else {
                    prev.next = next;
                }
                return e.value;
            }
            prev = e;
            e = next;
        }
        
        return null;
    
private voidtransfer(com.sun.ejb.containers.util.LongHashMap$Entry[] newTable)
Transfer all entries from current table to newTable.

        Entry[] src = table;
        int newCapacity = newTable.length;
        int bucketmask = newCapacity-1;
        for (int j = 0; j < src.length; j++) {
            Entry e = src[j];
            if (e != null) {
                src[j] = null;
                do {
                    Entry next = e.next;
                    int index = ((int) e.key) & bucketmask;
                    e.next = newTable[index];
                    newTable[index] = e;
                    e = next;
                } while (e != null);
            }
        }
    
public java.util.Iteratorvalues()

        ArrayList keyList = new ArrayList();
        for (int index=0; index<capacity; index++) {
            for (Entry e = table[index]; e != null; e = e.next) {
                keyList.add(e.value);                   
            }
        }
        
        return keyList.iterator();