[jboss-svn-commits] JBL Code SVN: r17755 - in labs/jbossrules/branches/righttuple/drools-core/src: main/java/org/drools/reteoo and 2 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Fri Jan 11 21:11:42 EST 2008


Author: mark.proctor at jboss.com
Date: 2008-01-11 21:11:42 -0500 (Fri, 11 Jan 2008)
New Revision: 17755

Modified:
   labs/jbossrules/branches/righttuple/drools-core/src/main/java/org/drools/common/DefaultFactHandle.java
   labs/jbossrules/branches/righttuple/drools-core/src/main/java/org/drools/common/InternalFactHandle.java
   labs/jbossrules/branches/righttuple/drools-core/src/main/java/org/drools/reteoo/AlphaNode.java
   labs/jbossrules/branches/righttuple/drools-core/src/main/java/org/drools/reteoo/CompositeLeftTupleSinkAdapter.java
   labs/jbossrules/branches/righttuple/drools-core/src/main/java/org/drools/reteoo/CompositeRightTupleSinkAdapter.java
   labs/jbossrules/branches/righttuple/drools-core/src/main/java/org/drools/reteoo/EmptyLeftTupleSinkAdapter.java
   labs/jbossrules/branches/righttuple/drools-core/src/main/java/org/drools/reteoo/EmptyRightTupleSinkAdapter.java
   labs/jbossrules/branches/righttuple/drools-core/src/main/java/org/drools/reteoo/JoinNode.java
   labs/jbossrules/branches/righttuple/drools-core/src/main/java/org/drools/reteoo/LeftInputAdapterNode.java
   labs/jbossrules/branches/righttuple/drools-core/src/main/java/org/drools/reteoo/LeftTuple.java
   labs/jbossrules/branches/righttuple/drools-core/src/main/java/org/drools/reteoo/LeftTupleSinkPropagator.java
   labs/jbossrules/branches/righttuple/drools-core/src/main/java/org/drools/reteoo/MemoryVisitor.java
   labs/jbossrules/branches/righttuple/drools-core/src/main/java/org/drools/reteoo/NotNode.java
   labs/jbossrules/branches/righttuple/drools-core/src/main/java/org/drools/reteoo/ObjectTypeNode.java
   labs/jbossrules/branches/righttuple/drools-core/src/main/java/org/drools/reteoo/Rete.java
   labs/jbossrules/branches/righttuple/drools-core/src/main/java/org/drools/reteoo/ReteooRuleBase.java
   labs/jbossrules/branches/righttuple/drools-core/src/main/java/org/drools/reteoo/RightTuple.java
   labs/jbossrules/branches/righttuple/drools-core/src/main/java/org/drools/reteoo/RightTupleSink.java
   labs/jbossrules/branches/righttuple/drools-core/src/main/java/org/drools/reteoo/RightTupletSinkPropagator.java
   labs/jbossrules/branches/righttuple/drools-core/src/main/java/org/drools/reteoo/SingleLeftTupleSinkAdapter.java
   labs/jbossrules/branches/righttuple/drools-core/src/main/java/org/drools/reteoo/SingleRightTupletSinkAdapter.java
   labs/jbossrules/branches/righttuple/drools-core/src/main/java/org/drools/util/FactHandleIndexHashTable.java
   labs/jbossrules/branches/righttuple/drools-core/src/main/java/org/drools/util/ObjectHashMap.java
   labs/jbossrules/branches/righttuple/drools-core/src/main/java/org/drools/util/ObjectHashSet.java
   labs/jbossrules/branches/righttuple/drools-core/src/main/java/org/drools/util/TupleIndexHashTable.java
   labs/jbossrules/branches/righttuple/drools-core/src/test/java/org/drools/examples/manners/ReteooMannersTest.java
Log:
-waltz and manners are now running with reasonable speed.

Modified: labs/jbossrules/branches/righttuple/drools-core/src/main/java/org/drools/common/DefaultFactHandle.java
===================================================================
--- labs/jbossrules/branches/righttuple/drools-core/src/main/java/org/drools/common/DefaultFactHandle.java	2008-01-12 00:59:23 UTC (rev 17754)
+++ labs/jbossrules/branches/righttuple/drools-core/src/main/java/org/drools/common/DefaultFactHandle.java	2008-01-12 02:11:42 UTC (rev 17755)
@@ -17,6 +17,7 @@
  */
 
 import org.drools.FactHandle;
+import org.drools.reteoo.LeftTuple;
 import org.drools.reteoo.RightTuple;
 
 /**
@@ -43,6 +44,7 @@
     private int               objectHashCode;
     private boolean           shadowFact;
     private RightTuple        rightTuple;
+    private LeftTuple         leftTuple;
 
     // ----------------------------------------------------------------------
     // Constructors
@@ -172,6 +174,14 @@
     public void setRightTuple(RightTuple rightTuple) {
         this.rightTuple = rightTuple;
     }
+    
+    public void setLeftTuple(LeftTuple leftTuple) {
+        this.leftTuple = leftTuple;
+    }
+    
+    public LeftTuple getLeftTuple(){
+        return this.leftTuple;
+    }
 
     /**
      * Always returns false, since the DefaultFactHandle is

Modified: labs/jbossrules/branches/righttuple/drools-core/src/main/java/org/drools/common/InternalFactHandle.java
===================================================================
--- labs/jbossrules/branches/righttuple/drools-core/src/main/java/org/drools/common/InternalFactHandle.java	2008-01-12 00:59:23 UTC (rev 17754)
+++ labs/jbossrules/branches/righttuple/drools-core/src/main/java/org/drools/common/InternalFactHandle.java	2008-01-12 02:11:42 UTC (rev 17755)
@@ -17,6 +17,7 @@
  */
 
 import org.drools.FactHandle;
+import org.drools.reteoo.LeftTuple;
 import org.drools.reteoo.RightTuple;
 
 public interface InternalFactHandle
@@ -48,6 +49,10 @@
 
     public void setRightTuple(RightTuple rightTuple);    
     
+    public void setLeftTuple(LeftTuple leftTuple);
+    
+    public LeftTuple getLeftTuple();
+    
     /**
      * Returns true if this FactHandle represents
      * and Event or false if this FactHandle represents

Modified: labs/jbossrules/branches/righttuple/drools-core/src/main/java/org/drools/reteoo/AlphaNode.java
===================================================================
--- labs/jbossrules/branches/righttuple/drools-core/src/main/java/org/drools/reteoo/AlphaNode.java	2008-01-12 00:59:23 UTC (rev 17754)
+++ labs/jbossrules/branches/righttuple/drools-core/src/main/java/org/drools/reteoo/AlphaNode.java	2008-01-12 02:11:42 UTC (rev 17755)
@@ -55,10 +55,6 @@
     private RightTupleSinkNode             previousRightTupleSinkNode;
     private RightTupleSinkNode             nextRightTupleNode;
 
-    private boolean                        rightTupleMemoryEnabled;
-
-    private boolean                        rightTupleMemoryAllowed;
-
     /**
      * Construct an <code>AlphaNode</code> with a unique id using the provided
      * <code>FieldConstraint</code> and the given <code>ObjectSource</code>.
@@ -79,12 +75,6 @@
                objectSource,
                context.getRuleBase().getConfiguration().getAlphaNodeHashingThreshold() );
         this.constraint = constraint;
-        this.rightTupleMemoryAllowed = context.isAlphaMemoryAllowed();
-        if ( this.rightTupleMemoryAllowed ) {
-            this.rightTupleMemoryEnabled = context.getRuleBase().getConfiguration().isAlphaMemory();
-        } else {
-            this.rightTupleMemoryEnabled = false;
-        }
     }
 
     /**
@@ -108,11 +98,6 @@
     public void attach(final InternalWorkingMemory[] workingMemories) {
         attach();
 
-        // we are attaching this node with existing working memories
-        // indicating that we are in a dynamic environment, that might benefit from alpha node memory, if allowed
-        if ( this.rightTupleMemoryAllowed ) {
-            setRightTupleMemoryEnabled( true );
-        }
         for ( int i = 0, length = workingMemories.length; i < length; i++ ) {
             final InternalWorkingMemory workingMemory = workingMemories[i];
             final PropagationContext propagationContext = new PropagationContextImpl( workingMemory.getNextPropagationIdCounter(),
@@ -125,60 +110,26 @@
         }
     }
 
-    public void assertRightTuple(final RightTuple rightTuple,
+    public void assertRightTuple(final InternalFactHandle handle,
                                  final PropagationContext context,
                                  final InternalWorkingMemory workingMemory) throws FactException {
-        if ( this.constraint.isAllowed( rightTuple.getHandle(),
+        if ( this.constraint.isAllowed( handle,
                                         workingMemory ) ) {
-            if ( isRightTupleMemoryEnabled() ) {
-                final FactHashTable memory = (FactHashTable) workingMemory.getNodeMemory( this );
-                memory.add( rightTuple );
-            }
-
-            this.sink.propagateAssertRightTuple( rightTuple,
+            this.sink.propagateAssertRightTuple( handle,
                                                  context,
                                                  workingMemory );
         }
     }
 
-    public void retractRightTuple(final RightTuple rightTuple,
-                                  final PropagationContext context,
-                                  final InternalWorkingMemory workingMemory) {        
-        if ( isRightTupleMemoryEnabled() ) {
-            final FactHashTable memory = (FactHashTable) workingMemory.getNodeMemory( this );
-            memory.remove( rightTuple );
-        }
-                
-        
-        if ( rightTuple.getAlphaChildren() != null ) {
-            this.sink.propagateRetractRightTuple( rightTuple,
-                                                  context,
-                                                  workingMemory,
-                                                  true );
-        }
-    }
-
     public void updateSink(final RightTupleSink sink,
                            final PropagationContext context,
                            final InternalWorkingMemory workingMemory) {
-        FactHashTable memory = null;
-
-        if ( !isRightTupleMemoryEnabled() ) {
-            // get the objects from the parent
-            RightTupleSinkUpdateAdapter adapter = new RightTupleSinkUpdateAdapter( sink,
-                                                                                   this.constraint );
-            this.objectSource.updateSink( adapter,
-                                          context,
-                                          workingMemory );
-        } else {
-            // if already has memory, just iterate and propagate
-            memory = (FactHashTable) workingMemory.getNodeMemory( this );
-            for ( RightTuple rightTuple = (RightTuple)  memory.getFirst( null ); rightTuple != null; rightTuple = (RightTuple) rightTuple.getNext() ) {
-                sink.assertRightTuple( rightTuple,
-                                       context,
-                                       workingMemory );
-            }
-        }
+        // get the objects from the parent
+        RightTupleSinkUpdateAdapter adapter = new RightTupleSinkUpdateAdapter( sink,
+                                                                               this.constraint );
+        this.objectSource.updateSink( adapter,
+                                      context,
+                                      workingMemory );
     }
 
     public void remove(final BaseNode node,
@@ -197,18 +148,6 @@
                                   workingMemories );
     }
 
-    public void setRightTupleMemoryAllowed(boolean objectMemoryAllowed) {
-        this.rightTupleMemoryAllowed = objectMemoryAllowed;
-    }
-
-    public boolean isRightTupleMemoryEnabled() {
-        return this.rightTupleMemoryEnabled;
-    }
-
-    public void setRightTupleMemoryEnabled(boolean objectMemoryEnabled) {
-        this.rightTupleMemoryEnabled = objectMemoryEnabled;
-    }
-
     /**
      * Creates a HashSet for the AlphaNode's memory.
      */
