directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: r761290 - in /directory/apacheds/branches/ldif-partition/core-avl/src/main/java/org/apache/directory/server/core/avltree: AvlTreeMapImpl.java AvlTreeMapNoDupsCursor.java SingletonOrOrderedSet.java
Date Thu, 02 Apr 2009 13:35:31 GMT
Author: akarasulu
Date: Thu Apr  2 13:35:31 2009
New Revision: 761290

URL: http://svn.apache.org/viewvc?rev=761290&view=rev
Log:
fixing a few issues with AvlTreeMapImpl due to use of SingletonOrOrderedSet - leaving remove
related issues

Modified:
    directory/apacheds/branches/ldif-partition/core-avl/src/main/java/org/apache/directory/server/core/avltree/AvlTreeMapImpl.java
    directory/apacheds/branches/ldif-partition/core-avl/src/main/java/org/apache/directory/server/core/avltree/AvlTreeMapNoDupsCursor.java
    directory/apacheds/branches/ldif-partition/core-avl/src/main/java/org/apache/directory/server/core/avltree/SingletonOrOrderedSet.java

Modified: directory/apacheds/branches/ldif-partition/core-avl/src/main/java/org/apache/directory/server/core/avltree/AvlTreeMapImpl.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/ldif-partition/core-avl/src/main/java/org/apache/directory/server/core/avltree/AvlTreeMapImpl.java?rev=761290&r1=761289&r2=761290&view=diff
==============================================================================
--- directory/apacheds/branches/ldif-partition/core-avl/src/main/java/org/apache/directory/server/core/avltree/AvlTreeMapImpl.java
(original)
+++ directory/apacheds/branches/ldif-partition/core-avl/src/main/java/org/apache/directory/server/core/avltree/AvlTreeMapImpl.java
Thu Apr  2 13:35:31 2009
@@ -24,6 +24,8 @@
 import java.util.Comparator;
 import java.util.List;
 
+import org.apache.directory.shared.ldap.NotImplementedException;
+
 
 /**
  * An AVL tree implementation with support to store both key and value.
@@ -94,7 +96,7 @@
     /* (non-Javadoc)
      * @see org.apache.directory.server.core.avltree.AvlTreeMap#insert(K, V)
      */
-    public K insert( K key, V value )
+    public V insert( K key, V value )
     {
         LinkedAvlMapNode<K,V> node, temp;
         LinkedAvlMapNode<K,V> parent = null;
@@ -129,9 +131,8 @@
                 }
                 else
                 {
-                    // replcae the existing value with the new value
-                    temp.value = value;
-                    return key;
+                    // replace the existing value with the new value
+                    return temp.value.setSingleton( value );
                 }
             }
             
@@ -165,26 +166,26 @@
     }
     
     
-    @SuppressWarnings("unchecked")
-    private K insertDupKey( K key, V value, LinkedAvlMapNode existingNode )
+    private V insertDupKey( K key, V value, LinkedAvlMapNode<K,V> existingNode )
     {
         AvlTree<V> dupsTree = null;
         
-        if( existingNode.value instanceof AvlTree )
+        if( existingNode.value.isOrderedSet() )
         {
-            dupsTree = ( AvlTree<V> ) existingNode.value;
+            dupsTree = existingNode.value.getOrderedSet();
         }
         else
         {
+            // create avlTree, insert singleton into it, then switch modes 
             dupsTree = new AvlTreeImpl<V>( valueComparator );
-            dupsTree.insert( ( V ) existingNode.value );
-            existingNode.value = dupsTree;
+            dupsTree.insert( existingNode.value.getSingleton() );
+            existingNode.value.switchToOrderedSet( dupsTree );
         }
         
         // check if value already exists
         if( dupsTree.find( value ) != null )
         {
-        	return key;
+        	return value;
         }
         
         // insert value into duplicate key holder
@@ -260,11 +261,16 @@
     }
     
     
+    public SingletonOrOrderedSet<V> remove( K key )
+    {
+        throw new NotImplementedException();
+    }
+    
+    
     /* (non-Javadoc)
      * @see org.apache.directory.server.core.avltree.AvlTreeMap#remove(K, V)
      */
