[jbosscache-commits] JBoss Cache SVN: r7372 - core/trunk/src/main/java/org/jboss/cache/util.
jbosscache-commits at lists.jboss.org
jbosscache-commits at lists.jboss.org
Mon Jan 5 10:52:48 EST 2009
Author: manik.surtani at jboss.com
Date: 2009-01-05 10:52:48 -0500 (Mon, 05 Jan 2009)
New Revision: 7372
Modified:
core/trunk/src/main/java/org/jboss/cache/util/FastCopyHashMap.java
Log:
Test FCHM
Modified: core/trunk/src/main/java/org/jboss/cache/util/FastCopyHashMap.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/util/FastCopyHashMap.java 2009-01-05 15:51:37 UTC (rev 7371)
+++ core/trunk/src/main/java/org/jboss/cache/util/FastCopyHashMap.java 2009-01-05 15:52:48 UTC (rev 7372)
@@ -68,12 +68,12 @@
/**
* The open-addressed table
*/
- private transient Entry<K, V>[] table;
+ private Entry<K, V>[] table;
/**
* The current number of key-value pairs
*/
- private transient int size;
+ private int size;
/**
* The next resize
@@ -98,13 +98,19 @@
public FastCopyHashMap(int initialCapacity, float loadFactor)
{
if (initialCapacity < 0)
+ {
throw new IllegalArgumentException("Can not have a negative size table!");
+ }
if (initialCapacity > MAXIMUM_CAPACITY)
+ {
initialCapacity = MAXIMUM_CAPACITY;
+ }
if (!(loadFactor > 0F && loadFactor <= 1F))
+ {
throw new IllegalArgumentException("Load factor must be greater than 0 and less than or equal to 1");
+ }
this.loadFactor = loadFactor;
init(initialCapacity, loadFactor);
@@ -207,10 +213,14 @@
{
Entry<K, V> e = table[index];
if (e == null)
+ {
return null;
+ }
if (e.hash == hash && eq(key, e.key))
+ {
return e.value;
+ }
index = nextIndex(index, length);
}
@@ -228,10 +238,14 @@
{
Entry<K, V> e = table[index];
if (e == null)
+ {
return false;
+ }
if (e.hash == hash && eq(key, e.key))
+ {
return true;
+ }
index = nextIndex(index, length);
}
@@ -240,8 +254,12 @@
public boolean containsValue(Object value)
{
for (Entry<K, V> e : table)
+ {
if (e != null && eq(value, e.value))
+ {
return true;
+ }
+ }
return false;
}
@@ -261,7 +279,9 @@
{
Entry<K, V> e = table[index];
if (e == null)
+ {
break;
+ }
if (e.hash == hash && eq(key, e.key))
{
@@ -271,13 +291,17 @@
index = nextIndex(index, length);
if (index == start)
+ {
throw new IllegalStateException("Table is full!");
+ }
}
modCount++;
table[index] = new Entry<K, V>(key, hash, value);
if (++size >= threshold)
+ {
resize(length);
+ }
return null;
}
@@ -290,7 +314,9 @@
// Can't get any bigger
if (newLength > MAXIMUM_CAPACITY || newLength <= from)
+ {
return;
+ }
Entry<K, V>[] newTable = new Entry[newLength];
Entry<K, V>[] old = table;
@@ -298,11 +324,15 @@
for (Entry<K, V> e : old)
{
if (e == null)
+ {
continue;
+ }
int index = index(e.hash, newLength);
while (newTable[index] != null)
+ {
index = nextIndex(index, newLength);
+ }
newTable[index] = e;
}
@@ -315,12 +345,16 @@
{
int size = map.size();
if (size == 0)
+ {
return;
+ }
if (size > threshold)
{
if (size > MAXIMUM_CAPACITY)
+ {
size = MAXIMUM_CAPACITY;
+ }
int length = table.length;
for (; length < size; length <<= 1) ;
@@ -329,7 +363,9 @@
}
for (Map.Entry<? extends K, ? extends V> e : map.entrySet())
+ {
put(e.getKey(), e.getValue());
+ }
}
public V remove(Object key)
@@ -345,7 +381,9 @@
{
Entry<K, V> e = table[index];
if (e == null)
+ {
return null;
+ }
if (e.hash == hash && eq(key, e.key))
{
@@ -358,7 +396,9 @@
index = nextIndex(index, length);
if (index == start)
+ {
return null;
+ }
}
@@ -374,7 +414,9 @@
{
Entry<K, V> e = table[current];
if (e == null)
+ {
return;
+ }
// A Doug Lea variant of Knuth's Section 6.4 Algorithm R.
// This provides a non-recursive method of relocating
@@ -397,7 +439,9 @@
modCount++;
Entry<K, V>[] table = this.table;
for (int i = 0; i < table.length; i++)
+ {
table[i] = null;
+ }
size = 0;
}
@@ -436,7 +480,9 @@
total++;
int target = index(e.hash, table.length);
if (i == target)
+ {
optimal++;
+ }
else
{
int skew = Math.abs(i - target);
@@ -457,7 +503,9 @@
public Set<Map.Entry<K, V>> entrySet()
{
if (entrySet == null)
+ {
entrySet = new EntrySet();
+ }
return entrySet;
}
@@ -465,7 +513,9 @@
public Set<K> keySet()
{
if (keySet == null)
+ {
keySet = new KeySet();
+ }
return keySet;
}
@@ -473,7 +523,9 @@
public Collection<V> values()
{
if (values == null)
+ {
values = new Values();
+ }
return values;
}
@@ -555,7 +607,9 @@
public boolean hasNext()
{
if (hasNext == true)
+ {
return true;
+ }
Entry<K, V> table[] = this.table;
for (int i = next; i < table.length; i++)
@@ -574,10 +628,14 @@
protected Entry<K, V> nextEntry()
{
if (modCount != expectedCount)
+ {
throw new ConcurrentModificationException();
+ }
if (!hasNext && !hasNext())
+ {
throw new NoSuchElementException();
+ }
current = next++;
hasNext = false;
@@ -589,13 +647,17 @@
public void remove()
{
if (modCount != expectedCount)
+ {
throw new ConcurrentModificationException();
+ }
int current = this.current;
int delete = current;
if (current == -1)
+ {
throw new IllegalStateException();
+ }
// Invalidate current (prevents multiple remove)
this.current = -1;
@@ -624,7 +686,9 @@
i = nextIndex(i, length);
Entry<K, V> e = table[i];
if (e == null)
+ {
break;
+ }
int prefer = index(e.hash, length);
if ((i < prefer && (prefer <= delete || delete <= i))
@@ -682,7 +746,9 @@
public V setValue(V value)
{
if (table != FastCopyHashMap.this.table)
+ {
FastCopyHashMap.this.put(getKey(), value);
+ }
return super.setValue(value);
}
@@ -754,7 +820,9 @@
public boolean contains(Object o)
{
if (!(o instanceof Map.Entry))
+ {
return false;
+ }
Map.Entry<?, ?> entry = (Map.Entry<?, ?>) o;
Object value = get(entry.getKey());
@@ -814,17 +882,21 @@
public boolean equals(Object o)
{
if (this == o)
+ {
return true;
+ }
if (!(o instanceof Map.Entry))
+ {
return false;
+ }
Map.Entry<?, ?> e = (Map.Entry<?, ?>) o;
return eq(key, e.getKey()) && eq(value, e.getValue());
}
public int hashCode()
{
- return hash(key) ^
+ return hash(maskNull(key)) ^
(value == null ? 0 : hash(value));
}
More information about the jbosscache-commits
mailing list