You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@directory.apache.org by Emmanuel Lécharny <el...@gmail.com> on 2013/10/04 22:18:39 UTC

[Mavinot] Value handling and multiple values

Hi,

I'm currently implementing the ValueHodler for the managed btrees, and
I'm coming with some nice solution for the duplicate values. The idea is
to make the ValueHolder class Iterable, so that we can get any of the
stored values in it (even if we have none or only one).

This is what it will looks like :

public class ValueHolder<K, V> implements Iterable<V>
{
    /** The deserialized value */
    V[] valueArray;

    /** The BTree storing multiple value, if we have moe than a
threashold values */
    BTree<V, V> valueBtree;

    /** The serialized value */
    ByteBuffer raw;

    /** A flag set to true if the values are stored in a BTree */
    boolean isBtree = false;

    private class ValueArrayIterator implements Iterator<V>
    {
        /** Store the current position in the array or in the BTree */

        private int currentPos;


        private ValueArrayIterator()
        {
            // Start at -1 to be positionned before the first element
            currentPos = -1;
        }


        @Override
        public boolean hasNext()
        {
            if ( valueArray == null )
            {
                // Load the array from the raw data
                return false;
            }
            else
            {
                return ( valueArray != null ) && ( currentPos <
valueArray.length );
            }
        }


        public V next()
        {
            if ( valueArray == null )
            {
                // Deserialize the array
                return null;
            }
            else
            {
                currentPos++;

                if ( currentPos == valueArray.length )
                {
                    // We have reached the end of the array
                    return null;
                }
                else
                {
                    return valueArray[currentPos];
                }
            }
        }


        public void remove()
        {
            // Nothing to do, we don't allow any mutation on this class
        }
    }

    private class ValueBtreeIterator implements Iterator<V>
    {
        /** Store the current position in the array or in the BTree */

        private int currentPos;


        private ValueBtreeIterator()
        {
            // Start at -1 to be positionned before the first element
            currentPos = -1;
        }


        @Override
        public boolean hasNext()
        {
            if ( valueBtree == null )
            {
                return true;
            }
            else
            {
                return true;
            }
        }


        public V next()
        {
            return null;
        }


        public void remove()
        {
            // Nothing to do, we don't allow any mutation on this class
        }
    }


    /**
     * {@inheritDoc}
     */
    @Override
    public Iterator<V> iterator()
    {
        if ( isBtree )
        {
            return new ValueBtreeIterator();
        }
        else
        {
            return new ValueArrayIterator();
        }
    }
}

As youc an see, we store either an array of Value, or a Btree. If we
have one single value, we use an array with one single element in it.

In any case, we define two different iterators which will be used
internally, but the caller will just have to use it as is.

