Exemple #1
0
            public override int NextDoc()
            {
                // increment the cursor and check if it falls in the range for the
                // number of batches, if not return false else, its within range
                if (++cursor < size)
                {
                    // We are already in the array
                    if (bi == blobSize)
                    {
                        if (offset == -1)
                        {
                            lastReturn = DocIdSetIterator.NO_MORE_DOCS;
                            return(DocIdSetIterator.NO_MORE_DOCS);
                        }
                        else
                        {
                            lastReturn += parent.current[offset++];
                        }
                    }
                    // if we are not in the array but on the boundary of a batch
                    // update local blob and set params
                    else if (offset == 0)
                    {
                        bi = BatchIndex(cursor);

                        if (bi < blobSize)
                        {
                            lastReturn = parent.baseList.Get(bi);
                            @ref       = parent.blob.Get(bi);
                            localCompressedSet.UpdateParams(@ref);
                            offset++; // cursor - (bi << ADDRESS_BITS);+1
                        }
                        else
                        {
                            // offset = 0;//cursor - (bi << ADDRESS_BITS);
                            lastReturn = parent.current[offset++];
                        }
                    }
                    else
                    {
                        lastReturn += localCompressedSet.Get(@ref, offset);
                        offset      = (++offset) % parent.BATCH_SIZE;
                    }
                    return(lastReturn);
                }
                lastReturn = DocIdSetIterator.NO_MORE_DOCS;
                return(DocIdSetIterator.NO_MORE_DOCS);
            }
        public override bool Find(int val)
        {
            long time = System.Environment.TickCount;
            int local = 0;

            if (Size() == 0)
            {
                return false;
            }


            if (val > lastAdded || val < baseList.Get(0)) //Short Circuit case where its not in the set at all
            {
                //System.out.println("Time to perform BinarySearch for:"+val+":"+(System.nanoTime() - time));
                return false;
            }
            else if (val >= current_base) // We are in the set
            {

                int i = 0;
                for (i = 0; i < current_size; i++)
                {
                    local += current[i];

                    if (local > val)
                    {
                        break;
                    }
                }

                if (i == current_size)
                {
                    return local == val;
                }
                else
                {
                    return (local - current[i] == val);
                }
            }
            else // We are in the compressed space
            {
                if (baseList.Size() == 0)
                {
                    return false;
                }

                int blobIndex = BinarySearchForNearest(val, 0, blob.Size() - 1);

                local = baseList.Get(blobIndex);
                long[] @ref = blob.Get(blobIndex);
                P4DSetNoBase localCompressedSet = new P4DSetNoBase();
                localCompressedSet.SetParam(0, DEFAULT_B, BATCH_SIZE, BATCH_OVER);
                localCompressedSet.UpdateParams(@ref);

                int i = 0;

                for (i = 0; i < BATCH_SIZE; i++)
                {
                    local += localCompressedSet.Get(@ref, i);

                    if (local > val)
                    {
                        break;
                    }

                }
                if (i == BATCH_SIZE)
                {
                    return local == val;
                }
                else
                {
                    return (local - localCompressedSet.Get(@ref, i)) == val;
                }
            }
        }
Exemple #3
0
        public override bool Find(int val)
        {
            long time  = System.Environment.TickCount;
            int  local = 0;

            if (Size() == 0)
            {
                return(false);
            }


            if (val > lastAdded || val < baseList.Get(0)) //Short Circuit case where its not in the set at all
            {
                //System.out.println("Time to perform BinarySearch for:"+val+":"+(System.nanoTime() - time));
                return(false);
            }
            else if (val >= current_base) // We are in the set
            {
                int i = 0;
                for (i = 0; i < current_size; i++)
                {
                    local += current[i];

                    if (local > val)
                    {
                        break;
                    }
                }

                if (i == current_size)
                {
                    return(local == val);
                }
                else
                {
                    return(local - current[i] == val);
                }
            }
            else // We are in the compressed space
            {
                if (baseList.Size() == 0)
                {
                    return(false);
                }

                int blobIndex = BinarySearchForNearest(val, 0, blob.Size() - 1);

                local = baseList.Get(blobIndex);
                long[]       @ref = blob.Get(blobIndex);
                P4DSetNoBase localCompressedSet = new P4DSetNoBase();
                localCompressedSet.SetParam(0, DEFAULT_B, BATCH_SIZE, BATCH_OVER);
                localCompressedSet.UpdateParams(@ref);

                int i = 0;

                for (i = 0; i < BATCH_SIZE; i++)
                {
                    local += localCompressedSet.Get(@ref, i);

                    if (local > val)
                    {
                        break;
                    }
                }
                if (i == BATCH_SIZE)
                {
                    return(local == val);
                }
                else
                {
                    return((local - localCompressedSet.Get(@ref, i)) == val);
                }
            }
        }