FileDocCategorySizeDatePackage
CacheTable.javaAPI DocJava SE 5 API4062Fri Aug 26 14:54:28 BST 2005com.sun.corba.se.impl.orbutil

CacheTable

public class CacheTable extends Object

Fields Summary
private boolean
noReverseMap
static final int
INITIAL_SIZE
static final int
MAX_SIZE
int
size
int
entryCount
private Entry[]
map
private Entry[]
rmap
private com.sun.corba.se.spi.orb.ORB
orb
private com.sun.corba.se.impl.logging.ORBUtilSystemException
wrapper
Constructors Summary
private CacheTable()


      
public CacheTable(com.sun.corba.se.spi.orb.ORB orb, boolean u)

	//System.out.println("using new cache table");
        this.orb = orb;
        wrapper = ORBUtilSystemException.get(orb, 
            CORBALogDomains.RPC_ENCODING);
	noReverseMap = u;
        size = INITIAL_SIZE;
	entryCount = 0;
	initTables();
    
Methods Summary
public final booleancontainsKey(java.lang.Object key)

	return (getVal(key) != -1);
    
public final booleancontainsOrderedVal(int val)

	return containsVal(val);
    
public final booleancontainsVal(int val)

	return (getKey(val) != null); 
    
public voiddone()

	map = null;
        rmap = null;
    
public final java.lang.ObjectgetKey(int val)

	int index = hash(val);
        for (Entry e = rmap[index]; e != null; e = e.rnext) {
            if (e.val == val)
                return e.key;
        }
        return null;
    
public final intgetVal(java.lang.Object key)

	int index = hash(key);
        for (Entry e = map[index]; e != null; e = e.next) {
            if (e.key == key) 
                return e.val;
        }
        return -1;
    
private voidgrow()

	if (size == MAX_SIZE)
		return;	
	Entry [] oldMap = map;
        int oldSize = size;
	size <<= 1;
	initTables();
	// now rehash the entries into the new table
	for (int i = 0; i < oldSize; i++) {
	    for (Entry e = oldMap[i]; e != null; e = e.next)
	        put_table(e.key, e.val);
	}
    
private inthash(java.lang.Object key)

	return moduloTableSize(System.identityHashCode(key));
    
private inthash(int val)

	return moduloTableSize(val);
    
private voidinitTables()

	map = new Entry[size];
	rmap = noReverseMap ? null : new Entry[size];
    
private intmoduloTableSize(int h)

	// these are the "supplemental hash function" copied from
        // java.util.HashMap, supposed to be "critical"
        h += ~(h << 9);
        h ^=  (h >>> 14);
        h +=  (h << 4);
        h ^=  (h >>> 10);
	return h & (size - 1);
    
public final voidput(java.lang.Object key, int val)

	if (put_table(key, val)) {
	    entryCount++;
	    if (entryCount > size * 3 / 4)
		grow();
	}
    
private booleanput_table(java.lang.Object key, int val)

	int index = hash(key);
	for (Entry e = map[index]; e != null; e = e.next) {
	    if (e.key == key) {
	        if (e.val != val) {
                    throw wrapper.duplicateIndirectionOffset();
		}	
		// if we get here we are trying to put in the same key/val pair
		// this is a no-op, so we just return
		return false;
	    }
        }
	// this means the key is not present in our table
	// then it shouldnt be present in our reverse table either
	Entry newEntry = new Entry(key, val);
	newEntry.next = map[index];
	map[index] = newEntry;
	if (!noReverseMap) {
	    int rindex = hash(val);
	    newEntry.rnext = rmap[rindex];
	    rmap[rindex] = newEntry;
        }
	return true;