@@ -286,6 +225,12 @@
         this.previousRightTupleSinkNode = previous;
     }
 
+    public void retractRightTuple(RightTuple rightTuple,
+                                  PropagationContext context,
+                                  InternalWorkingMemory workingMemory) {
+        throw new UnsupportedOperationException( "AlphaNode.retractRightTuple is not supported." );
+    }
+
     /**
      * Used with the updateSink method, so that the parent ObjectSource
      * can  update the  TupleSink
@@ -304,35 +249,27 @@
             this.constraint = constraint;
         }
 
-        public void assertRightTuple(final RightTuple rightTuple,
+        public void assertRightTuple(final InternalFactHandle handle,
                                      final PropagationContext context,
                                      final InternalWorkingMemory workingMemory) {
-            if ( this.constraint.isAllowed( rightTuple.getHandle(),
+            if ( this.constraint.isAllowed( handle,
                                             workingMemory ) ) {
-                this.sink.assertRightTuple( rightTuple,
+                this.sink.assertRightTuple( handle,
                                             context,
                                             workingMemory );
             }
         }
 
-        public void modifyObject(final InternalFactHandle handle,
-                                 final PropagationContext context,
-                                 final InternalWorkingMemory workingMemory) {
-            throw new UnsupportedOperationException( "ObjectSinkUpdateAdapter onlys supports assertObject method calls" );
-        }
+        //        public void modifyObject(final InternalFactHandle handle,
+        //                                 final PropagationContext context,
+        //                                 final InternalWorkingMemory workingMemory) {
+        //            throw new UnsupportedOperationException( "ObjectSinkUpdateAdapter onlys supports assertObject method calls" );
+        //        }
 
         public void retractRightTuple(final RightTuple rightTuple,
                                       final PropagationContext context,
                                       final InternalWorkingMemory workingMemory) {
-            throw new UnsupportedOperationException( "ObjectSinkUpdateAdapter onlys supports assertObject method calls" );
+            throw new UnsupportedOperationException( "RightTupleSinkUpdateAdapter.retractRightTuple is not supported." );
         }
-
-        public boolean isRightTupleMemoryEnabled() {
-            throw new UnsupportedOperationException( "ObjectSinkUpdateAdapter have no Object memory" );
-        }
-
-        public void setRightTupleMemoryEnabled(boolean objectMemoryEnabled) {
-            throw new UnsupportedOperationException( "ObjectSinkUpdateAdapter have no Object memory" );
-        }
     }
 }

Modified: labs/jbossrules/branches/righttuple/drools-core/src/main/java/org/drools/reteoo/CompositeLeftTupleSinkAdapter.java
===================================================================
--- labs/jbossrules/branches/righttuple/drools-core/src/main/java/org/drools/reteoo/CompositeLeftTupleSinkAdapter.java	2008-01-12 00:59:23 UTC (rev 17754)
+++ labs/jbossrules/branches/righttuple/drools-core/src/main/java/org/drools/reteoo/CompositeLeftTupleSinkAdapter.java	2008-01-12 02:11:42 UTC (rev 17755)
@@ -1,5 +1,6 @@
 package org.drools.reteoo;
 
+import org.drools.common.InternalFactHandle;
 import org.drools.common.InternalWorkingMemory;
 import org.drools.spi.PropagationContext;
 
@@ -79,31 +80,17 @@
         rightTuple.setBetaChildren( null );
     }
 
-    public void createAndPropagateAssertTuple(final RightTuple rightTuple,
+    public void createAndPropagateAssertTuple(final InternalFactHandle factHandle,
                                               final PropagationContext context,
                                               final InternalWorkingMemory workingMemory) {
         for ( LeftTupleSinkNode sink = this.sinks.getFirst(); sink != null; sink = sink.getNextLeftTupleSinkNode() ) {
-            sink.assertTuple( new LeftTuple( rightTuple,
+            sink.assertTuple( new LeftTuple( factHandle,
                                              sink ),
                               context,
                               workingMemory );
         }
     }
 
-    public void createAndPropagateRetractTuple(final RightTuple rightTuple,
-                                               final PropagationContext context,
-                                               final InternalWorkingMemory workingMemory) {
-        LeftTuple child = rightTuple.getBetaChildren();
-        while ( child != null ) {
-            //LeftTuple temp = child.getRightParentNext();
-            //child.unlinkFromParents();
-            child.getSink().retractTuple( child, context, workingMemory );
-            child = child.getRightParentNext();
-            //child = temp;
-        }
-        rightTuple.setBetaChildren( null );
-    }
-
     public LeftTupleSink[] getSinks() {
         final LeftTupleSink[] sinkArray = new LeftTupleSink[this.sinks.size()];
 

Modified: labs/jbossrules/branches/righttuple/drools-core/src/main/java/org/drools/reteoo/CompositeRightTupleSinkAdapter.java
===================================================================
--- labs/jbossrules/branches/righttuple/drools-core/src/main/java/org/drools/reteoo/CompositeRightTupleSinkAdapter.java	2008-01-12 00:59:23 UTC (rev 17754)
+++ labs/jbossrules/branches/righttuple/drools-core/src/main/java/org/drools/reteoo/CompositeRightTupleSinkAdapter.java	2008-01-12 02:11:42 UTC (rev 17755)
@@ -6,6 +6,7 @@
 
 import org.drools.base.ValueType;
 import org.drools.base.evaluators.Operator;
+import org.drools.common.InternalFactHandle;
 import org.drools.common.InternalWorkingMemory;
 import org.drools.rule.LiteralConstraint;
 import org.drools.spi.AlphaNodeFieldConstraint;
@@ -275,10 +276,10 @@
         return null;
     }
 
-    public void propagateAssertRightTuple(final RightTuple rightTuple,
+    public void propagateAssertRightTuple(final InternalFactHandle factHandle,
                                           final PropagationContext context,
                                           final InternalWorkingMemory workingMemory) {
-        final Object object = rightTuple.getHandle().getObject();
+        final Object object = factHandle.getObject();
 
         // Iterates t he FieldIndex collection, which tells you if particularly field is hashed or not
         // if the field is hashed then it builds the hashkey to return the correct sink for the current objects slot's
@@ -298,8 +299,7 @@
                 final RightTupleSink sink = (RightTupleSink) this.hashedSinkMap.get( this.hashKey );
                 if ( sink != null ) {
                     // The sink exists so propagate
-                    sink.assertRightTuple( new RightTuple( rightTuple, 
-                                                           sink ),
+                    sink.assertRightTuple( factHandle,
                                            context,
                                            workingMemory );
                 }
@@ -309,8 +309,7 @@
         // propagate unhashed
         if ( this.hashableSinks != null ) {
             for ( RightTupleSinkNode sink = this.hashableSinks.getFirst(); sink != null; sink = sink.getNextRightTupleSinkNode() ) {
-                sink.assertRightTuple( new RightTuple( rightTuple, 
-                                                       sink ),
+                sink.assertRightTuple( factHandle,
                                        context,
                                        workingMemory );
             }
@@ -319,8 +318,7 @@
         if ( this.otherSinks != null ) {
             // propagate others
             for ( RightTupleSinkNode sink = this.otherSinks.getFirst(); sink != null; sink = sink.getNextRightTupleSinkNode() ) {
-                sink.assertRightTuple( new RightTuple( rightTuple, 
-                                                       sink ),
+                sink.assertRightTuple( factHandle,
                                        context,
                                        workingMemory );
             }
@@ -328,16 +326,6 @@
 
     }
 
-    public void propagateRetractRightTuple(final RightTuple rightTuple,
-                                           final PropagationContext context,
-                                           final InternalWorkingMemory workingMemory,
-                                           final boolean useHash) {
-        for( RightTuple childRightTuple = rightTuple.getAlphaChildren(); childRightTuple != null; childRightTuple = childRightTuple.getParentNext() ) {
-            childRightTuple.getRightTupleSink().retractRightTuple( childRightTuple, context, workingMemory );
-        }
-        rightTuple.setAlphaChildren( null );
-    }
-
     public RightTupleSink[] getSinks() {
         final List list = new ArrayList();
 

Modified: labs/jbossrules/branches/righttuple/drools-core/src/main/java/org/drools/reteoo/EmptyLeftTupleSinkAdapter.java
===================================================================
--- labs/jbossrules/branches/righttuple/drools-core/src/main/java/org/drools/reteoo/EmptyLeftTupleSinkAdapter.java	2008-01-12 00:59:23 UTC (rev 17754)
+++ labs/jbossrules/branches/righttuple/drools-core/src/main/java/org/drools/reteoo/EmptyLeftTupleSinkAdapter.java	2008-01-12 02:11:42 UTC (rev 17755)
@@ -1,5 +1,6 @@
 package org.drools.reteoo;
 
+import org.drools.common.InternalFactHandle;
 import org.drools.common.InternalWorkingMemory;
 import org.drools.spi.PropagationContext;
 
@@ -32,16 +33,11 @@
                                       final InternalWorkingMemory workingMemory) {
     }
 
-    public void createAndPropagateAssertTuple(final RightTuple rightTuple,
+    public void createAndPropagateAssertTuple(final InternalFactHandle factHandle,
                                               final PropagationContext context,
                                               final InternalWorkingMemory workingMemory) {
     }
 
-    public void createAndPropagateRetractTuple(final RightTuple rightTuple,
-                                               final PropagationContext context,
-                                               final InternalWorkingMemory workingMemory) {
-    }
-
     public LeftTupleSink[] getSinks() {
         return new LeftTupleSink[]{};
     }

Modified: labs/jbossrules/branches/righttuple/drools-core/src/main/java/org/drools/reteoo/EmptyRightTupleSinkAdapter.java
===================================================================
--- labs/jbossrules/branches/righttuple/drools-core/src/main/java/org/drools/reteoo/EmptyRightTupleSinkAdapter.java	2008-01-12 00:59:23 UTC (rev 17754)
+++ labs/jbossrules/branches/righttuple/drools-core/src/main/java/org/drools/reteoo/EmptyRightTupleSinkAdapter.java	2008-01-12 02:11:42 UTC (rev 17755)
@@ -1,5 +1,6 @@
 package org.drools.reteoo;
 
+import org.drools.common.InternalFactHandle;
 import org.drools.common.InternalWorkingMemory;
 import org.drools.spi.PropagationContext;
 
@@ -7,12 +8,12 @@
     implements
     RightTupletSinkPropagator {
 
-    private static final long serialVersionUID = -631743913176779720L;
+    private static final long                       serialVersionUID = -631743913176779720L;
 
-    private static final EmptyRightTupleSinkAdapter instance = new EmptyRightTupleSinkAdapter();
-    
-    private static final RightTupleSink[] SINK_LIST = new RightTupleSink[0];
+    private static final EmptyRightTupleSinkAdapter instance         = new EmptyRightTupleSinkAdapter();
 
+    private static final RightTupleSink[]           SINK_LIST        = new RightTupleSink[0];
+
     public static EmptyRightTupleSinkAdapter getInstance() {
         return instance;
     }
@@ -20,22 +21,16 @@
     private EmptyRightTupleSinkAdapter() {
     }
 
-    public void propagateAssertRightTuple(final RightTuple rightTuple,
-                                      final PropagationContext context,
-                                      final InternalWorkingMemory workingMemory) {
+    public void propagateAssertRightTuple(final InternalFactHandle handle,
+                                          final PropagationContext context,
+                                          final InternalWorkingMemory workingMemory) {
 
     }
 
-    public void propagateRetractRightTuple(final RightTuple rightTuple,
-                                       final PropagationContext context,
-                                       final InternalWorkingMemory workingMemory,
-                                       final boolean useHash) {
-    }
-
     public RightTupleSink[] getSinks() {
         return SINK_LIST;
     }
-    
+
     public int size() {
         return 0;
     }

Modified: labs/jbossrules/branches/righttuple/drools-core/src/main/java/org/drools/reteoo/JoinNode.java
===================================================================
--- labs/jbossrules/branches/righttuple/drools-core/src/main/java/org/drools/reteoo/JoinNode.java	2008-01-12 00:59:23 UTC (rev 17754)
+++ labs/jbossrules/branches/righttuple/drools-core/src/main/java/org/drools/reteoo/JoinNode.java	2008-01-12 02:11:42 UTC (rev 17755)
@@ -52,7 +52,7 @@
     // ------------------------------------------------------------
     // Instance methods
     // ------------------------------------------------------------
-    
+
     /**
      * 
      */