-    @SuppressWarnings("unchecked")
-    public K remove( K key, V value )
+    public V remove( K key, V value )
     {
         LinkedAvlMapNode<K,V> temp = null;
         LinkedAvlMapNode<K,V> y = null;
@@ -283,9 +289,9 @@
         // check if the value matches
         if( value != null )
         {
-            if( temp.value instanceof AvlTree )
+            if( temp.value.isOrderedSet() )
             {
-                AvlTree<V> dupsTree = ( AvlTree<V> ) temp.value;
+                AvlTree<V> dupsTree = temp.value.getOrderedSet();
                 V removedVal = dupsTree.remove( value );
                 
                 // if the removal is successful and the tree is not empty
@@ -296,12 +302,12 @@
                 // further down in this function
                 if( ( removedVal != null ) && ! dupsTree.isEmpty() )
                 {
-                    return key;//no need to balance
+                    return value;//no need to balance
                 }
             }
             else
             {
-                if( valueComparator.compare( temp.value, value ) != 0 )
+                if( valueComparator.compare( temp.value.getSingleton(), value ) != 0 )
                 {
                     return null;// no need to balance
                 }
@@ -309,7 +315,7 @@
         }
         
         // remove from the doubly linked
-        removeFromList(temp);        
+        removeFromList( temp );        
         
         if( temp.isLeaf() )
         {
@@ -878,7 +884,6 @@
     /* (non-Javadoc)
      * @see org.apache.directory.server.core.avltree.AvlTreeMap#find(K, V)
      */
-    @SuppressWarnings("unchecked")
     public LinkedAvlMapNode<K,V> find( K key, V value )
     {
         if( key == null || value == null )
@@ -886,16 +891,16 @@
             return null;
         }
         
-        LinkedAvlMapNode<K,V> node = find( key, root);
+        LinkedAvlMapNode<K,V> node = find( key, root );
         
         if( node == null )
         {
             return null;
         }
         
-        if( node.value instanceof AvlTree )
+        if( node.value.isOrderedSet() )
         {
-            AvlTree<V> dupsTree = ( AvlTree<V> ) node.value;
+            AvlTree<V> dupsTree = node.value.getOrderedSet();
             
             if( dupsTree.find( value ) == null )
             {
@@ -904,7 +909,7 @@
         }
         else
         {
-            if( valueComparator.compare( node.value, value ) != 0 )
+            if( valueComparator.compare( node.value.getSingleton(), value ) != 0 )
             {
                 return null;
             }

Modified: directory/apacheds/branches/ldif-partition/core-avl/src/main/java/org/apache/directory/server/core/avltree/AvlTreeMapNoDupsCursor.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/ldif-partition/core-avl/src/main/java/org/apache/directory/server/core/avltree/AvlTreeMapNoDupsCursor.java?rev=761290&r1=761289&r2=761290&view=diff
==============================================================================
--- directory/apacheds/branches/ldif-partition/core-avl/src/main/java/org/apache/directory/server/core/avltree/AvlTreeMapNoDupsCursor.java
(original)
+++ directory/apacheds/branches/ldif-partition/core-avl/src/main/java/org/apache/directory/server/core/avltree/AvlTreeMapNoDupsCursor.java
Thu Apr  2 13:35:31 2009
@@ -100,7 +100,7 @@
         if ( onNode )
         {
             returnedTuple.setKey( node.key );
-            returnedTuple.setValue( node.value );
+            returnedTuple.setValue( node.value.getSingleton() );
             return returnedTuple;
         }
         

Modified: directory/apacheds/branches/ldif-partition/core-avl/src/main/java/org/apache/directory/server/core/avltree/SingletonOrOrderedSet.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/ldif-partition/core-avl/src/main/java/org/apache/directory/server/core/avltree/SingletonOrOrderedSet.java?rev=761290&r1=761289&r2=761290&view=diff
==============================================================================
--- directory/apacheds/branches/ldif-partition/core-avl/src/main/java/org/apache/directory/server/core/avltree/SingletonOrOrderedSet.java
(original)
+++ directory/apacheds/branches/ldif-partition/core-avl/src/main/java/org/apache/directory/server/core/avltree/SingletonOrOrderedSet.java
Thu Apr  2 13:35:31 2009
@@ -86,6 +86,23 @@
         return orderedSet != null;
     }
     
+
+    /**
+     * Gets the singleton value.
+     *
+     * @return the singleton value
+     * @exception RuntimeException if not in singleton mode
+     */
+    public V getSingleton()
+    {
+        if ( singleton != null )
+        {
+            return singleton;
+        }
+        
+        throw new RuntimeException( "Cannot request singleton when in ordered set mode."
);
+    }
+    
     
     /**
      * Sets the singleton if in singleton mode.
@@ -140,6 +157,23 @@
     
     
     /**
+     * Gets the ordered set.
+     * 
+     * @return the ordered set
+     * @exception RuntimeException if in singleton mode
+     */
+    public AvlTree<V> getOrderedSet()
+    {
+        if ( orderedSet != null )
+        {
+            return orderedSet;
+        }
+        
+        throw new RuntimeException( "Cannot get ordered set in singleton mode." );
+    }
+    
+    
+    /**
      * Sets the set of ordered values.
      *
      * @param orderedSet the set of ordered values to use



Mime
View raw message