It seems convenient, at least for a very first version, and it can be
used by the in-memory btree too, eliminating the need of many tests in
the implementation (things like : if ( btree.isAllowDuplicates() ).

wdyt ?

-- 
Regards,
Cordialement,
Emmanuel Lécharny
www.iktek.com 


Re: [Mavinot] Value handling and multiple values

Posted by Emmanuel Lécharny <el...@gmail.com>.
Le 10/6/13 4:42 PM, Kiran Ayyagari a écrit :
> On Sat, Oct 5, 2013 at 1:48 AM, Emmanuel Lécharny <el...@gmail.com>wrote:
>
>> Hi,
>>
>> I'm currently implementing the ValueHodler for the managed btrees, and
>> I'm coming with some nice solution for the duplicate values. The idea is
>> to make the ValueHolder class Iterable, so that we can get any of the
>> stored values in it (even if we have none or only one).
>>
>> This is what it will looks like :
>>
>> public class ValueHolder<K, V> implements Iterable<V>
>> {
>>     /** The deserialized value */
>>     V[] valueArray;
>>
>>     /** The BTree storing multiple value, if we have moe than a
>> threashold values */
>>     BTree<V, V> valueBtree;
>>
>>     /** The serialized value */
>>     ByteBuffer raw;
>>
>>     /** A flag set to true if the values are stored in a BTree */
>>     boolean isBtree = false;
>>
>>     private class ValueArrayIterator implements Iterator<V>
>>     {
>>         /** Store the current position in the array or in the BTree */
>>
>>         private int currentPos;
>>
>>
>>         private ValueArrayIterator()
>>         {
>>             // Start at -1 to be positionned before the first element
>>             currentPos = -1;
>>         }
>>
>>
>>         @Override
>>         public boolean hasNext()
>>         {
>>             if ( valueArray == null )
>>             {
>>                 // Load the array from the raw data
>>                 return false;
>>             }
>>             else
>>             {
>>                 return ( valueArray != null ) && ( currentPos <
>> valueArray.length );
>>             }
>>         }
>>
>>
>>         public V next()
>>         {
>>             if ( valueArray == null )
>>             {
>>                 // Deserialize the array
>>                 return null;
>>             }
>>             else
>>             {
>>                 currentPos++;
>>
>>                 if ( currentPos == valueArray.length )
>>                 {
>>                     // We have reached the end of the array
>>                     return null;
>>                 }
>>                 else
>>                 {
>>                     return valueArray[currentPos];
>>                 }
>>             }
>>         }
>>
>>
>>         public void remove()
>>         {
>>             // Nothing to do, we don't allow any mutation on this class
>>         }
>>     }
>>
>>     private class ValueBtreeIterator implements Iterator<V>
>>     {
>>         /** Store the current position in the array or in the BTree */
>>
>>         private int currentPos;
>>
>>
>>         private ValueBtreeIterator()
>>         {
>>             // Start at -1 to be positionned before the first element
>>             currentPos = -1;
>>         }
>>
>>
>>         @Override
>>         public boolean hasNext()
>>         {
>>             if ( valueBtree == null )
>>             {
>>                 return true;
>>             }
>>             else
>>             {
>>                 return true;
>>             }
>>         }
>>
>>
>>         public V next()
>>         {
>>             return null;
>>         }
>>
>>
>>         public void remove()
>>         {
>>             // Nothing to do, we don't allow any mutation on this class
>>         }
>>     }
>>
>>
>>     /**
>>      * {@inheritDoc}
>>      */
>>     @Override
>>     public Iterator<V> iterator()
>>     {
>>         if ( isBtree )
>>         {
>>             return new ValueBtreeIterator();
>>         }
>>         else
>>         {
>>             return new ValueArrayIterator();
>>         }
>>     }
>> }
>>
>> As youc an see, we store either an array of Value, or a Btree. If we
>> have one single value, we use an array with one single element in it.
>>
>> In any case, we define two different iterators which will be used
>> internally, but the caller will just have to use it as is.
>>
>> It seems convenient, at least for a very first version, and it can be
>> used by the in-memory btree too, eliminating the need of many tests in
>> the implementation (things like : if ( btree.isAllowDuplicates() ).
>>
>> wdyt ?
>>
>> I prefer a cursor

I'll ue a Cursor then :-)

Seriously, it makes sense to use a Cursor, as we already have such an
interface existing. Although I had to transform it a bit, to create a
consistant hierarchy (the cursor we have deals with Tuple, and we don't
need tuples when we browe values).

So, work in progress...


-- 
Regards,
Cordialement,
Emmanuel Lécharny
www.iktek.com 


Re: [Mavinot] Value handling and multiple values

Posted by Kiran Ayyagari <ka...@apache.org>.
On Sat, Oct 5, 2013 at 1:48 AM, Emmanuel Lécharny <el...@gmail.com>wrote:

> Hi,
>
> I'm currently implementing the ValueHodler for the managed btrees, and
> I'm coming with some nice solution for the duplicate values. The idea is
> to make the ValueHolder class Iterable, so that we can get any of the
> stored values in it (even if we have none or only one).
>
> This is what it will looks like :
>
> public class ValueHolder<K, V> implements Iterable<V>
> {
>     /** The deserialized value */
>     V[] valueArray;
>
>     /** The BTree storing multiple value, if we have moe than a
> threashold values */
>     BTree<V, V> valueBtree;
>
>     /** The serialized value */
>     ByteBuffer raw;
>
>     /** A flag set to true if the values are stored in a BTree */
>     boolean isBtree = false;
>
>     private class ValueArrayIterator implements Iterator<V>
>     {
>         /** Store the current position in the array or in the BTree */
>
>         private int currentPos;
>
>
>         private ValueArrayIterator()
>         {
>             // Start at -1 to be positionned before the first element
>             currentPos = -1;
>         }
>
>
>         @Override
>         public boolean hasNext()
>         {
>             if ( valueArray == null )
>             {
>                 // Load the array from the raw data
>                 return false;
>             }
>             else
>             {
>                 return ( valueArray != null ) && ( currentPos <
> valueArray.length );
>             }
>         }
>
>
>         public V next()
>         {
>             if ( valueArray == null )
>             {
>                 // Deserialize the array
>                 return null;
>             }
>             else
>             {
>                 currentPos++;
>
>                 if ( currentPos == valueArray.length )
>                 {
>                     // We have reached the end of the array
>                     return null;
>                 }
>                 else
>                 {
>                     return valueArray[currentPos];
>                 }
>             }
>         }
>
>
>         public void remove()
>         {
>             // Nothing to do, we don't allow any mutation on this class
>         }
>     }
>
>     private class ValueBtreeIterator implements Iterator<V>
>     {
>         /** Store the current position in the array or in the BTree */
>
>         private int currentPos;
>
>
>         private ValueBtreeIterator()
>         {
>             // Start at -1 to be positionned before the first element
>             currentPos = -1;
>         }
>
>
>         @Override
>         public boolean hasNext()
>         {
>             if ( valueBtree == null )
>             {
>                 return true;
>             }
>             else
>             {
>                 return true;
>             }
>         }
>
>
>         public V next()
>         {
>             return null;
>         }
>
>
>         public void remove()
>         {
>             // Nothing to do, we don't allow any mutation on this class
>         }
>     }
>
>
>     /**
>      * {@inheritDoc}
>      */
>     @Override
>     public Iterator<V> iterator()
>     {
>         if ( isBtree )
>         {
>             return new ValueBtreeIterator();
>         }
>         else
>         {
>             return new ValueArrayIterator();
>         }
>     }
> }
>
> As youc an see, we store either an array of Value, or a Btree. If we
> have one single value, we use an array with one single element in it.
>
> In any case, we define two different iterators which will be used
> internally, but the caller will just have to use it as is.
>
> It seems convenient, at least for a very first version, and it can be
> used by the in-memory btree too, eliminating the need of many tests in
> the implementation (things like : if ( btree.isAllowDuplicates() ).
>
> wdyt ?
>
> I prefer a cursor

> --
> Regards,
> Cordialement,
> Emmanuel Lécharny
> www.iktek.com
>
>


-- 
Kiran Ayyagari
http://keydap.com