directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kayyag...@apache.org
Subject svn commit: r811674 - in /directory/apacheds/branches/apacheds-schema/core-avl/src/main/java/org/apache/directory/server/core/avltree: AvlTreeImpl.java AvlTreeMapImpl.java
Date Sat, 05 Sep 2009 16:40:23 GMT
Author: kayyagari
Date: Sat Sep  5 16:40:23 2009
New Revision: 811674

URL: http://svn.apache.org/viewvc?rev=811674&view=rev
Log:
o added a new variable to keep track of size
o updated the inefficient getSize() method

Modified:
    directory/apacheds/branches/apacheds-schema/core-avl/src/main/java/org/apache/directory/server/core/avltree/AvlTreeImpl.java
    directory/apacheds/branches/apacheds-schema/core-avl/src/main/java/org/apache/directory/server/core/avltree/AvlTreeMapImpl.java

Modified: directory/apacheds/branches/apacheds-schema/core-avl/src/main/java/org/apache/directory/server/core/avltree/AvlTreeImpl.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-schema/core-avl/src/main/java/org/apache/directory/server/core/avltree/AvlTreeImpl.java?rev=811674&r1=811673&r2=811674&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-schema/core-avl/src/main/java/org/apache/directory/server/core/avltree/AvlTreeImpl.java
(original)
+++ directory/apacheds/branches/apacheds-schema/core-avl/src/main/java/org/apache/directory/server/core/avltree/AvlTreeImpl.java
Sat Sep  5 16:40:23 2009
@@ -45,6 +45,8 @@
     /** node representing the end of the doubly linked list formed with the tree nodes */
     private LinkedAvlNode<K> last;
 
+    /** size of the tree */
+    private int size;
 
     /**
      * Creates a new instance of AVLTree.
@@ -80,6 +82,7 @@
           root = new LinkedAvlNode<K>( key );
           first = root;
           last = root;
+          size++;
           return null;
         }
         
@@ -127,6 +130,7 @@
         treePath.add( 0, node );
         balance(treePath);
         
+        size++;
         return null;
     }
     
@@ -224,6 +228,7 @@
             if( temp == root )
             {
               root = null;
+              size--;
               return key;
             }
             
@@ -297,6 +302,7 @@
        treePath.add( 0, y ); // y can be null but getBalance returns 0 so np
        balance( treePath );
        
+       size--;
        return key;
     }
     
@@ -375,26 +381,6 @@
     //NOTE: This method is internally used by AVLTreeMarshaller
     public int getSize()
     {
-        if ( root == null )
-        {
-            return 0;
-        }
-        
-        if( root.isLeaf() )
-        {
-            return 1;
-        }
-      
-        int size = 0;
-        
-        LinkedAvlNode<K> x = first;
-        
-        while( x != null )
-        {
-            size++;
-            x = x.next;
-        }
-        
         return size;
     }
     

Modified: directory/apacheds/branches/apacheds-schema/core-avl/src/main/java/org/apache/directory/server/core/avltree/AvlTreeMapImpl.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-schema/core-avl/src/main/java/org/apache/directory/server/core/avltree/AvlTreeMapImpl.java?rev=811674&r1=811673&r2=811674&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-schema/core-avl/src/main/java/org/apache/directory/server/core/avltree/AvlTreeMapImpl.java
(original)
+++ directory/apacheds/branches/apacheds-schema/core-avl/src/main/java/org/apache/directory/server/core/avltree/AvlTreeMapImpl.java
Sat Sep  5 16:40:23 2009
@@ -53,6 +53,8 @@
     /** flag to allow storing duplicate keys */
     private boolean allowDuplicates;
 
+    /** size of the map */
+    private int size;
 
     /**
      * Creates a new instance of AVLTreeMap without support for duplicate keys.
@@ -105,6 +107,7 @@
           root = new LinkedAvlMapNode<K,V>( key, value );
           first = root;
           last = root;
+          size++;
           return null;
         }
         
@@ -160,6 +163,7 @@
         treePath.add( 0, node );
         balance(treePath);
         
+        size++;
         return null;
     }
     
@@ -291,6 +295,7 @@
             balanceNodesAfterRemove( treePath, temp );
         }
         
+        size--;
        return temp.value;
     }
     
@@ -366,12 +371,14 @@
             {
                 root = null;
             }
-            
+       
+            size--;
             return value;
         }
 
        balanceNodesAfterRemove( treePath, temp );
-        
+
+       size--;
        return value;
     }
 
@@ -538,25 +545,6 @@
     //NOTE: This method is internally used by AVLTreeMarshaller
     public int getSize()
     {
-        if ( root == null )
-        {
-            return 0;
-        }
-        
-        if( root.isLeaf() )
-        {
-            return 1;
-        }
-      
-        int size = 0;
-        LinkedAvlMapNode<K,V> x = first;
-      
-        while( x != null )
-        {
-            size++;
-            x = x.next;
-        }
-      
         return size;
     }
     



Mime
View raw message