[jboss-svn-commits] JBL Code SVN: r6779 - in labs/jbossrules/trunk/drools-core/src/main/java/org/drools: common reteoo util
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Thu Oct 12 21:36:50 EDT 2006
Author: mark.proctor at jboss.com
Date: 2006-10-12 21:36:47 -0400 (Thu, 12 Oct 2006)
New Revision: 6779
Modified:
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/DefaultFactHandle.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ReteTuple.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/AbstractHashTable.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/FactHashTable.java
Log:
JBRULES-498 Optimised HashMap implementations
-Facts are unique, so check instance rather than equality or id cheques.
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/DefaultFactHandle.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/DefaultFactHandle.java 2006-10-13 01:13:34 UTC (rev 6778)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/DefaultFactHandle.java 2006-10-13 01:36:47 UTC (rev 6779)
@@ -33,7 +33,7 @@
/**
*
*/
- private static final long serialVersionUID = 1035305202846367106L;
+ private static final long serialVersionUID = 320L;
/** Handle id. */
private long id;
private long recency;
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ReteTuple.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ReteTuple.java 2006-10-13 01:13:34 UTC (rev 6778)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ReteTuple.java 2006-10-13 01:36:47 UTC (rev 6779)
@@ -156,7 +156,7 @@
return false;
}
- if ( this.handle.getId() != other.handle.getId() ) {
+ if ( this.handle != handle ) {
return false;
}
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/AbstractHashTable.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/AbstractHashTable.java 2006-10-13 01:13:34 UTC (rev 6778)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/AbstractHashTable.java 2006-10-13 01:36:47 UTC (rev 6779)
@@ -296,16 +296,20 @@
public int hashCode;
public Entry next;
+
+// private LinkedList list;
public FactEntry(InternalFactHandle handle) {
this.handle = handle;
this.hashCode = handle.hashCode();
+// this.list = new LinkedList();
}
public FactEntry(InternalFactHandle handle,
int hashCode) {
this.handle = handle;
this.hashCode = hashCode;
+// this.list = new LinkedList();
}
public InternalFactHandle getFactHandle() {
@@ -319,19 +323,20 @@
public void setNext(Entry next) {
this.next = next;
}
+//
+// void add(final LinkedListEntry tupleMatchEntry) {
+// this.list.add( tupleMatchEntry );
+// }
+// void remove(final LinkedListEntry tupleMatchEntry) {
+// this.list.remove( tupleMatchEntry );
+// }
public int hashCode() {
return this.hashCode;
}
public boolean equals(Object object) {
- if ( object == this ) {
- return true;
- }
-
- // assumes we never have null or wrong class
- FactEntry other = (FactEntry) object;
- return this.handle.equals( other.handle );
+ return ( object == this) || (this.handle == ((FactEntry)object).handle);
}
}
}
\ No newline at end of file
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/FactHashTable.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/FactHashTable.java 2006-10-13 01:13:34 UTC (rev 6778)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/FactHashTable.java 2006-10-13 01:36:47 UTC (rev 6779)
@@ -8,8 +8,10 @@
import org.drools.reteoo.ReteTuple;
import org.drools.util.ObjectHashMap.ObjectEntry;
-public class FactHashTable extends AbstractHashTable implements ObjectHashTable {
- private static final long serialVersionUID = 320L;
+public class FactHashTable extends AbstractHashTable
+ implements
+ ObjectHashTable {
+ private static final long serialVersionUID = 320L;
public FactHashTable() {
this( 16,
@@ -20,22 +22,24 @@
float loadFactor) {
super( capacity,
loadFactor );
- }
-
+ }
+
public Iterator iterator(int hashCode) {
- throw new UnsupportedOperationException("FactHashTable does not support the method iterator(int hashCode");
- }
-
+ throw new UnsupportedOperationException( "FactHashTable does not support the method iterator(int hashCode" );
+ }
+
public Iterator iterator(ReteTuple tuple) {
return iterator();
- }
+ }
public boolean add(InternalFactHandle handle) {
- return add( handle, true);
+ return add( handle,
+ true );
}
-
- public boolean add(InternalFactHandle handle, boolean checkExists) {
- int hashCode = this.comparator.hashCodeOf( handle );
+
+ public boolean add(InternalFactHandle handle,
+ boolean checkExists) {
+ int hashCode = this.comparator.hashCodeOf( handle );
int index = indexOf( hashCode,
table.length );
@@ -43,7 +47,7 @@
if ( checkExists ) {
FactEntry current = (FactEntry) this.table[index];
while ( current != null ) {
- if ( hashCode == current.hashCode && handle.getId() == current.handle.getId() ) {
+ if ( hashCode == current.hashCode && handle.getId() == current.handle.getId() ) {
return false;
}
current = (FactHashTable.FactEntry) current.getNext();
@@ -52,7 +56,7 @@
// We aren't checking the key exists, or it didn't find the key
FactEntry entry = new FactEntry( handle,
- hashCode );
+ hashCode );
entry.next = this.table[index];
this.table[index] = entry;
@@ -100,15 +104,15 @@
current = next;
}
return false;
- }
-
+ }
+
public Entry getBucket(Object object) {
int hashCode = this.comparator.hashCodeOf( object );
int index = indexOf( hashCode,
table.length );
- return (ObjectEntry) this.table[index];
- }
+ return (ObjectEntry) this.table[index];
+ }
public int hash(Object key) {
return key.hashCode();
@@ -117,8 +121,8 @@
protected int indexOf(int hashCode,
int dataSize) {
return hashCode & (dataSize - 1);
- }
-
+ }
+
public boolean isIndexed() {
return false;
}
More information about the jboss-svn-commits
mailing list