directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kayyag...@apache.org
Subject svn commit: r998494 - in /directory/apacheds/trunk/core-avl/src: main/java/org/apache/directory/server/core/avltree/AvlTreeMapImpl.java test/java/org/apache/directory/server/core/avltree/AvlTreeMapTest.java
Date Sat, 18 Sep 2010 16:47:55 GMT
Author: kayyagari
Date: Sat Sep 18 16:47:55 2010
New Revision: 998494

URL: http://svn.apache.org/viewvc?rev=998494&view=rev
Log:
o added a method to remove all the nodes from a tree and a associated test case
o removed some empty blocks from the test class

Modified:
    directory/apacheds/trunk/core-avl/src/main/java/org/apache/directory/server/core/avltree/AvlTreeMapImpl.java
    directory/apacheds/trunk/core-avl/src/test/java/org/apache/directory/server/core/avltree/AvlTreeMapTest.java

Modified: directory/apacheds/trunk/core-avl/src/main/java/org/apache/directory/server/core/avltree/AvlTreeMapImpl.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-avl/src/main/java/org/apache/directory/server/core/avltree/AvlTreeMapImpl.java?rev=998494&r1=998493&r2=998494&view=diff
==============================================================================
--- directory/apacheds/trunk/core-avl/src/main/java/org/apache/directory/server/core/avltree/AvlTreeMapImpl.java
(original)
+++ directory/apacheds/trunk/core-avl/src/main/java/org/apache/directory/server/core/avltree/AvlTreeMapImpl.java
Sat Sep 18 16:47:55 2010
@@ -1138,4 +1138,24 @@ public class AvlTreeMapImpl<K, V> implem
     {
         return allowDuplicates;
     }
+    
+    
+    /**
+     * removes all the nodes from the tree
+     */
+    public void removeAll()
+    {
+        LinkedAvlMapNode<K, V> tmp;
+        
+        while ( first != null )
+        {
+            tmp = first;
+            first = tmp.next;
+            tmp = null;
+        }
+
+        last = null;
+        root = null;
+        size = 0;
+    }
 }

Modified: directory/apacheds/trunk/core-avl/src/test/java/org/apache/directory/server/core/avltree/AvlTreeMapTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-avl/src/test/java/org/apache/directory/server/core/avltree/AvlTreeMapTest.java?rev=998494&r1=998493&r2=998494&view=diff
==============================================================================
--- directory/apacheds/trunk/core-avl/src/test/java/org/apache/directory/server/core/avltree/AvlTreeMapTest.java
(original)
+++ directory/apacheds/trunk/core-avl/src/test/java/org/apache/directory/server/core/avltree/AvlTreeMapTest.java
Sat Sep 18 16:47:55 2010
@@ -62,7 +62,7 @@ public class AvlTreeMapTest
     };
 
     
-    private AvlTreeMap<Integer, Integer> createTree()
+    private AvlTreeMapImpl<Integer, Integer> createTree()
     {
         return new AvlTreeMapImpl<Integer, Integer>( comparator, comparator, true );
     }
@@ -160,16 +160,8 @@ public class AvlTreeMapTest
         tree.insert( 28, 4 );
         tree.insert( 26, 5 );
 
-        if ( LOG.isDebugEnabled() )
-        {
-            
-        }
-
         tree.remove( 24, 3 ); // this causes a single left rotation on node with key 12
-        if ( LOG.isDebugEnabled() )
-        {
-            
-        }
+
         assertTrue( tree.getRoot().getLeft().key == 26 );
     }
 
@@ -386,6 +378,32 @@ public class AvlTreeMapTest
     }
 
     
+    @Test
+    public void testRemoveAll()
+    {
+        AvlTreeMapImpl<Integer, Integer> tree = createTree();
+        assertNull( tree.insert( 3, 1 ) );
+        tree.insert( 37, 2 );
+
+        assertFalse( tree.isEmpty() );
+        assertEquals( 2, tree.getSize() );
+        
+        tree.removeAll();
+        
+        assertTrue( tree.isEmpty() );
+        assertEquals( 0, tree.getSize() );
+        assertNull( tree.getFirst() );
+        assertNull( tree.getLast() );
+        assertNull( tree.getRoot() );
+        
+        // re-insert
+        assertNull( tree.insert( 3, 1 ) );
+        tree.insert( 37, 2 );
+        assertFalse( tree.isEmpty() );
+        assertEquals( 2, tree.getSize() );
+    }
+
+    
     private String getInorderForm( AvlTreeMap<Integer, Integer> tree )
     {
       StringBuilder sb = new StringBuilder();



Mime
View raw message