Ejemplo n.º 1
0
            protected override void Swap(int i, int j)
            {
                long tmpDoc = docs.Get(j);

                docs.Set(j, docs.Get(i));
                docs.Set(i, tmpDoc);

                long tmpVal = values.Get(j);

                values.Set(j, values.Get(i));
                values.Set(i, tmpVal);

                bool tmpBool = docsWithField.Get(j);

                if (docsWithField.Get(i))
                {
                    docsWithField.Set(j);
                }
                else
                {
                    docsWithField.Clear(j);
                }
                if (tmpBool)
                {
                    docsWithField.Set(i);
                }
                else
                {
                    docsWithField.Clear(i);
                }
            }
            protected internal override void Swap(int i, int j)
            {
                long tmpDoc = Docs.Get(j);

                Docs.Set(j, Docs.Get(i));
                Docs.Set(i, tmpDoc);

                long tmpVal = Values.Get(j);

                Values.Set(j, Values.Get(i));
                Values.Set(i, tmpVal);

                bool tmpBool = DocsWithField.Get(j);

                if (DocsWithField.Get(i))
                {
                    DocsWithField.Set(j);
                }
                else
                {
                    DocsWithField.Clear(j);
                }
                if (tmpBool)
                {
                    DocsWithField.Set(i);
                }
                else
                {
                    DocsWithField.Clear(i);
                }
            }
            public int NextDoc()
            {
                if (Idx >= Size)
                {
                    Offset = -1;
                    return(Doc_Renamed = DocIdSetIterator.NO_MORE_DOCS);
                }
                Doc_Renamed = (int)Docs.Get(Idx);
                ++Idx;
                while (Idx < Size && Docs.Get(Idx) == Doc_Renamed)
                {
                    ++Idx;
                }
                // idx points to the "next" element
                long prevIdx = Idx - 1;

                if (!DocsWithField.Get((int)prevIdx))
                {
                    Offset = -1;
                }
                else
                {
                    // cannot change 'value' here because nextDoc is called before the
                    // value is used, and it's a waste to clone the BytesRef when we
                    // obtain the value
                    Offset = (int)Offsets.Get(prevIdx);
                    Length = (int)Lengths.Get(prevIdx);
                }
                return(Doc_Renamed);
            }
Ejemplo n.º 4
0
            public override int NextDoc()
            {
                if (idx >= size)
                {
                    offset = -1;
                    return(doc = DocIdSetIterator.NO_MORE_DOCS);
                }
                doc = (int)docs.Get(idx);
                ++idx;
                while (idx < size && docs.Get(idx) == doc)
                {
                    ++idx;
                }
                // idx points to the "next" element
                long prevIdx = idx - 1;

                if (!docsWithField.Get((int)prevIdx))
                {
                    offset = -1;
                }
                else
                {
                    // cannot change 'value' here because nextDoc is called before the
                    // value is used, and it's a waste to clone the BytesRef when we
                    // obtain the value
                    offset = (int)offsets.Get(prevIdx);
                    length = (int)lengths.Get(prevIdx);
                }
                return(doc);
            }
Ejemplo n.º 5
0
        public long Add(Builder.UnCompiledNode <T> nodeIn)
        {
            //System.out.println("hash: add count=" + count + " vs " + table.size() + " mask=" + mask);
            long h   = Hash(nodeIn);
            long pos = h & mask;
            int  c   = 0;

            while (true)
            {
                long v = table.Get(pos);
                if (v == 0)
                {
                    // freeze & add
                    long node = fst.AddNode(nodeIn);
                    //System.out.println("  now freeze node=" + node);
                    if (Debugging.AssertsEnabled)
                    {
                        // LUCENENET specific - store hash value and reuse it, since it might be expensive to create
                        long hash = Hash(node);
                        Debugging.Assert(hash == h, "frozenHash={0} vs h={1}", hash, h);
                    }
                    count++;
                    table.Set(pos, node);
                    // Rehash at 2/3 occupancy:
                    if (count > 2 * table.Count / 3)
                    {
                        Rehash();
                    }
                    return(node);
                }
                else if (NodesEqual(nodeIn, v))
                {
                    // same node is already here
                    return(v);
                }

                // quadratic probe
                pos = (pos + (++c)) & mask;
            }
        }
Ejemplo n.º 6
0
        public long Add(Builder.UnCompiledNode <T> nodeIn)
        {
            //System.out.println("hash: add count=" + count + " vs " + table.size() + " mask=" + mask);
            long h   = Hash(nodeIn);
            long pos = h & mask;
            int  c   = 0;

            while (true)
            {
                long v = table.Get(pos);
                if (v == 0)
                {
                    // freeze & add
                    long node = fst.AddNode(nodeIn);
                    //System.out.println("  now freeze node=" + node);
                    if (Debugging.AssertsEnabled)
                    {
                        Debugging.Assert(Hash(node) == h, () => "frozenHash=" + Hash(node) + " vs h=" + h);
                    }
                    count++;
                    table.Set(pos, node);
                    // Rehash at 2/3 occupancy:
                    if (count > 2 * table.Count / 3)
                    {
                        Rehash();
                    }
                    return(node);
                }
                else if (NodesEqual(nodeIn, v))
                {
                    // same node is already here
                    return(v);
                }

                // quadratic probe
                pos = (pos + (++c)) & mask;
            }
        }
