directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: r761264 - in /directory/apacheds/branches/ldif-partition/core-avl/src/main/java/org/apache/directory/server/core/avltree: AvlTreeMap.java LinkedAvlMapNode.java SingletonOrOrderedSet.java
Date Thu, 02 Apr 2009 12:21:41 GMT
Author: akarasulu
Date: Thu Apr  2 12:21:41 2009
New Revision: 761264

URL: http://svn.apache.org/viewvc?rev=761264&view=rev
Log:
experimental idea with dual mode value object usign in AvlTreeMap and LinkedAvlMapNode called
SingletonOrOrderedSet

Added:
    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/AvlTreeMap.java
    directory/apacheds/branches/ldif-partition/core-avl/src/main/java/org/apache/directory/server/core/avltree/LinkedAvlMapNode.java

Modified: directory/apacheds/branches/ldif-partition/core-avl/src/main/java/org/apache/directory/server/core/avltree/AvlTreeMap.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/ldif-partition/core-avl/src/main/java/org/apache/directory/server/core/avltree/AvlTreeMap.java?rev=761264&r1=761263&r2=761264&view=diff
==============================================================================
--- directory/apacheds/branches/ldif-partition/core-avl/src/main/java/org/apache/directory/server/core/avltree/AvlTreeMap.java
(original)
+++ directory/apacheds/branches/ldif-partition/core-avl/src/main/java/org/apache/directory/server/core/avltree/AvlTreeMap.java
Thu Apr  2 12:21:41 2009
@@ -11,13 +11,13 @@
     /**
      * @return the key comparator associated with this tree 
      */
-    public abstract Comparator<K> getKeyComparator();
+    Comparator<K> getKeyComparator();
 
 
     /**
      * @return the value comparator associated with this tree 
      */
-    public abstract Comparator<V> getValueComparator();
+    Comparator<V> getValueComparator();
 
 
     /**
@@ -27,7 +27,7 @@
      * @return the replaced key if it already exists
      * Note: Replaces a nodes value if duplicate keys are not allowed.
      */
-    public abstract K insert( K key, V value );
+    V insert( K key, V value );
 
 
     /**
@@ -38,15 +38,19 @@
      *              including any values having the same key
      * @return the removed key, if any, or null if the key does not exist
      */
-    public abstract K remove( K key, V value );
+    V remove( K key, V value );
 
+    
+    // ------ NEW ------
+    SingletonOrOrderedSet<V> remove( K key );
 
+    
     /**
      * Tests if the tree is logically empty.
      * 
      * @return true if the tree is empty, false otherwise
      */
-    public abstract boolean isEmpty();
+    boolean isEmpty();
 
 
     /**
@@ -54,39 +58,38 @@
      * 
      * @return the number of nodes present in this tree
      */
-    //NOTE: This method is internally used by AVLTreeMarshaller
-    public abstract int getSize();
+    int getSize();
 
 
     /**
-     * @return the root element of this tree (ie, not the first, but the
+     * @return the root element of this tree (i.e., not the first, but the
      * topmost element)
      */
-    public abstract LinkedAvlMapNode<K, V> getRoot();
+    LinkedAvlMapNode<K, V> getRoot();
 
 
     /**
      * @return a list of the stored keys in this tree
      */
-    public abstract List<K> getKeys();
+    List<K> getKeys();
 
 
     /**
      * Prints the contents of AVL tree in pretty format
      */
-    public abstract void printTree();
+    void printTree();
 
 
     /**
      * @return The first element of this tree
      */
-    public abstract LinkedAvlMapNode<K, V> getFirst();
+    LinkedAvlMapNode<K, V> getFirst();
 
 
     /**
      * @return The last element in this tree
      */
-    public abstract LinkedAvlMapNode<K, V> getLast();
+    LinkedAvlMapNode<K, V> getLast();
 
 
     /**
@@ -96,7 +99,7 @@
      * @return the LinkedAvlMapNode<K,V> whose key is greater than the given key ,<br>
      *         null if there is no node with a higher key than the given key.
      */
-    public abstract LinkedAvlMapNode<K, V> findGreater( K key );
+    LinkedAvlMapNode<K, V> findGreater( K key );
 
 
     /**
@@ -106,7 +109,7 @@
      * @return the LinkedAvlMapNode<K,V> whose key is greater than the given key ,<br>
      *         null if there is no node with a higher key than the given key.
      */
