directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: r762158 - /directory/apacheds/branches/ldif-partition/ldif-partition/src/main/java/org/apache/directory/server/core/partition/ldif/
Date Sun, 05 Apr 2009 21:20:11 GMT
Author: akarasulu
Date: Sun Apr  5 21:20:11 2009
New Revision: 762158

URL: http://svn.apache.org/viewvc?rev=762158&view=rev
Log:
moving stuff over after apachecon

Added:
    directory/apacheds/branches/ldif-partition/ldif-partition/src/main/java/org/apache/directory/server/core/partition/ldif/
    directory/apacheds/branches/ldif-partition/ldif-partition/src/main/java/org/apache/directory/server/core/partition/ldif/AvlTable.java
    directory/apacheds/branches/ldif-partition/ldif-partition/src/main/java/org/apache/directory/server/core/partition/ldif/DupsAvlCursor.java
    directory/apacheds/branches/ldif-partition/ldif-partition/src/main/java/org/apache/directory/server/core/partition/ldif/DupsAvlTable.java
    directory/apacheds/branches/ldif-partition/ldif-partition/src/main/java/org/apache/directory/server/core/partition/ldif/DupsAvlTupleComparator.java
    directory/apacheds/branches/ldif-partition/ldif-partition/src/main/java/org/apache/directory/server/core/partition/ldif/NoDupsAvlTable.java
    directory/apacheds/branches/ldif-partition/ldif-partition/src/main/java/org/apache/directory/server/core/partition/ldif/NoDupsAvlTupleComparator.java