@@ -92,14 +92,14 @@
                             final PropagationContext context,
                             final InternalWorkingMemory workingMemory) {
         final BetaMemory memory = (BetaMemory) workingMemory.getNodeMemory( this );
-        
+
         if ( this.tupleMemoryEnabled ) {
             memory.getLeftTupleMemory().add( leftTuple );
         }
 
         this.constraints.updateFromTuple( workingMemory,
                                           leftTuple );
-        
+
         for ( RightTuple rightTuple = memory.getRightTupleMemory().getFirst( leftTuple ); rightTuple != null; rightTuple = (RightTuple) rightTuple.getNext() ) {
             if ( this.constraints.isAllowedCachedLeft( rightTuple.getHandle() ) ) {
                 this.sink.propagateAssertTuple( leftTuple,
@@ -108,7 +108,7 @@
                                                 workingMemory );
             }
         }
-        
+
         this.constraints.resetTuple();
     }
 
@@ -130,15 +130,18 @@
      * @param workingMemory
      *            The working memory seesion.
      */
-    public void assertRightTuple(final RightTuple rightTuple,
-                             final PropagationContext context,
-                             final InternalWorkingMemory workingMemory) {
+    public void assertRightTuple(final InternalFactHandle factHandle,
+                                 final PropagationContext context,
+                                 final InternalWorkingMemory workingMemory) {
         final BetaMemory memory = (BetaMemory) workingMemory.getNodeMemory( this );
 
+        RightTuple rightTuple = new RightTuple( factHandle,
+                                                this );
+
         //new RightTuple()
-        
+
         memory.getRightTupleMemory().add( rightTuple );
-        if ( ! this.tupleMemoryEnabled ) {
+        if ( !this.tupleMemoryEnabled ) {
             // do nothing here, as we know there are no left tuples at this stage in sequential mode.
             return;
         }
@@ -168,12 +171,15 @@
      *            The working memory seesion.
      */
     public void retractRightTuple(final RightTuple rightTuple,
-                              final PropagationContext context,
-                              final InternalWorkingMemory workingMemory) {        
+                                  final PropagationContext context,
+                                  final InternalWorkingMemory workingMemory) {
         final BetaMemory memory = (BetaMemory) workingMemory.getNodeMemory( this );
         memory.getRightTupleMemory().remove( rightTuple );
+        
         if ( rightTuple.getBetaChildren() != null ) {
-            this.sink.propagateRetractRightTuple( rightTuple, context, workingMemory );
+            this.sink.propagateRetractRightTuple( rightTuple,
+                                                  context,
+                                                  workingMemory );
         }
     }
 
@@ -195,20 +201,22 @@
         final BetaMemory memory = (BetaMemory) workingMemory.getNodeMemory( this );
         memory.getLeftTupleMemory().remove( leftTuple );
         if ( leftTuple.getBetaChildren() != null ) {
-            this.sink.propagateRetractLeftTuple( leftTuple, context, workingMemory );
+            this.sink.propagateRetractLeftTuple( leftTuple,
+                                                 context,
+                                                 workingMemory );
         }
-        
-//        final Iterator it = memory.getRightTupleMemory().iterator( leftTuple );
-//        this.constraints.updateFromTuple( workingMemory,
-//                                          leftTuple );
-//        for ( RightTuple rightTuple = (RightTuple) it.next(); rightTuple != null; rightTuple = (RightTuple) it.next() ) {
-//            if ( this.constraints.isAllowedCachedLeft( rightTuple.getHandle() ) ) {
-//                this.sink.propagateRetractTuple( leftTuple,
-//                                                 rightTuple,
-//                                                 context,
-//                                                 workingMemory );
-//            }
-//        }
+
+        //        final Iterator it = memory.getRightTupleMemory().iterator( leftTuple );
+        //        this.constraints.updateFromTuple( workingMemory,
+        //                                          leftTuple );
+        //        for ( RightTuple rightTuple = (RightTuple) it.next(); rightTuple != null; rightTuple = (RightTuple) it.next() ) {
+        //            if ( this.constraints.isAllowedCachedLeft( rightTuple.getHandle() ) ) {
+        //                this.sink.propagateRetractTuple( leftTuple,
+        //                                                 rightTuple,
+        //                                                 context,
+        //                                                 workingMemory );
+        //            }
+        //        }
     }
 
     /* (non-Javadoc)
@@ -235,7 +243,7 @@
             }
         }
         this.constraints.updateFromTuple( workingMemory,
-                                          null );        
+                                          null );
     }
 
     public String toString() {

Modified: labs/jbossrules/branches/righttuple/drools-core/src/main/java/org/drools/reteoo/LeftInputAdapterNode.java
===================================================================
--- labs/jbossrules/branches/righttuple/drools-core/src/main/java/org/drools/reteoo/LeftInputAdapterNode.java	2008-01-12 00:59:23 UTC (rev 17754)
+++ labs/jbossrules/branches/righttuple/drools-core/src/main/java/org/drools/reteoo/LeftInputAdapterNode.java	2008-01-12 02:11:42 UTC (rev 17755)
@@ -51,8 +51,6 @@
     private RightTupleSinkNode     previousRightTupleSinkNode;
     private RightTupleSinkNode     nextRightTupleSinkNode;
 
-    private boolean                rightTupleMemoryEnabled;
-
     /**
      * Constructus a LeftInputAdapterNode with a unique id that receives <code>FactHandle</code> from a 
      * parent <code>ObjectSource</code> and adds it to a given pattern in the resulting Tuples.
@@ -70,8 +68,6 @@
                                 final BuildContext context) {
         super( id );
         this.objectSource = source;
-        //this.constraints = constraints;
-        setRightTupleMemoryEnabled( false );
     }
 
     /* (non-Javadoc)
@@ -107,65 +103,32 @@
      * @param workingMemory
      *            the <code>WorkingMemory</code> session.
      */
-    public void assertRightTuple(final RightTuple rightTuple,
+    public void assertRightTuple(final InternalFactHandle factHandle,
                                  final PropagationContext context,
                                  final InternalWorkingMemory workingMemory) {
 
         if ( !workingMemory.isSequential() ) {
-            this.sink.createAndPropagateAssertTuple( rightTuple,
+            this.sink.createAndPropagateAssertTuple( factHandle,
                                                      context,
                                                      workingMemory );
-
-            if ( this.rightTupleMemoryEnabled ) {
-                final FactHashTable memory = (FactHashTable) workingMemory.getNodeMemory( this );
-                memory.add( rightTuple );
-            }
         } else {
             //workingMemory.addLIANodePropagation( new LIANodePropagation(this, rightTuple, context) );
         }
     }
-
-    /**
-     * Retract an existing <code>FactHandleImpl</code> by placing it in a new <code>ReteTuple</code> before 
-     * proagating to the <code>TupleSinks</code>
-     * 
-     * @param rightTuple
-     *            The <code>FactHandle/code> to retract.
-     * @param context
-     *             The <code>PropagationContext</code> of the <code>WorkingMemory<code> action.           
-     * @param workingMemory
-     *            the <code>WorkingMemory</code> session.
-     */
+    
     public void retractRightTuple(final RightTuple rightTuple,
                                   final PropagationContext context,
                                   final InternalWorkingMemory workingMemory) {
-        if ( this.rightTupleMemoryEnabled ) {
-            final FactHashTable memory = (FactHashTable) workingMemory.getNodeMemory( this );
-            memory.remove( rightTuple );
-        }
+        throw new UnsupportedOperationException( "LeftInputAdapterNode.retractRightTuple is not supported." );
+    }     
 
-        this.sink.createAndPropagateRetractTuple( rightTuple,
-                                                  context,
-                                                  workingMemory );
-    }
-
     public void updateSink(final LeftTupleSink sink,
                            final PropagationContext context,
                            final InternalWorkingMemory workingMemory) {
-        if ( this.rightTupleMemoryEnabled ) {
-            // We have memory so iterate over all entries
-            final FactHashTable memory = (FactHashTable) workingMemory.getNodeMemory( this );
-            for ( RightTuple rightTuple = (RightTuple) memory.getFirst( null ); rightTuple != null; rightTuple = (RightTuple) rightTuple.getNext() ) {
-                sink.assertTuple( new LeftTuple( rightTuple, sink ),
-                                  context,
-                                  workingMemory );
-            }
-        } else {
-            final RightTupleSinkAdapter adapter = new RightTupleSinkAdapter( sink );
-            this.objectSource.updateSink( adapter,
-                                          context,
-                                          workingMemory );
-        }
+        final RightTupleSinkAdapter adapter = new RightTupleSinkAdapter( sink );
+        this.objectSource.updateSink( adapter,
+                                      context,
+                                      workingMemory );
     }
 
     public void remove(final BaseNode node,
@@ -183,14 +146,6 @@
                                   workingMemories );
     }
 
-    public boolean isRightTupleMemoryEnabled() {
-        return this.rightTupleMemoryEnabled;
-    }
-
-    public void setRightTupleMemoryEnabled(boolean objectMemoryEnabled) {
-        this.rightTupleMemoryEnabled = objectMemoryEnabled;
-    }
-
     /**
      * Returns the next node
      * @return
@@ -264,11 +219,10 @@
             this.sink = sink;
         }
 
-        public void assertRightTuple(final RightTuple rightTuple,
+        public void assertRightTuple(final InternalFactHandle factHandle,
                                      final PropagationContext context,
                                      final InternalWorkingMemory workingMemory) {
-            final LeftTuple tuple = new LeftTuple( rightTuple, this.sink );
-            this.sink.assertTuple( tuple,
+            this.sink.assertTuple( new LeftTuple( factHandle, this.sink ),
                                    context,
                                    workingMemory );
         }

Modified: labs/jbossrules/branches/righttuple/drools-core/src/main/java/org/drools/reteoo/LeftTuple.java
===================================================================
--- labs/jbossrules/branches/righttuple/drools-core/src/main/java/org/drools/reteoo/LeftTuple.java	2008-01-12 00:59:23 UTC (rev 17754)
+++ labs/jbossrules/branches/righttuple/drools-core/src/main/java/org/drools/reteoo/LeftTuple.java	2008-01-12 02:11:42 UTC (rev 17755)
@@ -9,6 +9,8 @@
 import org.drools.spi.Activation;
 import org.drools.spi.Tuple;
 import org.drools.util.Entry;
+import org.drools.util.FactHashTable;
+import org.drools.util.TupleHashTable;
 
 public class LeftTuple
     implements
@@ -44,6 +46,7 @@
     private LeftTuple                rightParentNext;
 
     // node memory
+    private TupleHashTable           memory;
     private Entry                    next;
     private Entry                    previous;
 
@@ -55,10 +58,10 @@
     // ------------------------------------------------------------
     // Constructors
     // ------------------------------------------------------------
-    public LeftTuple(final RightTuple rightTuple,
+    public LeftTuple(final InternalFactHandle factHandle,
                      LeftTupleSink sink) {
-        this.handle = rightTuple.getHandle();
-        this.recency = this.handle.getRecency();
+        this.handle = factHandle;
+        this.recency = factHandle.getRecency();
 
         int h = handle.hashCode();
         h += ~(h << 9);
@@ -67,13 +70,15 @@
         h ^= (h >>> 10);
         this.hashCode = h;
 
-        this.rightParent = rightTuple;
-        this.rightParentNext = this.rightParent.getBetaChildren();
-        if ( this.rightParentNext != null ) {
-            this.rightParentNext.rightParentPrevious = this;
-        }
-        this.rightParent.setBetaChildren( this );
         this.sink = sink;
+        
+        LeftTuple currentFirst = handle.getLeftTuple();
+        if ( currentFirst != null ) {
+            currentFirst.leftParentPrevious =  this;
+            this.leftParentNext = currentFirst;
+        }
+        
+        handle.setLeftTuple( this );         
     }
 
     public LeftTuple(final LeftTuple leftTuple,
@@ -117,52 +122,7 @@
         this.leftParent.children = this;
         this.sink = sink;
     }
-
-//    public void unlinkFromParents() {
-//        LeftTuple previous = (LeftTuple) this.rightParentPrevious;
-//        LeftTuple next = (LeftTuple) this.rightParentNext;
-//
-//        if ( previous != null && next != null ) {
-//            //remove  from middle
-//            this.rightParentPrevious.rightParentNext = this.rightParentNext;
-//            this.rightParentNext.rightParentPrevious = this.rightParentPrevious;
-//        } else if ( next != null ) {
-//            //remove from first
-//            this.rightParent.setBetaChildren( this.rightParentNext );
-//            this.rightParentNext.rightParentPrevious = null;
-//        } else if ( previous != null ) {
-//            //remove from end
-//            this.rightParentPrevious.rightParentNext = null;
-//        } else if ( this.rightParent != null ){
-//            this.rightParent.setBetaChildren( null );
-//        }    
-//
-//        if ( previous != null && next != null ) {
-//            //remove  from middle
-//            this.leftParentPrevious.leftParentNext = this.leftParentNext;
-//            this.leftParentNext.leftParentPrevious = this.leftParentPrevious;
-//        } else if ( next != null ) {
-//            //remove from first
-//            this.leftParent.children = this.leftParentNext;
-//            this.leftParentNext.leftParentPrevious = null;
-//        } else if ( previous != null ) {
-//            //remove from end
-//            this.leftParentPrevious.leftParentNext = null;
-//        } else {
-//            this.leftParent.children = null;
-//        }   
-//        
-//        this.parent  = null;
-//        
-//        this.leftParent  = null;
-//        this.leftParentPrevious = null;        
-//        this.leftParentNext =  null;
-//        
-//        this.rightParent  = null;
-//        this.rightParentPrevious = null;
-//        this.rightParentPrevious = null;
-//    }
-//    
+    
     public void unlinkFromLeftParent() {
         LeftTuple previous = (LeftTuple) this.leftParentPrevious;
         LeftTuple next = (LeftTuple) this.leftParentNext;
@@ -181,21 +141,21 @@
         } else {
             this.leftParent.children = null;
         }
-        
+
         //this.parent  = null;
-        
-        this.leftParent  = null;
-        this.leftParentPrevious = null;        
-        this.leftParentNext =  null;
-        
+
+        this.leftParent = null;
+        this.leftParentPrevious = null;
+        this.leftParentNext = null;
+//
         this.blocker = null;
-        
-        this.rightParent  = null;
+//
+        this.rightParent = null;
         this.rightParentPrevious = null;
-        this.rightParentNext = null;        
-    }           
-    
-    public void unlinkFromRightParent() {               
+        this.rightParentNext = null;
+    }
+
+    public void unlinkFromRightParent() {
         LeftTuple previous = (LeftTuple) this.rightParentPrevious;
         LeftTuple next = (LeftTuple) this.rightParentNext;
 
@@ -210,23 +170,22 @@
         } else if ( previous != null ) {
             //remove from end
             this.rightParentPrevious.rightParentNext = null;
-        } else if ( this.rightParent != null ){
+        } else if ( this.rightParent != null ) {
             this.rightParent.setBetaChildren( null );
         }
-        
+
         //this.parent  = null;
-        
-        this.leftParent  = null;
-        this.leftParentPrevious = null;        
-        this.leftParentNext =  null;
-        
-        this.blocker = null;        
-        
-        this.rightParent  = null;
+
+        this.leftParent = null;
+        this.leftParentPrevious = null;
+        this.leftParentNext = null;
+
+        this.blocker = null;
+
+        this.rightParent = null;
         this.rightParentPrevious = null;
-        this.rightParentNext = null;        
+        this.rightParentNext = null;
     }
-    
 
     public LeftTupleSink getSink() {
         return sink;
@@ -295,7 +254,15 @@
         }
         return entry.handle;
     }
+    
+    public TupleHashTable getMemory() {
+        return this.memory;
+    }
 
+    public void setMemory(TupleHashTable memory) {
+        this.memory = memory;
+    }    
+
     public Entry getPrevious() {
         return previous;
     }

Modified: labs/jbossrules/branches/righttuple/drools-core/src/main/java/org/drools/reteoo/LeftTupleSinkPropagator.java
===================================================================
--- labs/jbossrules/branches/righttuple/drools-core/src/main/java/org/drools/reteoo/LeftTupleSinkPropagator.java	2008-01-12 00:59:23 UTC (rev 17754)
+++ labs/jbossrules/branches/righttuple/drools-core/src/main/java/org/drools/reteoo/LeftTupleSinkPropagator.java	2008-01-12 02:11:42 UTC (rev 17755)
@@ -2,6 +2,7 @@
 
 import java.io.Serializable;
 
+import org.drools.common.InternalFactHandle;
 import org.drools.common.InternalWorkingMemory;
 import org.drools.spi.PropagationContext;
 
@@ -25,14 +26,10 @@
                                            PropagationContext context,
                                            InternalWorkingMemory workingMemory);
 
-    public void createAndPropagateAssertTuple(RightTuple rightTuple,
+    public void createAndPropagateAssertTuple(InternalFactHandle factHandle,
                                               PropagationContext context,
                                               InternalWorkingMemory workingMemory);
 
-    public void createAndPropagateRetractTuple(RightTuple rightTuple,
-                                               PropagationContext context,
-                                               InternalWorkingMemory workingMemory);
-
     public LeftTupleSink[] getSinks();
 
     //    public void propagateNewTupleSink(TupleMatch tupleMatch,

Modified: labs/jbossrules/branches/righttuple/drools-core/src/main/java/org/drools/reteoo/MemoryVisitor.java
===================================================================
--- labs/jbossrules/branches/righttuple/drools-core/src/main/java/org/drools/reteoo/MemoryVisitor.java	2008-01-12 00:59:23 UTC (rev 17754)
+++ labs/jbossrules/branches/righttuple/drools-core/src/main/java/org/drools/reteoo/MemoryVisitor.java	2008-01-12 02:11:42 UTC (rev 17755)
@@ -10,6 +10,7 @@
 import org.drools.util.Entry;
 import org.drools.util.FactHandleIndexHashTable;
 import org.drools.util.FactHashTable;
+import org.drools.util.ObjectHashSet;
 import org.drools.util.ReflectiveVisitor;
 import org.drools.util.TupleHashTable;
 import org.drools.util.TupleIndexHashTable;
@@ -46,8 +47,8 @@
     public void visitObjectTypeNode(final ObjectTypeNode node) {
         System.out.println( indent() + node );
 
-        final FactHashTable memory = (FactHashTable) this.workingMemory.getNodeMemory( node );
-        checkObjectHashTable( memory );
+        final ObjectHashSet memory = (ObjectHashSet) this.workingMemory.getNodeMemory( node );
+        //checkObjectHashTable( memory );
 
         this.indent++;
         try {

Modified: labs/jbossrules/branches/righttuple/drools-core/src/main/java/org/drools/reteoo/NotNode.java
===================================================================
--- labs/jbossrules/branches/righttuple/drools-core/src/main/java/org/drools/reteoo/NotNode.java	2008-01-12 00:59:23 UTC (rev 17754)
+++ labs/jbossrules/branches/righttuple/drools-core/src/main/java/org/drools/reteoo/NotNode.java	2008-01-12 02:11:42 UTC (rev 17755)
@@ -16,8 +16,10 @@
  * limitations under the License.
  */
 
+import java.util.ArrayList;
+import java.util.List;
+
 import org.drools.common.BetaConstraints;
-import org.drools.common.EmptyBetaConstraints;
 import org.drools.common.InternalFactHandle;
 import org.drools.common.InternalWorkingMemory;
 import org.drools.reteoo.builder.BuildContext;
@@ -107,6 +109,22 @@
             }
         }
         