-    public abstract LinkedAvlMapNode<K, V> findGreaterOrEqual( K key );
+    LinkedAvlMapNode<K, V> findGreaterOrEqual( K key );
 
 
     /**
@@ -116,7 +119,7 @@
      * @return the LinkedAvlMapNode<K,V> whose key is lower than the given key ,<br>
      *         null if there is no node with a lower key than the given key.
      */
-    public abstract LinkedAvlMapNode<K, V> findLess( K key );
+    LinkedAvlMapNode<K, V> findLess( K key );
 
 
     /**
@@ -126,7 +129,7 @@
      * @return the LinkedAvlMapNode<K,V> whose key is lower than the given key ,<br>
      *         null if there is no node with a lower key than the given key.
      */
-    public abstract LinkedAvlMapNode<K, V> findLessOrEqual( K key );
+    LinkedAvlMapNode<K, V> findLessOrEqual( K key );
 
 
     /**
@@ -136,12 +139,12 @@
      * @param key the key to find
      * @return the list of traversed LinkedAvlNode.
      */
-    public abstract LinkedAvlMapNode<K, V> find( K key );
+    LinkedAvlMapNode<K, V> find( K key );
 
 
-    public abstract LinkedAvlMapNode<K, V> find( K key, V value );
+    LinkedAvlMapNode<K, V> find( K key, V value );
 
 
-    public abstract boolean isDupsAllowed();
+    boolean isDupsAllowed();
 
 }
\ No newline at end of file

Modified: directory/apacheds/branches/ldif-partition/core-avl/src/main/java/org/apache/directory/server/core/avltree/LinkedAvlMapNode.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/ldif-partition/core-avl/src/main/java/org/apache/directory/server/core/avltree/LinkedAvlMapNode.java?rev=761264&r1=761263&r2=761264&view=diff
==============================================================================
--- directory/apacheds/branches/ldif-partition/core-avl/src/main/java/org/apache/directory/server/core/avltree/LinkedAvlMapNode.java
(original)
+++ directory/apacheds/branches/ldif-partition/core-avl/src/main/java/org/apache/directory/server/core/avltree/LinkedAvlMapNode.java
Thu Apr  2 12:21:41 2009
@@ -32,7 +32,7 @@
     K key;
     
     /** the value stored in the node */
-    V value;
+    SingletonOrOrderedSet<V> value;
 
     /** The left child */
     LinkedAvlMapNode<K, V> left;
@@ -61,7 +61,7 @@
     public LinkedAvlMapNode( K theKey, V theValue )
     {
         key = theKey;
-        value = theValue;
+        value = new SingletonOrOrderedSet<V>( theValue );
         left = null;
         right = null;
     }
@@ -109,7 +109,7 @@
     }
 
 
-    public V getValue()
+    public SingletonOrOrderedSet<V> getValue()
     {
         return value;
     }