Added: directory/apacheds/branches/ldif-partition/ldif-partition/src/main/java/org/apache/directory/server/core/partition/ldif/AvlTable.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/ldif-partition/ldif-partition/src/main/java/org/apache/directory/server/core/partition/ldif/AvlTable.java?rev=762158&view=auto
==============================================================================
--- directory/apacheds/branches/ldif-partition/ldif-partition/src/main/java/org/apache/directory/server/core/partition/ldif/AvlTable.java
(added)
+++ directory/apacheds/branches/ldif-partition/ldif-partition/src/main/java/org/apache/directory/server/core/partition/ldif/AvlTable.java
Sun Apr  5 21:20:11 2009
@@ -0,0 +1,309 @@
+/*
+ *   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.partition.ldif;
+
+import java.util.Comparator;
+
+import org.apache.directory.server.core.avltree.AvlTree;
+import org.apache.directory.server.core.cursor.Cursor;
+import org.apache.directory.server.xdbm.Table;
+import org.apache.directory.server.xdbm.Tuple;
+
+
+/**
+ * A Table implementation backed by an in memory AVL Tree.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class AvlTable<K,V> implements Table<K, V>
+{
+    public final DupsAvlTable<K,V> dupsTable;
+    public final NoDupsAvlTable<K, V> noDupsTable;
+    public final boolean dupsEnabled;
+    
+    
+    public AvlTable( String name, Comparator<K> keyComparator, Comparator<V>
valueComparator,
+        boolean dupsEnabled )
+    {
+        this.dupsEnabled = dupsEnabled;
+        
+        if ( dupsEnabled )
+        {
+            dupsTable = new DupsAvlTable<K, V>( name, 
+                new DupsAvlTupleComparator<K, V>( keyComparator, valueComparator )
);
+            noDupsTable = null;
+        }
+        else
+        {
+            dupsTable = null;
+            noDupsTable = new NoDupsAvlTable<K, V>( 
+                new NoDupsAvlTupleComparator<K, V>( keyComparator, valueComparator
) );
+        }
+    }
+
+    
+    public void close() throws Exception
+    {
+    }
+
+    
+    public int count() throws Exception
+    {
+        if ( dupsEnabled )
+        {
+            return dupsTable.count();
+        }
+        
+        return noDupsTable.count();
+    }
+    
+
+    public int count( K key ) throws Exception
+    {
+        if ( dupsEnabled )
+        {
+            return dupsTable.count( key );
+        }
+        
+        return noDupsTable.count( key );
+    }
+
+    
+    public Cursor<Tuple<K, V>> cursor() throws Exception
+    {
+        if ( dupsEnabled )
+        {
+            return dupsTable.cursor();
+        }
+        
+        return noDupsTable.cursor();
+    }
+    
+
+    public Cursor<Tuple<K, V>> cursor( K key ) throws Exception
+    {
+        if ( dupsEnabled )
+        {
+            return dupsTable.cursor( key );
+        }
+        
+        return noDupsTable.cursor( key );
+    }
+
+    
+    public V get( K key ) throws Exception
+    {
+        if ( dupsEnabled )
+        {
+            return dupsTable.get( key ).getFirst().getKey();
+        }
+        
+        return noDupsTable.get( key );
+    }
+
+    
+    public Comparator<K> getKeyComparator()
+    {
+        if ( dupsEnabled )
+        {
+            return dupsTable.getKeyComparator();
+        }
+        
+        return noDupsTable.getKeyComparator();
+    }
+    
+
+    public String getName()
+    {
+        if ( dupsEnabled )
+        {
+            return dupsTable.getName();
+        }
+        
+        return noDupsTable.getName();
+    }
+    
+
+    public Comparator<V> getValueComparator()
+    {
+        if ( dupsEnabled )
+        {
+            return dupsTable.getValueComparator();
+        }
+        
+        return noDupsTable.getValueComparator();
+    }
+
+    
+    public int greaterThanCount( K key ) throws Exception
+    {
+        if ( dupsEnabled )
+        {
+            return dupsTable.greaterThanCount( key );
+        }
+        
+        return noDupsTable.greaterThanCount( key );
+    }
+
+    
+    public boolean has( K key ) throws Exception
+    {
+        if ( dupsEnabled )
+        {
+            return dupsTable.has( key );
+        }
+        
+        return noDupsTable.has( key );
+    }
+
+    
+    public boolean has( K key, V value ) throws Exception
+    {
+        if ( dupsEnabled )
+        {
+            AvlTree<V> secondary = dupsTable.get( key );
+            if ( secondary == null )
+            {
+                return false;
+            }
+            return secondary.find( value ) != null;
+        }
+        
+        return noDupsTable.has( key, value );
+    }
+
+    
+    public boolean hasGreaterOrEqual( K key ) throws Exception
+    {
+        if ( dupsEnabled )
+        {
+            return dupsTable.hasGreaterOrEqual( key );
+        }
+        
+        return noDupsTable.hasGreaterOrEqual( key );
+    }
+
+    
+    public boolean hasGreaterOrEqual( K key, V val ) throws Exception
+    {
+        if ( dupsEnabled )
+        {
+            return dupsTable.hasGreaterOrEqual( key, val );
+        }
+        
+        return noDupsTable.hasGreaterOrEqual( key, val );
+    }
+
+    
+    public boolean hasLessOrEqual( K key ) throws Exception
+    {
+        if ( dupsEnabled )
+        {
+            return dupsTable.hasLessOrEqual( key );
+        }
+        
+        return noDupsTable.hasLessOrEqual( key );
+    }
+    
+
+    public boolean hasLessOrEqual( K key, V val ) throws Exception
+    {
+        if ( dupsEnabled )
+        {
+            return dupsTable.hasLessOrEqual( key, val );
+        }
+        
+        return noDupsTable.hasLessOrEqual( key, val );
+    }
+    
+
+    public boolean isCountExact()
+    {
+        return false;
+    }
+
+    
+    public boolean isDupsEnabled()
+    {
+        return dupsEnabled;
+    }
+
+    
+    public int lessThanCount( K key ) throws Exception
+    {
+        if ( dupsEnabled )
+        {
+            return dupsTable.lessThanCount( key );
+        }
+        
+        return noDupsTable.lessThanCount( key );
+    }
+
+    
+    public void put( K key, V value ) throws Exception
+    {
+        if ( dupsEnabled )
+        {
+            dupsTable.put( key, value );
+        }
+        else
+        {
+            noDupsTable.put( key, value );
+        }
+    }
+
+    
+    public void remove( K key ) throws Exception
+    {
+        if ( dupsEnabled )
+        {
+            dupsTable.remove( key );
+        }
+        else
+        {
+            noDupsTable.remove( key );
+        }
+    }
+
+    
+    public void remove( K key, V value ) throws Exception
+    {
+        if ( dupsEnabled )
+        {
+            dupsTable.remove( key, value );
+        }
+        else
+        {
+            return noDupsTable.remove( key, value );
+        }
+    }
+
+    
+    public Cursor<V> valueCursor( K key ) throws Exception
+    {
+        if ( dupsEnabled )
+        {
+            return dupsTable.valueCursor( key );
+        }
+        
+        return noDupsTable.valueCursor( key );
+    }
+}

Added: directory/apacheds/branches/ldif-partition/ldif-partition/src/main/java/org/apache/directory/server/core/partition/ldif/DupsAvlCursor.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/ldif-partition/ldif-partition/src/main/java/org/apache/directory/server/core/partition/ldif/DupsAvlCursor.java?rev=762158&view=auto
==============================================================================
--- directory/apacheds/branches/ldif-partition/ldif-partition/src/main/java/org/apache/directory/server/core/partition/ldif/DupsAvlCursor.java
(added)
+++ directory/apacheds/branches/ldif-partition/ldif-partition/src/main/java/org/apache/directory/server/core/partition/ldif/DupsAvlCursor.java
Sun Apr  5 21:20:11 2009
@@ -0,0 +1,147 @@
+/*
+ *   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.partition.ldif;
+
+
+import java.util.Iterator;
+
+import org.apache.directory.server.core.avltree.AvlTree;
+import org.apache.directory.server.core.cursor.ClosureMonitor;
+import org.apache.directory.server.core.cursor.Cursor;
+import org.apache.directory.server.xdbm.Tuple;
+
+
+/**
+ * A Cursor designed to scan a AvlTree which supports duplicates as if each
+ * duplicate key value was a single Tuple.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class DupsAvlCursor<K,V> implements Cursor<Tuple<K,V>>
+{
+    private final DupsAvlTable<K,V> table;
+    private K currentKey;
+    private Cursor<V> valueCursor;
+    
+    
+    public DupsAvlCursor( DupsAvlTable<K,V> table )
+    {
+        this.table = table;
+    }
+    
+
+    public void after( Tuple<K, V> element ) throws Exception
+    {
+        table.getAvlTree().findGreater( new Tuple<K,AvlTree<V>>( element.getKey(),
null ) );
+    }
+
+    
+    public void afterLast() throws Exception
+    {
+        // TODO Auto-generated method stub
+    }
+
+    
+    public boolean available()
+    {
+        // TODO Auto-generated method stub
+        return false;
+    }
+
+    public void before( Tuple<K, V> element ) throws Exception
+    {
+        // TODO Auto-generated method stub
+        
+    }
+
+    public void beforeFirst() throws Exception
+    {
+        // TODO Auto-generated method stub
+        
+    }
+
+    public void close() throws Exception
+    {
+        // TODO Auto-generated method stub
+        
+    }
+
+    public void close( Exception reason ) throws Exception
+    {
+        // TODO Auto-generated method stub
+        
+    }
+
+    public boolean first() throws Exception
+    {
+        // TODO Auto-generated method stub
+        return false;
+    }
+
+    public Tuple<K, V> get() throws Exception
+    {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    public boolean isClosed() throws Exception
+    {
+        // TODO Auto-generated method stub
+        return false;
+    }
+
+    public boolean isElementReused()
+    {
+        // TODO Auto-generated method stub
+        return false;
+    }
+
+    public boolean last() throws Exception
+    {
+        // TODO Auto-generated method stub
+        return false;
+    }
+
+    public boolean next() throws Exception
+    {
+        // TODO Auto-generated method stub
+        return false;
+    }
+
+    public boolean previous() throws Exception
+    {
+        // TODO Auto-generated method stub
+        return false;
+    }
+
+    public void setClosureMonitor( ClosureMonitor monitor )
+    {
+        // TODO Auto-generated method stub
+        
+    }
+
+    public Iterator<Tuple<K, V>> iterator()
+    {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+}

Added: directory/apacheds/branches/ldif-partition/ldif-partition/src/main/java/org/apache/directory/server/core/partition/ldif/DupsAvlTable.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/ldif-partition/ldif-partition/src/main/java/org/apache/directory/server/core/partition/ldif/DupsAvlTable.java?rev=762158&view=auto
==============================================================================
--- directory/apacheds/branches/ldif-partition/ldif-partition/src/main/java/org/apache/directory/server/core/partition/ldif/DupsAvlTable.java
(added)
+++ directory/apacheds/branches/ldif-partition/ldif-partition/src/main/java/org/apache/directory/server/core/partition/ldif/DupsAvlTable.java
Sun Apr  5 21:20:11 2009
@@ -0,0 +1,279 @@
+/*
+ *   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.partition.ldif;
+
+
+import java.util.Comparator;
+
+import org.apache.directory.server.core.avltree.AvlTree;
+import org.apache.directory.server.core.avltree.AvlTreeCursor;
+import org.apache.directory.server.core.avltree.LinkedAvlNode;
+import org.apache.directory.server.core.cursor.Cursor;
+import org.apache.directory.server.core.cursor.EmptyCursor;
+import org.apache.directory.server.core.cursor.SingletonCursor;
+import org.apache.directory.server.xdbm.Table;
+import org.apache.directory.server.xdbm.Tuple;
+
+
+/**
+ * A Table backed by in memory AVL Trees which allows for duplicates.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class DupsAvlTable<K,V> implements Table<K, AvlTree<V>>
+{
+    private final AvlTree<Tuple<K,AvlTree<V>>> avlTree;
+    private final Comparator<K> keyComparator;
+    private final Comparator<V> valueComparator;
+    private final String name;
+    private int count;
+    
+    
+    public DupsAvlTable( String name, DupsAvlTupleComparator<K,V> comparator )
+    {
+        this.name = name;
+        this.avlTree = new AvlTree<Tuple<K,AvlTree<V>>>( comparator );
+        this.keyComparator = comparator.getKeyComparator();
+        this.valueComparator = comparator.getValueComparator();
+    }
+    
+
+
+    public void close() throws Exception
+    {
+    }
+
+    
+    public int count() throws Exception
+    {
+        return count;
+    }
+
+    
+    public int count( K key ) throws Exception
+    {
+        LinkedAvlNode<Tuple<K,AvlTree<V>>> node = avlTree.find( new Tuple<K,AvlTree<V>>(
key, null ) );
+        
+        if ( node != null )
+        {
+            return node.getKey().getValue().getSize();
+        }
+        
+        return 0;
+    }
+
+    
+    public Cursor<Tuple<K, AvlTree<V>>> cursor() throws Exception
+    {
+        return new AvlTreeCursor<Tuple<K,AvlTree<V>>>( avlTree );
+    }
+
+    
+    public Cursor<Tuple<K, AvlTree<V>>> cursor( K key ) throws Exception
+    {
+        LinkedAvlNode<Tuple<K,AvlTree<V>>> node = avlTree.find( new Tuple<K,AvlTree<V>>(
key, null ) );
+        
+        if ( node == null )
+        {
+            return new EmptyCursor<Tuple<K,AvlTree<V>>>();
+        }
+        
+        return new SingletonCursor<Tuple<K,AvlTree<V>>>( node.getKey()
);
+    }
+
+    
+    public AvlTree<V> get( K key ) throws Exception
+    {
+        if ( key == null )
+        {
+            return null;
+        }
+        
+        LinkedAvlNode<Tuple<K,AvlTree<V>>> node = avlTree.find( new Tuple<K,AvlTree<V>>(
key, null ) );
+        
+        if ( node == null )
+        {
+            return null;
+        }
+        
+        return node.getKey().getValue();
+    }
+
+    
+    public Comparator<K> getKeyComparator()
+    {
+        return keyComparator;
+    }
+
+    
+    @SuppressWarnings("unchecked")
+    public Comparator<AvlTree<V>> getValueComparator()
+    {
+        return ( Comparator<AvlTree<V>> ) valueComparator;
+    }
+
+
+    public String getName()
+    {
+        return name;
+    }
+
+    
+    public int greaterThanCount( K key ) throws Exception
+    {
+        if ( key == null )
+        {
+            return 0;
+        }
+        
+        return count;
+    }
+
+    
+    public boolean has( K key ) throws Exception
+    {
+        if ( key == null )
+        {
+            return false;
+        }
+        
+        return avlTree.find( new Tuple<K,AvlTree<V>>( key, null ) ) != null;
+    }
+
+    
+    public boolean has( K key, AvlTree<V> value ) throws Exception
+    {
+        return has( key );
+    }
+
+    
+    public boolean hasGreaterOrEqual( K key ) throws Exception
+    {
+        return avlTree.findGreaterOrEqual( new Tuple<K,AvlTree<V>>( key, null
) ) != null;
+    }
+
+    
+    public boolean hasGreaterOrEqual( K key, AvlTree<V> val ) throws Exception
+    {
+        return avlTree.findGreaterOrEqual( new Tuple<K,AvlTree<V>>( key, null
) ) != null;
+    }
+
+    
+    public boolean hasLessOrEqual( K key ) throws Exception
+    {
+        return avlTree.findLessOrEqual( new Tuple<K,AvlTree<V>>( key, null )
) != null;
+    }
+
+    
+    public boolean hasLessOrEqual( K key, AvlTree<V> val ) throws Exception
+    {
+        return avlTree.findLessOrEqual( new Tuple<K,AvlTree<V>>( key, null )
) != null;
+    }
+
+    
+    public boolean isCountExact()
+    {
+        return false;
+    }
+
+    
+    public boolean isDupsEnabled()
+    {
+        return true;
+    }
+
+    
+    public int lessThanCount( K key ) throws Exception
+    {
+        return count;
+    }
+
+    
+    public void put( K key, AvlTree<V> value ) throws Exception
+    {
+        Tuple<K,AvlTree<V>> replaced = avlTree.insert( new Tuple<K, AvlTree<V>>(
key, value ) );
+        
+        if ( replaced != null )
+        {
+            count -= replaced.getValue().getSize();
+        }
+        
+        count += value.getSize();
+    }
+
+    
+    public void remove( K key ) throws Exception
+    {
+        Tuple<K,AvlTree<V>> removed = avlTree.remove( new Tuple<K, AvlTree<V>>(
key, null ) );
+        
+        if ( removed != null )
+        {
+            count -= removed.getValue().getSize();
+        }
+    }
+
+    
+    public void remove( K key, AvlTree<V> value ) throws Exception
+    {
+        LinkedAvlNode<Tuple<K,AvlTree<V>>> node = avlTree.find( new Tuple<K,
AvlTree<V>>( key, null ) );
+        
+        if ( node == null )
+        {
+            return;
+        }
+        
+        AvlTree<V> existing = node.getKey().getValue();
+        AvlTreeCursor<V> cursor = new AvlTreeCursor<V>( value );
+        
+        while ( cursor.next() )
+        {
+            V remove = cursor.get();
+            if ( existing.remove( remove ) != null )
+            {
+                count --;
+            }
+        }
+    }
+
+    
+    public Cursor<AvlTree<V>> valueCursor( K key ) throws Exception
+    {
+        LinkedAvlNode<Tuple<K,AvlTree<V>>> node = avlTree.find( new Tuple<K,
AvlTree<V>>( key, null ) );
+
+        if ( node == null )
+        {
+            return new EmptyCursor<AvlTree<V>>();
+        }
+        
+        return new SingletonCursor<AvlTree<V>>( node.getKey().getValue() );
+    }
+    
+    
+    /**
+     * Exposes access so some Cursor implementations can access the AvlTree.
+     *
+     * @return avlTree
+     */
+    AvlTree<Tuple<K,AvlTree<V>>> getAvlTree()
+    {
+        return avlTree;
+    }
+}