+//        for ( RightTuple rightTuple = memory.getRightTupleMemory().getFirst( leftTuple ); rightTuple != null; rightTuple = (RightTuple) rightTuple.getNext() ) {
+//            if ( this.constraints.isAllowedCachedLeft( rightTuple.getHandle() ) ) {
+//
+//                leftTuple.setBlocker( rightTuple );
+//
+//                LeftTuple blockedPrevious = rightTuple.getBlocked();
+//                if ( blockedPrevious != null ) {
+//                    leftTuple.setBlockedNext( blockedPrevious );
+//                    blockedPrevious.setBlockedPrevious( leftTuple );
+//                }
+//                rightTuple.setBlocked( leftTuple );
+//
+//                break;
+//            }
+//        }        
+        
         this.constraints.resetTuple();     
 
         if ( leftTuple.getBlocker() == null ) {
@@ -133,11 +151,13 @@
      * @param workingMemory
      *            The working memory seesion.
      */
-    public void assertRightTuple(final RightTuple rightTuple,
+    public void assertRightTuple(final InternalFactHandle factHandle,
                                  final PropagationContext context,
                                  final InternalWorkingMemory workingMemory) {
+        final RightTuple rightTuple = new RightTuple( factHandle, this);
+        
         final BetaMemory memory = (BetaMemory) workingMemory.getNodeMemory( this );
-        memory.getRightTupleMemory().add( rightTuple );
+        memory.getRightTupleMemory().add( rightTuple );        
 
         if ( !this.tupleMemoryEnabled ) {
             // do nothing here, as we know there are no left tuples at this stage in sequential mode.
@@ -147,7 +167,10 @@
         this.constraints.updateFromRightTuple( workingMemory,
                                                rightTuple );
 
-        for ( LeftTuple leftTuple = memory.getLeftTupleMemory().getFirst( rightTuple ); leftTuple != null; leftTuple = (LeftTuple) leftTuple.getNext() ) {
+        for ( LeftTuple leftTuple = memory.getLeftTupleMemory().getFirst( rightTuple ); leftTuple != null; ) {
+            // preserve next now, in case we remove this leftTuple 
+            LeftTuple temp = (LeftTuple) leftTuple.getNext();
+            
             // we know that only unblocked LeftTuples are  still in the memory
             if ( this.constraints.isAllowedCachedRight( leftTuple ) ) {
                 leftTuple.setBlocker( rightTuple );
@@ -159,16 +182,18 @@
                 }
                 rightTuple.setBlocked( leftTuple );
 
-                LeftTuple temp = (LeftTuple) leftTuple.getPrevious();
+                
                 // this is now blocked so remove from memory
-                memory.getLeftTupleMemory().remove( leftTuple );
+                memory.getLeftTupleMemory().remove( leftTuple );                
 
                 if ( leftTuple.getBetaChildren() != null ) {
                     this.sink.propagateRetractLeftTuple( leftTuple,
                                                          context,
                                                          workingMemory );
-                }
+                }                
             }
+            
+            leftTuple = temp;
         }
         
         this.constraints.resetFactHandle();       
@@ -190,43 +215,65 @@
     public void retractRightTuple(final RightTuple rightTuple,
                                   final PropagationContext context,
                                   final InternalWorkingMemory workingMemory) {
-        final BetaMemory memory = (BetaMemory) workingMemory.getNodeMemory( this );
-
-               
+        // assign now, so we can remove from memory before doing any possible propagations
+        final RightTuple rootBlocker = (RightTuple) rightTuple.getPrevious();     
+        
+        final BetaMemory memory = (BetaMemory) workingMemory.getNodeMemory( this );        
+        memory.getRightTupleMemory().remove( rightTuple );
+        
         if ( rightTuple.getBlocked() == null ) {
-            memory.getRightTupleMemory().remove( rightTuple );
+            //System.out.println( "NotNode.retractObjject" + rightTuple.getHandle() + " : 0 : []");
             return;
-        }
+        }           
+
+        //int blockedCount = 0;
+        //List list  = new  ArrayList();
         
-        // assign now, so we can remove from memory before doing any possible propagations
-        final RightTuple rootBlocker = (RightTuple) rightTuple.getPrevious();        
-
-        for ( LeftTuple leftTuple = (LeftTuple) rightTuple.getBlocked(); leftTuple != null; leftTuple = (LeftTuple) leftTuple.getBlockedNext() ) {
+        for ( LeftTuple leftTuple = (LeftTuple) rightTuple.getBlocked(); leftTuple != null; ) {
+            //blockedCount++;
+            LeftTuple temp = leftTuple.getBlockedNext();            
+            
             leftTuple.setBlocker( null );
-            LeftTuple previousBlocked = leftTuple.getBlockedPrevious();
-            if ( previousBlocked != null ) {
-                previousBlocked.setBlockedNext( null );
-            }
-            leftTuple.setBlockedPrevious ( null );
+            leftTuple.setBlockedPrevious( null );
+            leftTuple.setBlockedNext( null );
             
             this.constraints.updateFromTuple( workingMemory,
                                               leftTuple );
+            
+            int blockSearch = 0;
+          // we know that older tuples have been checked so continue previously
+          for ( RightTuple newBlocker = memory.getRightTupleMemory().getFirst( leftTuple ); newBlocker != null; newBlocker = (RightTuple) newBlocker.getNext() ) {
+              //blockSearch++;
+              if ( this.constraints.isAllowedCachedLeft( newBlocker.getHandle() ) ) {
+                  leftTuple.setBlocker( newBlocker );
 
-            // we know that older tuples have been checked so continue previously
-            for ( RightTuple newBlocker = rootBlocker; newBlocker != null; newBlocker = (RightTuple) newBlocker.getPrevious() ) {
-                if ( this.constraints.isAllowedCachedLeft( newBlocker.getHandle() ) ) {
-                    leftTuple.setBlocker( newBlocker );
+                  LeftTuple blockedPrevious = newBlocker.getBlocked();
+                  if ( blockedPrevious != null ) {
+                      leftTuple.setBlockedNext( blockedPrevious );
+                      blockedPrevious.setBlockedPrevious( leftTuple );
+                  }
+                  newBlocker.setBlocked( leftTuple );
 
-                    LeftTuple blockedPrevious = newBlocker.getBlocked();
-                    if ( blockedPrevious != null ) {
-                        leftTuple.setBlockedNext( blockedPrevious );
-                        blockedPrevious.setBlockedPrevious( leftTuple );
-                    }
-                    newBlocker.setBlocked( leftTuple );
+                  break;
+              }
+          }  
+          //list.add( blockSearch );
 
-                    break;
-                }
-            }
+//            // we know that older tuples have been checked so continue previously
+//            for ( RightTuple newBlocker = rootBlocker; newBlocker != null; newBlocker = (RightTuple) newBlocker.getPrevious() ) {
+//                if ( this.constraints.isAllowedCachedLeft( newBlocker.getHandle() ) ) {
+//                    leftTuple.setBlocker( newBlocker );
+//
+//                    LeftTuple blockedPrevious = newBlocker.getBlocked();
+//                    if ( blockedPrevious != null ) {
+//                        leftTuple.setBlockedNext( blockedPrevious );
+//                        blockedPrevious.setBlockedPrevious( leftTuple );
+//                    }
+//                    newBlocker.setBlocked( leftTuple );
+//
+//                    break;
+//                }
+//            }
             
             if ( leftTuple.getBlocker() == null ) {
                 // was previous blocked and not in memory, so add
@@ -236,7 +283,10 @@
                                                 context,
                                                 workingMemory );
             }            
+            
+            leftTuple = temp;
         }
+        //System.out.println( "NotNode.retractObjject" + rightTuple.getHandle() + " : " + blockedCount + " : " + list);
     }
 
     /**

Modified: labs/jbossrules/branches/righttuple/drools-core/src/main/java/org/drools/reteoo/ObjectTypeNode.java
===================================================================
--- labs/jbossrules/branches/righttuple/drools-core/src/main/java/org/drools/reteoo/ObjectTypeNode.java	2008-01-12 00:59:23 UTC (rev 17754)
+++ labs/jbossrules/branches/righttuple/drools-core/src/main/java/org/drools/reteoo/ObjectTypeNode.java	2008-01-12 02:11:42 UTC (rev 17755)
@@ -20,6 +20,7 @@
 
 import org.drools.RuleBaseConfiguration;
 import org.drools.common.BaseNode;
+import org.drools.common.InternalFactHandle;
 import org.drools.common.InternalWorkingMemory;
 import org.drools.common.NodeMemory;
 import org.drools.common.PropagationContextImpl;
@@ -31,7 +32,11 @@
 import org.drools.spi.PropagationContext;
 import org.drools.util.FactHashTable;
 import org.drools.util.Iterator;
+import org.drools.util.ObjectHashSet;
+import org.drools.util.ObjectHashSet.ObjectEntry;
 
+;
+
 /**
  * <code>ObjectTypeNodes<code> are responsible for filtering and propagating the matching
  * fact assertions propagated from the <code>Rete</code> node using <code>ObjectType</code> interface.
@@ -138,7 +143,7 @@
      * @param workingMemory
      *            The working memory session.
      */
-    public void assertRightTuple(final RightTuple rightTuple,
+    public void assertRightTuple(final InternalFactHandle factHandle,
                                  final PropagationContext context,
                                  final InternalWorkingMemory workingMemory) {
         if ( context.getType() == PropagationContext.MODIFICATION && this.skipOnModify && context.getDormantActivations() == 0 ) {
@@ -147,15 +152,22 @@
         }
 
         if ( this.objectMemoryEnabled ) {
-            final FactHashTable memory = (FactHashTable) workingMemory.getNodeMemory( this );
-            memory.add( rightTuple );
+            final ObjectHashSet memory = (ObjectHashSet) workingMemory.getNodeMemory( this );
+            memory.add( factHandle );
         }
 
-        this.sink.propagateAssertRightTuple( rightTuple,
+        this.sink.propagateAssertRightTuple( factHandle,
                                              context,
                                              workingMemory );
     }
 
+    public void retractRightTuple(final RightTuple rightTuple,
+                                  final PropagationContext context,
+                                  final InternalWorkingMemory workingMemory) {
+        throw new UnsupportedOperationException( "ObjectTypeNode.retractRightTuple is not supported." );
+
+    }
+
     /**
      * Retract the <code>FactHandleimpl</code> from the <code>Rete</code> network. Also remove the 
      * <code>FactHandleImpl</code> from the node memory.
@@ -167,7 +179,7 @@
      * @param workingMemory
      *            The working memory session.
      */
-    public void retractRightTuple(final RightTuple rightTuple,
+    public void retractRightTuple(final InternalFactHandle factHandle,
                                   final PropagationContext context,
                                   final InternalWorkingMemory workingMemory) {
 
@@ -176,18 +188,23 @@
         }
 
         if ( this.objectMemoryEnabled ) {
-            final FactHashTable memory = (FactHashTable) workingMemory.getNodeMemory( this );
-            memory.remove( rightTuple );
+            final ObjectHashSet memory = (ObjectHashSet) workingMemory.getNodeMemory( this );
+            memory.remove( factHandle );
         }
-         
-        
-        if ( rightTuple.getAlphaChildren() != null ) {
-            this.sink.propagateRetractRightTuple( rightTuple,
-                                                  context,
-                                                  workingMemory,
-                                                  true );
+
+        for ( RightTuple rightTuple = factHandle.getRightTuple(); rightTuple != null; rightTuple = (RightTuple) rightTuple.getHandleNext() ) {
+            rightTuple.getRightTupleSink().retractRightTuple( rightTuple,
+                                                              context,
+                                                              workingMemory );
         }
+        factHandle.setRightTuple( null );
 
+        for ( LeftTuple leftTuple = factHandle.getLeftTuple(); leftTuple != null; leftTuple = (LeftTuple) leftTuple.getLeftParentNext() ) {
+            leftTuple.getSink().retractTuple( leftTuple,
+                                              context,
+                                              workingMemory );
+        }
+        factHandle.setLeftTuple( null );
     }
 
     public void updateSink(final RightTupleSink sink,
@@ -195,9 +212,10 @@
                            final InternalWorkingMemory workingMemory) {
         final FactHashTable memory = (FactHashTable) workingMemory.getNodeMemory( this );
         for ( RightTuple rightTuple = (RightTuple) memory.getFirst( null ); rightTuple != null; rightTuple = (RightTuple) rightTuple.getNext() ) {
-            sink.assertRightTuple( rightTuple,
-                                   context,
-                                   workingMemory );
+            //@ TODO
+            //            sink.assertRightTuple( rightTuple,
+            //                                   context,
+            //                                   workingMemory );
         }
     }
 
@@ -255,7 +273,7 @@
      * to switch back to a standard HashMap.
      */
     public Object createMemory(final RuleBaseConfiguration config) {
-        return new FactHashTable();
+        return new ObjectHashSet();
     }
 
     public boolean isRightTupleMemoryEnabled() {

Modified: labs/jbossrules/branches/righttuple/drools-core/src/main/java/org/drools/reteoo/Rete.java
===================================================================
--- labs/jbossrules/branches/righttuple/drools-core/src/main/java/org/drools/reteoo/Rete.java	2008-01-12 00:59:23 UTC (rev 17754)
+++ labs/jbossrules/branches/righttuple/drools-core/src/main/java/org/drools/reteoo/Rete.java	2008-01-12 02:11:42 UTC (rev 17755)
@@ -22,6 +22,7 @@
 import java.util.HashMap;
 import java.util.Map;
 
+import org.drools.FactHandle;
 import org.drools.base.ShadowProxy;
 import org.drools.common.BaseNode;
 import org.drools.common.DroolsObjectInputStream;
@@ -95,12 +96,6 @@
     // Instance methods
     // ------------------------------------------------------------
 
-    
-    public void assertRightTuple(final RightTuple rightTuple,
-                                 final PropagationContext context,
-                                 final InternalWorkingMemory workingMemory) {
-        // do nothing
-    }
     /**
      * This is the entry point into the network for all asserted Facts. Iterates a cache
      * of matching <code>ObjectTypdeNode</code>s asserting the Fact. If the cache does not
@@ -135,22 +130,11 @@
 
         ObjectTypeNode[] cachedNodes = objectTypeConf.getObjectTypeNodes();
 
-        RightTuple rightTuple = null;
         for ( int i = 0, length = cachedNodes.length; i < length; i++ ) {
-            rightTuple =  new RightTuple( factHandle,
-                                          cachedNodes[i] );
-            cachedNodes[i].assertRightTuple( rightTuple,
+            cachedNodes[i].assertRightTuple( factHandle,
                                              context,
                                              workingMemory );
-            if ( i < length-1 ) {
-                RightTuple temp = new RightTuple( factHandle );
-                temp.setParentNext( rightTuple );
-                rightTuple.setParentPrevious( temp );
-                                
-                rightTuple = temp;
-            }
         }
-        factHandle.setRightTuple( rightTuple );
     }
 
     /**
@@ -162,13 +146,28 @@
      * @param workingMemory
      *            The working memory session.
      */
-    public void retractRightTuple(RightTuple rightTuple,
+    public void retractRightTuple(final InternalFactHandle factHandle,
                                   final PropagationContext context,
                                   final InternalWorkingMemory workingMemory) {
-        for ( ; rightTuple != null; rightTuple = ( RightTuple ) rightTuple.getParentNext() ) {
-            rightTuple.getRightTupleSink().retractRightTuple( rightTuple, context, workingMemory );
-        }
+        Object object = factHandle.getObject();
+        
+        ObjectTypeConf objectTypeConf = workingMemory.getObjectTypeConf( context.getEntryPoint(),
+                                                                         object );
+        
+        ObjectTypeNode[] cachedNodes = objectTypeConf.getObjectTypeNodes();
+
+        for ( int i = 0, length = cachedNodes.length; i < length; i++ ) {
+            cachedNodes[i].retractRightTuple( factHandle,
+                                              context,
+                                              workingMemory );
+        }        
     }
+    
+    public void retractRightTuple(final RightTuple rightTuple,
+                                  final PropagationContext context,
+                                  final InternalWorkingMemory workingMemory) {
+        throw new UnsupportedOperationException( "Rete.retractRightTuple is not supported." );
+    }    
 
     /**
      * Adds the <code>ObjectSink</code> so that it may receive
@@ -264,11 +263,12 @@
                 objectTypeConf.resetCache();
                 ObjectTypeNode sourceNode = objectTypeConf.getConcreteObjectTypeNode();
                 FactHashTable table = (FactHashTable) workingMemory.getNodeMemory( sourceNode );
-                for ( RightTuple rightTuple = (RightTuple) table.getFirst( null ); rightTuple != null; rightTuple = (RightTuple) rightTuple.getNext() ) {
-                    sink.assertRightTuple( new RightTuple( rightTuple, sink ),
-                                           context,
-                                           workingMemory );
-                }
+                // @TODO
+//                for ( RightTuple rightTuple = (RightTuple) table.getFirst( null ); rightTuple != null; rightTuple = (RightTuple) rightTuple.getNext() ) {
+//                    sink.assertRightTuple( new RightTuple( rightTuple, sink ),
+//                                           context,
+//                                           workingMemory );
+//                }
             }
         }
     }

Modified: labs/jbossrules/branches/righttuple/drools-core/src/main/java/org/drools/reteoo/ReteooRuleBase.java
===================================================================
--- labs/jbossrules/branches/righttuple/drools-core/src/main/java/org/drools/reteoo/ReteooRuleBase.java	2008-01-12 00:59:23 UTC (rev 17754)
+++ labs/jbossrules/branches/righttuple/drools-core/src/main/java/org/drools/reteoo/ReteooRuleBase.java	2008-01-12 02:11:42 UTC (rev 17755)
@@ -215,11 +215,9 @@
     public void retractObject(final FactHandle handle,
                               final PropagationContext context,
                               final ReteooWorkingMemory workingMemory) throws FactException {
-        getRete().retractRightTuple( ((InternalFactHandle)handle).getRightTuple(),
+        getRete().retractRightTuple( (InternalFactHandle) handle,
                                      context,
-                                     workingMemory );
-        
-        ((InternalFactHandle)handle).setRightTuple( null );
+                                     workingMemory );        
     }
 
     public synchronized StatefulSession newStatefulSession(final boolean keepReference) {

Modified: labs/jbossrules/branches/righttuple/drools-core/src/main/java/org/drools/reteoo/RightTuple.java
===================================================================
--- labs/jbossrules/branches/righttuple/drools-core/src/main/java/org/drools/reteoo/RightTuple.java	2008-01-12 00:59:23 UTC (rev 17754)
+++ labs/jbossrules/branches/righttuple/drools-core/src/main/java/org/drools/reteoo/RightTuple.java	2008-01-12 02:11:42 UTC (rev 17755)
@@ -2,20 +2,21 @@
 
 import org.drools.common.InternalFactHandle;
 import org.drools.util.Entry;
+import org.drools.util.FactHashTable;
 
 public class RightTuple
     implements
     Entry {
     private final InternalFactHandle handle;
+    
+    private RightTuple               handlePrevious;
+    private RightTuple               handleNext;
 
-    private RightTuple               parent;
-    private RightTuple               parentPrevious;
-    private RightTuple               parentNext;
-
+    private FactHashTable            memory;
+    
     private Entry                    previous;
     private Entry                    next;
 
-    private RightTuple               alphaChildren;
     private LeftTuple                betaChildren;
 
     private LeftTuple                blocked;
@@ -27,41 +28,33 @@
     public RightTuple(InternalFactHandle handle) {
         this.handle = handle;
         this.hashCode = this.handle.hashCode();
-        this.parent = null;
     }
 
     public RightTuple(InternalFactHandle handle,
                       RightTupleSink sink) {
         this.handle = handle;
         this.hashCode = this.handle.hashCode();
-        this.parent = null;
         this.sink = sink;
+        
+        RightTuple currentFirst = handle.getRightTuple();
+        if ( currentFirst != null ) {
+            currentFirst.handlePrevious =  this;
+            this.handleNext = currentFirst;
+        }
+        
+        handle.setRightTuple( this );                
     }
 
     public RightTuple(RightTuple parent) {
         this.handle = parent.getHandle();
         this.hashCode = this.handle.hashCode();
-        this.parent = parent;
-
-        this.parentNext = parent.getAlphaChildren();
-        if ( parentNext != null ) {
-            this.parentNext.parentPrevious = this;
-        }
-        parent.setAlphaChildren( this );
     }
 
     public RightTuple(RightTuple parent,
                       RightTupleSink sink) {
         this.handle = parent.getHandle();
         this.hashCode = this.handle.hashCode();
-        this.parent = parent;
 
-        this.parentNext = parent.getAlphaChildren();
-        if ( parentNext != null ) {
-            this.parentNext.parentPrevious = this;
-        }
-        parent.setAlphaChildren( this );
-
         this.sink = sink;
 
     }
@@ -70,64 +63,68 @@
         return this.sink;
     }
 
-    public void unlinkFromRightParent() {
-        if ( this.parent != null ) {
-            if ( this.parentPrevious != null ) {
-                this.parentPrevious.parentNext = this.parentNext;
-            } else {
-                // first one in the chain, so treat differently                
-                this.parent.setAlphaChildren( this.parentNext );
-            }
+//    public void unlinkFromRightParent() {
+//        if ( this.parent != null ) {
+//            if ( this.parentPrevious != null ) {
+//                this.parentPrevious.parentNext = this.parentNext;
+//            } else {
+//                // first one in the chain, so treat differently                
+//                this.parent.setAlphaChildren( this.parentNext );
+//            }
+//
+//            if ( this.parentNext != null ) {
+//                this.parentNext.parentPrevious = this.parentPrevious;
+//            }
+//        }
+//
+//        this.parent = null;
+//        this.parentPrevious = null;
+//        this.parentNext = null;
+//        this.blocked = null;
+//    }
 
-            if ( this.parentNext != null ) {
-                this.parentNext.parentPrevious = this.parentPrevious;
-            }
-        }
-
-        this.parent = null;
-        this.parentPrevious = null;
-        this.parentNext = null;
-        this.blocked = null;
-    }
-
     public InternalFactHandle getHandle() {
         return this.handle;
     }
 
-    public RightTuple getParent() {
-        return parent;
+    public LeftTuple getBlocked() {
+        return blocked;
     }
 
-    public RightTuple getParentPrevious() {
-        return parentPrevious;
-    }
+    public void setBlocked(LeftTuple blocked) {
+        this.blocked = blocked;
+    }        
 
-    public void setParentPrevious(RightTuple parentPrevious) {
-        this.parentPrevious = parentPrevious;
+    public FactHashTable getMemory() {
+        return memory;
     }
 
-    public RightTuple getParentNext() {
-        return parentNext;
+    public void setMemory(FactHashTable memory) {
+        this.memory = memory;
     }
 
-    public void setParentNext(RightTuple parentNext) {
-        this.parentNext = parentNext;
+    public Entry getPrevious() {
+        return previous;
     }
 
-    public LeftTuple getBlocked() {
-        return blocked;
+    public void setPrevious(Entry previous) {
+        this.previous = previous;
+    }        
+
+    public RightTuple getHandlePrevious() {
+        return handlePrevious;
     }
 
-    public void setBlocked(LeftTuple blocked) {
-        this.blocked = blocked;
+    public void setHandlePrevious(RightTuple handlePrevious) {
+        this.handlePrevious = handlePrevious;
     }
 
-    public Entry getPrevious() {
-        return previous;
+    public RightTuple getHandleNext() {
+        return handleNext;
     }
 
-    public void setPrevious(Entry previous) {
-        this.previous = previous;
+    public void setHandleNext(RightTuple handleNext) {
+        this.handleNext = handleNext;
     }
 
     public Entry getNext() {
@@ -138,14 +135,6 @@
         this.next = next;
     }
 
-    public RightTuple getAlphaChildren() {
-        return alphaChildren;
-    }
-
-    public void setAlphaChildren(RightTuple alphaChildren) {
-        this.alphaChildren = alphaChildren;
-    }
-
     public LeftTuple getBetaChildren() {
         return betaChildren;
     }

Modified: labs/jbossrules/branches/righttuple/drools-core/src/main/java/org/drools/reteoo/RightTupleSink.java
===================================================================
--- labs/jbossrules/branches/righttuple/drools-core/src/main/java/org/drools/reteoo/RightTupleSink.java	2008-01-12 00:59:23 UTC (rev 17754)
+++ labs/jbossrules/branches/righttuple/drools-core/src/main/java/org/drools/reteoo/RightTupleSink.java	2008-01-12 02:11:42 UTC (rev 17755)
@@ -16,6 +16,7 @@
  * limitations under the License.
  */
 
+import org.drools.common.InternalFactHandle;
 import org.drools.common.InternalWorkingMemory;
 import org.drools.spi.PropagationContext;
 
@@ -43,9 +44,9 @@
      * @param workingMemory
      *            the <code>WorkingMemory</code> session.
      */
-    void assertRightTuple(RightTuple rightTuple,
-                      PropagationContext context,
-                      InternalWorkingMemory workingMemory);
+    void assertRightTuple(InternalFactHandle handle,
+                          PropagationContext context,
+                          InternalWorkingMemory workingMemory);
 
     /**
      * Retract an existing <code>FactHandleImpl</code>.
@@ -58,10 +59,7 @@
      *            the <code>WorkingMemory</code> session.
      */
     void retractRightTuple(RightTuple rightTuple,
-                       PropagationContext context,
-                       InternalWorkingMemory workingMemory);
+                           PropagationContext context,
+                           InternalWorkingMemory workingMemory);
 
-    public boolean isRightTupleMemoryEnabled();
-
-    public void setRightTupleMemoryEnabled(boolean objectMemoryOn);
 }

Modified: labs/jbossrules/branches/righttuple/drools-core/src/main/java/org/drools/reteoo/RightTupletSinkPropagator.java
===================================================================
--- labs/jbossrules/branches/righttuple/drools-core/src/main/java/org/drools/reteoo/RightTupletSinkPropagator.java	2008-01-12 00:59:23 UTC (rev 17754)
+++ labs/jbossrules/branches/righttuple/drools-core/src/main/java/org/drools/reteoo/RightTupletSinkPropagator.java	2008-01-12 02:11:42 UTC (rev 17755)
@@ -2,21 +2,17 @@
 
 import java.io.Serializable;
 
+import org.drools.common.InternalFactHandle;
 import org.drools.common.InternalWorkingMemory;
 import org.drools.spi.PropagationContext;
 
 public interface RightTupletSinkPropagator
     extends
     Serializable {
-    public void propagateAssertRightTuple(RightTuple rightTuple,
+    public void propagateAssertRightTuple(InternalFactHandle handle,
                                           PropagationContext context,
                                           InternalWorkingMemory workingMemory);
 
-    public void propagateRetractRightTuple(RightTuple rightTuple,
-                                           PropagationContext context,
-                                           InternalWorkingMemory workingMemory,
-                                           boolean useHash);
-
     public RightTupleSink[] getSinks();
 
     public int size();

Modified: labs/jbossrules/branches/righttuple/drools-core/src/main/java/org/drools/reteoo/SingleLeftTupleSinkAdapter.java
===================================================================
--- labs/jbossrules/branches/righttuple/drools-core/src/main/java/org/drools/reteoo/SingleLeftTupleSinkAdapter.java	2008-01-12 00:59:23 UTC (rev 17754)
+++ labs/jbossrules/branches/righttuple/drools-core/src/main/java/org/drools/reteoo/SingleLeftTupleSinkAdapter.java	2008-01-12 02:11:42 UTC (rev 17755)
@@ -1,5 +1,6 @@
 package org.drools.reteoo;
 
+import org.drools.common.InternalFactHandle;
 import org.drools.common.InternalWorkingMemory;
 import org.drools.spi.PropagationContext;
 
@@ -83,29 +84,15 @@
         rightTuple.setBetaChildren( null );
     }    
 
-    public void createAndPropagateAssertTuple(final RightTuple rightTuple,
+    public void createAndPropagateAssertTuple(final InternalFactHandle factHandle,
                                               final PropagationContext context,
                                               final InternalWorkingMemory workingMemory) {
-        this.sink.assertTuple( new LeftTuple( rightTuple,
+        this.sink.assertTuple( new LeftTuple( factHandle,
                                               this.sink ),
                                context,
                                workingMemory );
     }
 
-    public void createAndPropagateRetractTuple(final RightTuple rightTuple,
-                                               final PropagationContext context,
-                                               final InternalWorkingMemory workingMemory) {
-        LeftTuple child = rightTuple.getBetaChildren();
-        while ( child != null ) {
-            //LeftTuple temp = child.getRightParentNext();
-            //child.unlinkFromParents();
-            child.getSink().retractTuple( child, context, workingMemory );
-            child = child.getRightParentNext();
-            //child = temp;
-        }
-        rightTuple.setBetaChildren( null );
-    }
-
     public LeftTupleSink[] getSinks() {
         return new LeftTupleSink[]{this.sink};
     }

Modified: labs/jbossrules/branches/righttuple/drools-core/src/main/java/org/drools/reteoo/SingleRightTupletSinkAdapter.java
===================================================================
--- labs/jbossrules/branches/righttuple/drools-core/src/main/java/org/drools/reteoo/SingleRightTupletSinkAdapter.java	2008-01-12 00:59:23 UTC (rev 17754)
+++ labs/jbossrules/branches/righttuple/drools-core/src/main/java/org/drools/reteoo/SingleRightTupletSinkAdapter.java	2008-01-12 02:11:42 UTC (rev 17755)
@@ -1,5 +1,6 @@
 package org.drools.reteoo;
 
+import org.drools.common.InternalFactHandle;
 import org.drools.common.InternalWorkingMemory;
 import org.drools.spi.PropagationContext;
 
@@ -15,26 +16,15 @@
         this.sink = sink;
     }
 
-    public void propagateAssertRightTuple(final RightTuple rightTuple,
+    public void propagateAssertRightTuple(final InternalFactHandle factHandle,
                                           final PropagationContext context,
                                           final InternalWorkingMemory workingMemory) {
-        this.sink.assertRightTuple( new RightTuple( rightTuple ),
+        this.sink.assertRightTuple( factHandle,
                                     context,
                                     workingMemory );
 
     }
 
-    public void propagateRetractRightTuple(final RightTuple rightTuple,
-                                           final PropagationContext context,
-                                           final InternalWorkingMemory workingMemory,
-                                           final boolean useHash) {
-        //rightTuple.unlinkFromRightParent();
-        this.sink.retractRightTuple( rightTuple.getAlphaChildren(),
-                                     context,
-                                     workingMemory );              
-        rightTuple.setAlphaChildren( null );        
-    }
-
     public RightTupleSink[] getSinks() {
         return new RightTupleSink[]{this.sink};
     }

Modified: labs/jbossrules/branches/righttuple/drools-core/src/main/java/org/drools/util/FactHandleIndexHashTable.java
===================================================================
--- labs/jbossrules/branches/righttuple/drools-core/src/main/java/org/drools/util/FactHandleIndexHashTable.java	2008-01-12 00:59:23 UTC (rev 17754)
+++ labs/jbossrules/branches/righttuple/drools-core/src/main/java/org/drools/util/FactHandleIndexHashTable.java	2008-01-12 02:11:42 UTC (rev 17755)
@@ -23,7 +23,7 @@
     private Index                       index;
 
     public FactHandleIndexHashTable(final FieldIndex[] index) {
-        this( 16,
+        this( 128,
               0.75f,
               index );
     }
@@ -146,6 +146,7 @@
 
     public void add(final RightTuple rightTuple) {
         final FactHashTable entry = getOrCreate( rightTuple.getHandle().getObject() );
+        rightTuple.setMemory( entry );
         entry.add( rightTuple );
         this.factSize++;
     }
@@ -154,46 +155,59 @@
      * We assume that this rightTuple is contained in this hash table
      */
     public void remove(final RightTuple rightTuple) {
-        RightTuple previousRightTuple = (RightTuple) rightTuple.getPrevious();
-        if ( previousRightTuple != null && rightTuple.getNext() != null ) {
-            // Optimisation for tuple self removal if it's not the first in the chain
-            // we can't do this if it's the only remain tuple, as we need to also remove the parent bucket.
-            previousRightTuple.setNext( rightTuple.getNext() );
-            rightTuple.getNext().setPrevious( previousRightTuple );
-            this.size--;
+        if ( rightTuple.getMemory() != null ) {
+            FactHashTable  memory =rightTuple.getMemory();
+            memory.remove( rightTuple );
+            if ( memory.first == null ) {
+                final int index = indexOf( memory.hashCode(),
+                                           this.table.length );                
+                FactHashTable previous = null;
+                FactHashTable current = (FactHashTable) this.table[index];
+                while ( current != memory ) {
+                    previous = current;
+                    current = (FactHashTable) current.getNext();
+                }
+                
+                if ( previous  != null ) {
+                    previous.next = current.next;
+                } else {
+                    this.table[index] = current.next;
+                }
+                this.size--;                
+            }
+            return;
         }
-
+        
         final Object object = rightTuple.getHandle().getObject();
-        //this.index.setCachedValue( object );
         final int hashCode = this.index.hashCodeOf( object );
-
         final int index = indexOf( hashCode,
                                    this.table.length );
 
-        // search the table for  the Entry, we need to track previous  and next, so if the 
-        // Entry is empty after  its had the FactEntry removed, we must remove  it from the table
-        FactHashTable previous = (FactHashTable) this.table[index];
-        FactHashTable current = previous;
-        while ( current != null ) {
-            final FactHashTable next = (FactHashTable) current.next;
+        // search the table for  the Entry, we need to track previous, so if the Entry
+        // is empty we can remove it.
+        FactHashTable previous = null;
+        FactHashTable current = (FactHashTable) this.table[index];
+        while ( current != null  ) {
             if ( current.matches( object,
                                   hashCode ) ) {
                 current.remove( rightTuple );
                 this.factSize--;
-                // If the FactEntryIndex is empty, then remove it from the hash table
+                
                 if ( current.first == null ) {
-                    if ( previous == current ) {
-                        this.table[index] = next;
+                    if ( previous  != null ) {
+                        previous.next = current.next;
                     } else {
-                        previous.next = next;
+                        this.table[index] = current.next;
                     }
-                    current.next = null;
                     this.size--;
                 }
+                break;
             }
             previous = current;
-            current = next;
+            current = (FactHashTable) current.next;
         }
+        rightTuple.setNext(null);
+        rightTuple.setPrevious(null);
     }
 
     public boolean contains(final RightTuple rightTuple) {

Modified: labs/jbossrules/branches/righttuple/drools-core/src/main/java/org/drools/util/ObjectHashMap.java
===================================================================
--- labs/jbossrules/branches/righttuple/drools-core/src/main/java/org/drools/util/ObjectHashMap.java	2008-01-12 00:59:23 UTC (rev 17754)
+++ labs/jbossrules/branches/righttuple/drools-core/src/main/java/org/drools/util/ObjectHashMap.java	2008-01-12 02:11:42 UTC (rev 17755)
@@ -10,7 +10,7 @@
     private static final long serialVersionUID = 400L;
 
     public ObjectHashMap() {
-        this( 16,
+        this( 128,
               0.75f );
     }
 

Modified: labs/jbossrules/branches/righttuple/drools-core/src/main/java/org/drools/util/ObjectHashSet.java
===================================================================
--- labs/jbossrules/branches/righttuple/drools-core/src/main/java/org/drools/util/ObjectHashSet.java	2008-01-12 00:59:23 UTC (rev 17754)
+++ labs/jbossrules/branches/righttuple/drools-core/src/main/java/org/drools/util/ObjectHashSet.java	2008-01-12 02:11:42 UTC (rev 17755)
@@ -10,7 +10,7 @@
     private static final long serialVersionUID = 400L;
 
     public ObjectHashSet() {
-        this( 16,
+        this( 128,
               0.75f );
     }
 

Modified: labs/jbossrules/branches/righttuple/drools-core/src/main/java/org/drools/util/TupleIndexHashTable.java
===================================================================
--- labs/jbossrules/branches/righttuple/drools-core/src/main/java/org/drools/util/TupleIndexHashTable.java	2008-01-12 00:59:23 UTC (rev 17754)
+++ labs/jbossrules/branches/righttuple/drools-core/src/main/java/org/drools/util/TupleIndexHashTable.java	2008-01-12 02:11:42 UTC (rev 17755)
@@ -25,7 +25,7 @@
     private Index                           index;
 
     public TupleIndexHashTable(final FieldIndex[] index) {
-        this( 16,
+        this( 128,
               0.75f,
               index );
     }
@@ -163,56 +163,64 @@
 
     public void add(final LeftTuple tuple) {
         final TupleHashTable entry = getOrCreate( tuple );
+        tuple.setMemory( entry );
         entry.add( tuple );
         this.factSize++;
     }
     
     public void remove(final LeftTuple leftTuple) {
-        LeftTuple previousLeftTuple = (LeftTuple) leftTuple.getPrevious();
-        LeftTuple nextLeftTuple = (LeftTuple) leftTuple.getNext();
-        if ( previousLeftTuple != null && nextLeftTuple != null ) {
-            // Optimisation for tuple self removal if it's not the first in the chain
-            // we can't do this if it's the only remain tuple, as we need to also remove the parent bucket.
-            previousLeftTuple.setNext( nextLeftTuple );
-            nextLeftTuple.setPrevious( previousLeftTuple );
-            this.size--;
-            leftTuple.setPrevious( null );
-            leftTuple.setNext( null );
+        if ( leftTuple.getMemory() != null ) {
+            TupleHashTable  memory =leftTuple.getMemory();
+            memory.remove( leftTuple );
+            if ( memory.first == null ) {
+                final int index = indexOf( memory.hashCode(),
+                                           this.table.length );                
+                TupleHashTable previous = null;
+                TupleHashTable current = (TupleHashTable) this.table[index];
+                while ( current != memory ) {
+                    previous = current;
+                    current = (TupleHashTable) current.getNext();
+                }
+                
+                if ( previous  != null ) {
+                    previous.next = current.next;
+                } else {
+                    this.table[index] = current.next;
+                }
+                this.size--;                
+            }
             return;
         }
         
         final int hashCode = this.index.hashCodeOf( leftTuple );
-
         final int index = indexOf( hashCode,
                                    this.table.length );
 
-        // search the table for  the Entry, we need to track previous  and next, so if the 
-        // Entry is empty after  its had the FactEntry removed, we must remove  it from the table
-        TupleHashTable previous = (TupleHashTable) this.table[index];
-        TupleHashTable current = previous;
-        while ( current != null ) {
-            final TupleHashTable next = (TupleHashTable) current.next;
+        // search the table for  the Entry, we need to track previous, so if the Entry
+        // is empty we can remove it.
+        TupleHashTable previous = null;
+        TupleHashTable current = (TupleHashTable) this.table[index];
+        while ( current != null  ) {
             if ( current.matches( leftTuple,
                                   hashCode ) ) {
                 current.remove( leftTuple );
                 this.factSize--;
-                // If the FactEntryIndex is empty, then remove it from the hash table
+                
                 if ( current.first == null ) {
-                    if ( previous == current ) {
-                        this.table[index] = next;
+                    if ( previous  != null ) {
+                        previous.next = current.next;
                     } else {
-                        previous.next = next;
+                        this.table[index] = current.next;
                     }
-                    current.next = null;
                     this.size--;
                 }
+                break;
             }
             previous = current;
-            current = next;
+            current = (TupleHashTable) current.next;
         }
-        
-        leftTuple.setPrevious( null );
-        leftTuple.setNext( null );
+        leftTuple.setNext(null);
+        leftTuple.setPrevious(null);
     }
 
     public boolean contains(final LeftTuple tuple) {

Modified: labs/jbossrules/branches/righttuple/drools-core/src/test/java/org/drools/examples/manners/ReteooMannersTest.java
===================================================================
--- labs/jbossrules/branches/righttuple/drools-core/src/test/java/org/drools/examples/manners/ReteooMannersTest.java	2008-01-12 00:59:23 UTC (rev 17754)
+++ labs/jbossrules/branches/righttuple/drools-core/src/test/java/org/drools/examples/manners/ReteooMannersTest.java	2008-01-12 02:11:42 UTC (rev 17755)
@@ -67,7 +67,7 @@
         };
 
         //workingMemory.addEventListener(listener );
-        final InputStream is = getClass().getResourceAsStream( "/manners64.dat" );
+        final InputStream is = getClass().getResourceAsStream( "/manners5.dat" );
         final List list = getInputObjects( is );
         for ( final Iterator it = list.iterator(); it.hasNext(); ) {
             final Object object = it.next();




More information about the jboss-svn-commits mailing list