Added: 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=761264&view=auto
==============================================================================
--- directory/apacheds/branches/ldif-partition/core-avl/src/main/java/org/apache/directory/server/core/avltree/SingletonOrOrderedSet.java
(added)
+++ directory/apacheds/branches/ldif-partition/core-avl/src/main/java/org/apache/directory/server/core/avltree/SingletonOrOrderedSet.java
Thu Apr  2 12:21:41 2009
@@ -0,0 +1,193 @@
+/*
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *   or more contributor license agreements.  See the NOTICE file
+ *   distributed with this work for additional information
+ *   regarding copyright ownership.  The ASF licenses this file
+ *   to you under the Apache License, Version 2.0 (the
+ *   "License"); you may not use this file except in compliance
+ *   with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing,
+ *   software distributed under the License is distributed on an
+ *   "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *   KIND, either express or implied.  See the License for the
+ *   specific language governing permissions and limitations
+ *   under the License.
+ *
+ */
+package org.apache.directory.server.core.avltree;
+
+
+/**
+ * Stores either a single object or many of them in an AvlTree.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class SingletonOrOrderedSet<V>
+{
+    private V singleton;
+    private AvlTree<V> orderedSet;
+    
+    
+    /**
+     * Creates a new instance of SingletonOrOrderedSet with a singleton value.
+     *
+     * @param singleton the singleton value
+     */
+    public SingletonOrOrderedSet( V singleton )
+    {
+        if ( singleton == null )
+        {
+            throw new NullPointerException( "singleton must not be null" );
+        }
+        
+        this.singleton = singleton;
+    }
+    
+    
+    /**
+     * Creates a new instance of SingletonOrOrderedSet with a set of ordered 
+     * values.
+     *
+     * @param orderedSet the set of ordered values
+     */
+    public SingletonOrOrderedSet( AvlTree<V> orderedSet )
+    {
+        if ( orderedSet == null )
+        {
+            throw new NullPointerException( "orderedSet must not be null" );
+        }
+        
+        this.orderedSet = orderedSet;
+    }
+    
+
+    /**
+     * Gets whether or not the stored value is a singleton.
+     *
+     * @return true if in singleton mode, false otherwise
+     */
+    public boolean isSingleton()
+    {
+        return singleton != null;
+    }
+    
+    
+    /**
+     * Gets whether or not the stored value is an ordered set.
+     * 
+     * @return true if in ordered set mode, false otherwise
+     */
+    public boolean isOrderedSet()
+    {
+        return orderedSet != null;
+    }
+    
+    
+    /**
+     * Sets the singleton if in singleton mode.
+     *
+     * @param singleton the singleton value to set
+     * @return old single value
+     */
+    public V setSingleton( V singleton )
+    {
+        if ( singleton == null )
+        {
+            throw new NullPointerException( "singleton must not be null" );
+        }
+        
+        if ( this.orderedSet != null )
+        {
+            throw new RuntimeException( "Cannot set a singleton when using multiple values:
" +
+            		"use switchToSingleton()" );
+        }
+        
+        V retval = this.singleton;
+        this.singleton = singleton;
+        return retval;
+    }
+    
+    
+    /**
+     * Switches from orderedSet mode to singleton mode, while returning the 
+     * ordered set of values before removing them forever.
+     *
+     * @param singleton the singleton value
+     * @return the set of ordered values before nulling it out
+     * @exception RuntimeException if already in singleton mode
+     */
+    public AvlTree<V> switchToSingleton( V singleton )
+    {
+        if ( singleton == null )
+        {
+            throw new NullPointerException( "singleton must not be null" );
+        }
+        
+        if ( this.singleton != null )
+        {
+            throw new RuntimeException( "Already in singleton mode." );
+        }
+        
+        AvlTree<V> retval = this.orderedSet;
+        this.orderedSet = null;
+        this.singleton = singleton;
+        return retval;
+    }
+    
+    
+    /**
+     * Sets the set of ordered values.
+     *
+     * @param orderedSet the set of ordered values to use
+     * @return the old set of ordered values
+     * @exception RuntimeException if in singleton mode
+     */
+    public AvlTree<V> setOrderedSet( AvlTree<V> orderedSet )
+    {
+        if ( orderedSet == null )
+        {
+            throw new NullPointerException( "orderedSet must not be null" );
+        }
+        
+        if ( this.singleton != null )
+        {
+            throw new RuntimeException( "Cannot set a orderedSet when in singleton mode:
" +
+                    "use switchToSingleValue()" );
+        }
+        
+        AvlTree<V> retval = this.orderedSet;
+        this.orderedSet = orderedSet;
+        return retval;
+    }
+    
+    
+    /**
+     * Switches from orderedSet mode to singleton mode, while returning the 
+     * singleton value before removing it forever.
+     *
+     * @param orderedSet the AvlTree to use for orderedSet of values
+     * @return the singleton to return before nulling it out
+     * @throws RuntimeException if the mode is already in orderedSet mode.
+     */
+    public V switchToOrderedSet( AvlTree<V> orderedSet )
+    {
+        if ( orderedSet == null )
+        {
+            throw new NullPointerException( "orderedSet must not be null" );
+        }
+        
+        if ( this.orderedSet != null )
+        {
+            throw new RuntimeException( "Already in ordered set mode." );
+        }
+        
+        V retval = this.singleton;
+        this.orderedSet = orderedSet;
+        this.singleton = null;
+        return retval;
+    }
+}



Mime
View raw message