Added: directory/apacheds/branches/ldif-partition/ldif-partition/src/main/java/org/apache/directory/server/core/partition/ldif/DupsAvlTupleComparator.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/ldif-partition/ldif-partition/src/main/java/org/apache/directory/server/core/partition/ldif/DupsAvlTupleComparator.java?rev=762158&view=auto
==============================================================================
--- directory/apacheds/branches/ldif-partition/ldif-partition/src/main/java/org/apache/directory/server/core/partition/ldif/DupsAvlTupleComparator.java
(added)
+++ directory/apacheds/branches/ldif-partition/ldif-partition/src/main/java/org/apache/directory/server/core/partition/ldif/DupsAvlTupleComparator.java
Sun Apr  5 21:20:11 2009
@@ -0,0 +1,78 @@
+/*
+ *   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.partition.ldif;
+
+
+import java.util.Comparator;
+
+import org.apache.directory.server.core.avltree.AvlTree;
+import org.apache.directory.server.xdbm.Tuple;
+
+
+/**
+ * A pair of comparators used to order Tuples in a AvlTree.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class DupsAvlTupleComparator<K,V> implements Comparator<Tuple<K,AvlTree<V>>>
+{
+    private final Comparator<K> keyComparator;
+    private final Comparator<V> valueComparator;
+  
+    
+    public DupsAvlTupleComparator( Comparator<K> keyComparator, Comparator<V>
valueComparator )
+    {
+        this.keyComparator = keyComparator;
+        this.valueComparator = valueComparator;
+    }
+  
+    
+    public Comparator<K> getKeyComparator()
+    {
+        return keyComparator;
+    }
+    
+    
+    public Comparator<V> getValueComparator()
+    {
+        return valueComparator;
+    }
+    
+
+//    public int compare( Tuple<K, V> t1, Tuple<K, V> t2 )
+//    {
+//        int keyComp = keyComparator.compare( t1.getKey(), t2.getKey() );
+//        
+//        if ( keyComp == 0 )
+//        {
+//            return valueComparator.compare( t1.getValue(), t2.getValue() );
+//        }
+//        
+//        return keyComp;
+//    }
+
+
+    public int compare( Tuple<K, AvlTree<V>> o1, Tuple<K, AvlTree<V>>
o2 )
+    {
+        // TODO Auto-generated method stub
+        return 0;
+    }
+}

Added: directory/apacheds/branches/ldif-partition/ldif-partition/src/main/java/org/apache/directory/server/core/partition/ldif/NoDupsAvlTable.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/ldif-partition/ldif-partition/src/main/java/org/apache/directory/server/core/partition/ldif/NoDupsAvlTable.java?rev=762158&view=auto
==============================================================================
--- directory/apacheds/branches/ldif-partition/ldif-partition/src/main/java/org/apache/directory/server/core/partition/ldif/NoDupsAvlTable.java
(added)
+++ directory/apacheds/branches/ldif-partition/ldif-partition/src/main/java/org/apache/directory/server/core/partition/ldif/NoDupsAvlTable.java
Sun Apr  5 21:20:11 2009
@@ -0,0 +1,226 @@
+/*
+ *   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.partition.ldif;
+
+
+import java.util.Comparator;
+
+import org.apache.directory.server.core.avltree.AvlTree;
+import org.apache.directory.server.core.avltree.AvlTreeCursor;
+import org.apache.directory.server.core.avltree.LinkedAvlNode;
+import org.apache.directory.server.core.cursor.Cursor;
+import org.apache.directory.server.core.cursor.EmptyCursor;
+import org.apache.directory.server.core.cursor.SingletonCursor;
+import org.apache.directory.server.xdbm.Table;
+import org.apache.directory.server.xdbm.Tuple;
+
+
+/**
+ * A Table implementation that does not allow duplicate keys backed by in 
+ * memory AVL Trees.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class NoDupsAvlTable<K,V> implements Table<K, V>
+{
+    private final AvlTree<Tuple<K,V>> avlTree;
+    private final Comparator<K> keyComparator;
+    private final Comparator<V> valueComparator;
+    private String name;
+    
+    
+    public NoDupsAvlTable( NoDupsAvlTupleComparator<K,V> comparator )
+    {
+        this.avlTree = new AvlTree<Tuple<K,V>>( comparator );
+        this.keyComparator = comparator.getKeyComparator();
+        this.valueComparator = comparator.getValueComparator();
+    }
+    
+
+    public void close() throws Exception
+    {
+    }
+
+    
+    public int count() throws Exception
+    {
+        return avlTree.getSize();
+    }
+    
+
+    public int count( K key ) throws Exception
+    {
+        if ( avlTree.find( new Tuple<K,V>( key, null ) ) != null )
+        {
+            return 1;
+        }
+        
+        return 0;
+    }
+
+    
+    public Cursor<Tuple<K, V>> cursor() throws Exception
+    {
+        return new AvlTreeCursor<Tuple<K,V>>( avlTree );
+    }
+
+    
+    public Cursor<Tuple<K, V>> cursor( K key ) throws Exception
+    {
+        LinkedAvlNode<Tuple<K,V>> node = avlTree.find( new Tuple<K,V>(
key, null ) );
+        
+        if ( node == null )
+        {
+            return new EmptyCursor<Tuple<K,V>>();
+        }
+
+        return new SingletonCursor<Tuple<K,V>>( node.getKey() );
+    }
+
+    
+    public V get( K key ) throws Exception
+    {
+        LinkedAvlNode<Tuple<K,V>> node = avlTree.find( new Tuple<K,V>(
key, null ) );
+        
+        if ( node != null )
+        {
+            return node.getKey().getValue();
+        }
+        
+        return null;
+    }
+
+    
+    public String getName()
+    {
+        return name;
+    }
+
+    
+    public Comparator<K> getKeyComparator()
+    {
+        return keyComparator;
+    }
+
+    
+    public Comparator<V> getValueComparator()
+    {
+        return valueComparator;
+    }
+    
+
+    public int greaterThanCount( K key ) throws Exception
+    {
+        return avlTree.getSize();
+    }
+
+    
+    public boolean has( K key ) throws Exception
+    {
+        return avlTree.find( new Tuple<K,V>( key, null ) ) != null;
+    }
+
+    
+    public boolean has( K key, V value ) throws Exception
+    {
+        LinkedAvlNode<Tuple<K,V>> node = avlTree.find( new Tuple<K,V>(
key, value ) );
+        
+        if ( valueComparator.compare( value, node.getKey().getValue() ) == 0 )
+        {
+            return true;
+        }
+
+        return false;
+    }
+
+    
+    public final boolean hasGreaterOrEqual( K key ) throws Exception
+    {
+        return avlTree.findGreaterOrEqual( new Tuple<K,V>( key, null ) ) != null;
+    }
+    
+
+    public final boolean hasGreaterOrEqual( K key, V val ) throws Exception
+    {
+        return avlTree.findGreaterOrEqual( new Tuple<K,V>( key, val ) ) != null;
+    }
+    
+
+    public final boolean hasLessOrEqual( K key ) throws Exception
+    {
+        return avlTree.findLessOrEqual( new Tuple<K,V>( key, null ) ) != null;
+    }
+    
+
+    public final boolean hasLessOrEqual( K key, V val ) throws Exception
+    {
+        return avlTree.findGreaterOrEqual( new Tuple<K,V>( key, val ) ) != null;
+    }
+
+    
+    public final boolean isCountExact()
+    {
+        return false;
+    }
+
+    
+    public final boolean isDupsEnabled()
+    {
+        return false;
+    }
+
+    
+    public final int lessThanCount( K key ) throws Exception
+    {
+        return avlTree.getSize();
+    }
+
+    
+    public final void put( K key, V value ) throws Exception
+    {
+        avlTree.insert( new Tuple<K,V>( key, value) );
+    }
+
+    
+    public final void remove( K key ) throws Exception
+    {
+        avlTree.remove( new Tuple<K,V>( key, null) );
+    }
+    
+
+    public final void remove( K key, V value ) throws Exception
+    {
+        avlTree.remove( new Tuple<K,V>( key, value) );
+    }
+
+    
+    public final Cursor<V> valueCursor( K key ) throws Exception
+    {
+        V value = get( key );
+        
+        if ( value == null )
+        {
+            return new EmptyCursor<V>();
+        }
+
+        return new SingletonCursor<V>( value );
+    }
+}

Added: directory/apacheds/branches/ldif-partition/ldif-partition/src/main/java/org/apache/directory/server/core/partition/ldif/NoDupsAvlTupleComparator.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/ldif-partition/ldif-partition/src/main/java/org/apache/directory/server/core/partition/ldif/NoDupsAvlTupleComparator.java?rev=762158&view=auto
==============================================================================
--- directory/apacheds/branches/ldif-partition/ldif-partition/src/main/java/org/apache/directory/server/core/partition/ldif/NoDupsAvlTupleComparator.java
(added)
+++ directory/apacheds/branches/ldif-partition/ldif-partition/src/main/java/org/apache/directory/server/core/partition/ldif/NoDupsAvlTupleComparator.java
Sun Apr  5 21:20:11 2009
@@ -0,0 +1,70 @@
+/*
+ *   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.partition.ldif;
+
+
+import java.util.Comparator;
+
+import org.apache.directory.server.xdbm.Tuple;
+
+
+/**
+ * A pair of comparators used to order Tuples in a AvlTree.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class NoDupsAvlTupleComparator<K,V> implements Comparator<Tuple<K,V>>
+{
+    private final Comparator<K> keyComparator;
+    private final Comparator<V> valueComparator;
+  
+    
+    public NoDupsAvlTupleComparator( Comparator<K> keyComparator, Comparator<V>
valueComparator )
+    {
+        this.keyComparator = keyComparator;
+        this.valueComparator = valueComparator;
+    }
+  
+    
+    public Comparator<K> getKeyComparator()
+    {
+        return keyComparator;
+    }
+    
+    
+    public Comparator<V> getValueComparator()
+    {
+        return valueComparator;
+    }
+    
+
+    public int compare( Tuple<K, V> t1, Tuple<K, V> t2 )
+    {
+        int keyComp = keyComparator.compare( t1.getKey(), t2.getKey() );
+        
+        if ( keyComp == 0 )
+        {
+            return valueComparator.compare( t1.getValue(), t2.getValue() );
+        }
+        
+        return keyComp;
+    }
+}



Mime
View raw message