Ejemplo n.º 7
0
        private void Rehash()
        {
            PagedGrowableWriter oldTable = table;

            table = new PagedGrowableWriter(2 * oldTable.Count, 1 << 30, PackedInt32s.BitsRequired(count), PackedInt32s.COMPACT);
            mask  = table.Count - 1;
            for (long idx = 0; idx < oldTable.Count; idx++)
            {
                long address = oldTable.Get(idx);
                if (address != 0)
                {
                    AddNew(address);
                }
            }
        }
            protected override void Swap(int i, int j)
            {
                long tmpDoc = Docs.Get(j);

                Docs.Set(j, Docs.Get(i));
                Docs.Set(i, tmpDoc);

                long tmpOffset = Offsets.Get(j);

                Offsets.Set(j, Offsets.Get(i));
                Offsets.Set(i, tmpOffset);

                long tmpLength = Lengths.Get(j);

                Lengths.Set(j, Lengths.Get(i));
                Lengths.Set(i, tmpLength);

                bool tmpBool = DocsWithField.Get(j);

                if (DocsWithField.Get(i))
                {
                    DocsWithField.Set(j);
                }
                else
                {
                    DocsWithField.Clear(j);
                }
                if (tmpBool)
                {
                    DocsWithField.Set(i);
                }
                else
                {
                    DocsWithField.Clear(i);
                }
            }
Ejemplo n.º 9
0
            protected override void Swap(int i, int j)
            {
                long tmpDoc = docs.Get(j);

                docs.Set(j, docs.Get(i));
                docs.Set(i, tmpDoc);

                long tmpOffset = offsets.Get(j);

                offsets.Set(j, offsets.Get(i));
                offsets.Set(i, tmpOffset);

                long tmpLength = lengths.Get(j);

                lengths.Set(j, lengths.Get(i));
                lengths.Set(i, tmpLength);

                bool tmpBool = docsWithField.Get(j);

                if (docsWithField.Get(i))
                {
                    docsWithField.Set(j);
                }
                else
                {
                    docsWithField.Clear(j);
                }
                if (tmpBool)
                {
                    docsWithField.Set(i);
                }
                else
                {
                    docsWithField.Clear(i);
                }
            }
Ejemplo n.º 10
0
        private void Rehash()
        {
            PagedGrowableWriter oldTable = Table;

            Table = new PagedGrowableWriter(2 * oldTable.Size(), 1 << 30, PackedInts.BitsRequired(Count), PackedInts.COMPACT);
            Mask  = Table.Size() - 1;
            for (long idx = 0; idx < oldTable.Size(); idx++)
            {
                long address = oldTable.Get(idx);
                if (address != 0)
                {
                    AddNew(address);
                }
            }
        }
Ejemplo n.º 11
0
        public long Add(Builder <T> .UnCompiledNode <T> nodeIn)
        {
            //System.out.println("hash: add count=" + count + " vs " + table.size() + " mask=" + mask);
            long h   = Hash(nodeIn);
            long pos = h & Mask;
            int  c   = 0;

            while (true)
            {
                long v = Table.Get(pos);
                if (v == 0)
                {
                    // freeze & add
                    long node = Fst.AddNode(nodeIn);
                    //System.out.println("  now freeze node=" + node);
                    long hashNode = Hash(node);
                    Debug.Assert(hashNode == h, "frozenHash=" + hashNode + " vs h=" + h);
                    Count++;
                    Table.Set(pos, node);
                    // Rehash at 2/3 occupancy:
                    if (Count > 2 * Table.Size() / 3)
                    {
                        Rehash();
                    }
                    return(node);
                }
                else if (NodesEqual(nodeIn, v))
                {
                    // same node is already here
                    return(v);
                }

                // quadratic probe
                pos = (pos + (++c)) & Mask;
            }
        }
Ejemplo n.º 12
0
 public override int NextDoc()
 {
     if (idx >= size)
     {
         value = null;
         return(doc = DocIdSetIterator.NO_MORE_DOCS);
     }
     doc = (int)docs.Get(idx);
     ++idx;
     while (idx < size && docs.Get(idx) == doc)
     {
         ++idx;
     }
     if (!docsWithField.Get((int)(idx - 1)))
     {
         value = null;
     }
     else
     {
         // idx points to the "next" element
         value = Convert.ToInt64(values.Get(idx - 1));
     }
     return(doc);
 }
 public int NextDoc()
 {
     if (Idx >= Size)
     {
         Value_Renamed = null;
         return(Doc_Renamed = DocIdSetIterator.NO_MORE_DOCS);
     }
     Doc_Renamed = (int)Docs.Get(Idx);
     ++Idx;
     while (Idx < Size && Docs.Get(Idx) == Doc_Renamed)
     {
         ++Idx;
     }
     if (!DocsWithField.Get((int)(Idx - 1)))
     {
         Value_Renamed = null;
     }
     else
     {
         // idx points to the "next" element
         Value_Renamed = Convert.ToInt64(Values.Get(Idx - 1));
     }
     return(Doc_Renamed);
 }