Methods Summary |
---|
void | addEntry(int hash, byte[] key, java.lang.Object value, int bucketIndex)
table[bucketIndex] = new Entry(hash, key, value, table[bucketIndex]);
if (size++ >= threshold)
resize(2 * table.length);
|
public void | clear()
Entry tab[] = table;
for (int i = 0; i < tab.length; i++)
tab[i] = null;
size = 0;
|
public boolean | containsKey(byte[] key)
int hash = hash(key);
int i = indexFor(hash, table.length);
Entry e = table[i];
while (true) {
if (e == null)
return( false );
if (e.hash == hash && eq(key, e.key))
return( true );
e = e.next;
}
|
void | createEntry(int hash, byte[] key, java.lang.Object value, int bucketIndex)
table[bucketIndex] = new Entry(hash, key, value, table[bucketIndex]);
size++;
|
public org.gudy.azureus2.core3.util.ByteArrayHashMap | duplicate()Bit inefficient at the moment
ByteArrayHashMap res = new ByteArrayHashMap(size,loadFactor);
for (int j = 0; j < table.length; j++) {
Entry e = table[j];
while( e != null ){
res.put( e.key, e.value );
e = e.next;
}
}
return( res );
|
private static final boolean | eq(byte[] x, byte[] y)
if ( x == y ){
return( true );
}
int len = x.length;
if ( len != y.length ){
return( false );
}
for (int i=0;i<len;i++){
if ( x[i] != y[i] ){
return( false );
}
}
return( true );
|
public java.lang.Object | get(byte[] key, int offset, int len)
byte[] k = new byte[len];
System.arraycopy( key, offset, k, 0, len );
return( get( k ));
|
public java.lang.Object | get(byte[] key)
int hash = hash(key);
int i = indexFor(hash, table.length);
Entry e = table[i];
while (true) {
if (e == null)
return e;
if (e.hash == hash && eq(key, e.key))
return e.value;
e = e.next;
}
|
private static final int | hash(byte[] x)
int hash = 0;
int len = x.length;
for (int i = 0; i < len; i++){
hash = 31*hash + x[i];
}
return( hash );
|
private static final int | indexFor(int h, int length)
return h & (length-1);
|
public boolean | isEmpty()
return size == 0;
|
public java.util.List | keys()
List res = new ArrayList();
for (int j = 0; j < table.length; j++) {
Entry e = table[j];
while( e != null ){
res.add( e.key );
e = e.next;
}
}
return( res );
|
public java.lang.Object | put(byte[] key, java.lang.Object value)
int hash = hash(key);
int i = indexFor(hash, table.length);
for (Entry e = table[i]; e != null; e = e.next) {
if (e.hash == hash && eq(key, e.key)) {
Object oldValue = e.value;
e.value = value;
return oldValue;
}
}
addEntry(hash, key, value, i);
return null;
|
public java.lang.Object | remove(byte[] key)
Entry e = removeEntryForKey(key);
return (e == null ? e : e.value);
|
org.gudy.azureus2.core3.util.ByteArrayHashMap$Entry | removeEntryForKey(byte[] key)
int hash = hash(key);
int i = indexFor(hash, table.length);
Entry prev = table[i];
Entry e = prev;
while (e != null) {
Entry next = e.next;
if (e.hash == hash && eq(key, e.key)) {
size--;
if (prev == e)
table[i] = next;
else
prev.next = next;
return e;
}
prev = e;
e = next;
}
return e;
|
void | resize(int newCapacity)
Entry[] oldTable = table;
int oldCapacity = oldTable.length;
if (oldCapacity == MAXIMUM_CAPACITY) {
threshold = Integer.MAX_VALUE;
return;
}
Entry[] newTable = new Entry[newCapacity];
transfer(newTable);
table = newTable;
threshold = (int)(newCapacity * loadFactor);
|
public int | size()
return size;
|
void | transfer(org.gudy.azureus2.core3.util.ByteArrayHashMap$Entry[] newTable)
Entry[] src = table;
int newCapacity = newTable.length;
for (int j = 0; j < src.length; j++) {
Entry e = src[j];
if (e != null) {
src[j] = null;
do {
Entry next = e.next;
int i = indexFor(e.hash, newCapacity);
e.next = newTable[i];
newTable[i] = e;
e = next;
} while (e != null);
}
}
|
public java.util.List | values()
List res = new ArrayList();
for (int j = 0; j < table.length; j++) {
Entry e = table[j];
while( e != null ){
res.add( e.value );
e = e.next;
}
}
return( res );
|