[jboss-svn-commits] JBL Code SVN: r12990 - labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Sun Jul 1 23:02:56 EDT 2007


Author: mark.proctor at jboss.com
Date: 2007-07-01 23:02:56 -0400 (Sun, 01 Jul 2007)
New Revision: 12990

Modified:
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/ArrayAgendaGroup.java
Log:
JBRULES-947 sequential rete
-add performance enhancement to reduce iteration range, be tracking first and last populated elements.

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/ArrayAgendaGroup.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/ArrayAgendaGroup.java	2007-07-02 02:35:56 UTC (rev 12989)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/ArrayAgendaGroup.java	2007-07-02 03:02:56 UTC (rev 12990)
@@ -57,6 +57,8 @@
 
     private int               index;
 
+    private int               lastIndex;
+
     /**
      * Construct an <code>AgendaGroup</code> with the given name.
      * 
@@ -68,12 +70,15 @@
                             final InternalRuleBase ruleBase) {
         this.name = name;
         Integer integer = (Integer) ruleBase.getAgendaGroupRuleTotals().get( name );
+           
         if ( integer == null ) {
             this.array = new LinkedList[0];
         } else {
             this.array = new LinkedList[integer.intValue()];    
         }
-        
+
+        this.index = this.array.length-1; 
+        this.lastIndex = 0;        
     }
 
     /* (non-Javadoc)
@@ -97,8 +102,17 @@
     public void add(final Activation activation) {
         AgendaItem item = (AgendaItem) activation;
         this.size++;
-
-        LinkedList list = this.array[item.getSequenence()];
+        int seq = item.getSequenence();
+        
+        if ( seq < this.index ) {
+            this.index = seq;
+        }
+        
+        if ( seq > this.lastIndex ) {
+            this.lastIndex = seq;
+        }
+        
+        LinkedList list = this.array[seq];
         if ( list == null ) {
             list = new LinkedList();
             this.array[item.getSequenence()] = list;
@@ -109,8 +123,7 @@
 
     public Activation getNext() {
         Activation activation = null;
-        int length = this.array.length;
-        while ( this.index < length ) {
+        while ( this.index <= lastIndex ) {
             LinkedList list = this.array[this.index];            
             if ( list != null ) {
                 activation = (Activation) ((LinkedListEntry)list.removeFirst()).getObject();




More information about the jboss-svn-commits mailing list