directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: r620591 - /directory/sandbox/akarasulu/bigbang/apacheds/core-splay/src/main/java/org/apache/directory/server/core/splay/SplayTree.java
Date Mon, 11 Feb 2008 19:40:51 GMT
Author: akarasulu
Date: Mon Feb 11 11:40:50 2008
New Revision: 620591

URL: http://svn.apache.org/viewvc?rev=620591&view=rev
Log:
DIRSERVER-1130: Applying patch from Kiran Ayyagari for splay tree print function

Modified:
    directory/sandbox/akarasulu/bigbang/apacheds/core-splay/src/main/java/org/apache/directory/server/core/splay/SplayTree.java

Modified: directory/sandbox/akarasulu/bigbang/apacheds/core-splay/src/main/java/org/apache/directory/server/core/splay/SplayTree.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/bigbang/apacheds/core-splay/src/main/java/org/apache/directory/server/core/splay/SplayTree.java?rev=620591&r1=620590&r2=620591&view=diff
==============================================================================
--- directory/sandbox/akarasulu/bigbang/apacheds/core-splay/src/main/java/org/apache/directory/server/core/splay/SplayTree.java
(original)
+++ directory/sandbox/akarasulu/bigbang/apacheds/core-splay/src/main/java/org/apache/directory/server/core/splay/SplayTree.java
Mon Feb 11 11:40:50 2008
@@ -285,7 +285,62 @@
     }
 
 
-    // test code stolen from Weiss
+    public LinkedBinaryNode<K> getRoot() {
+		return root;
+	}
+
+
+    /**
+     * Prints the contents of splay tree in pretty format
+     */
+    public void printTree() {
+    	
+    	if( isEmpty() )
+    	{
+    		System.out.println( "Tree is empty" );
+    		return;
+    	}
+    	
+		getRoot().setDepth( 0 );
+
+		System.out.println( getRoot() );
+		
+		visit( getRoot().getRight(), getRoot() );
+		
+		visit( getRoot().getLeft(), getRoot() );
+	}
+	
+	private void visit( LinkedBinaryNode<K> node, LinkedBinaryNode<K> parentNode
) 
+	{
+		if( node == null )
+		{
+			return;
+		}
+		
+		if( !node.isLeaf() )
+		{
+			node.setDepth( parentNode.getDepth() + 1 );
+		}
+		
+		for( int i=0; i < parentNode.getDepth(); i++ )
+		{
+			System.out.print( "|  " );
+		}
+
+		System.out.println( "|--" + node );
+		
+		if ( node.getRight() != null )
+		{
+			visit( node.getRight(), node );
+		}
+		
+		if( node.getLeft() != null )
+		{
+			visit( node.getLeft(), node );
+		}
+	}
+
+	// test code stolen from Weiss
     public static void main( String[] args )
     {
         SplayTree<Integer> t = new SplayTree<Integer>( new Comparator<Integer>()




Mime
View raw message