コード例 #1
0
ファイル: NodeHash.cs プロジェクト: ywscr/lucenenet
        private bool NodesEqual(Builder.UnCompiledNode <T> node, long address)
        {
            fst.ReadFirstRealTargetArc(address, scratchArc, input);
            if (scratchArc.BytesPerArc != 0 && node.NumArcs != scratchArc.NumArcs)
            {
                return(false);
            }
            for (int arcUpto = 0; arcUpto < node.NumArcs; arcUpto++)
            {
                Builder.Arc <T> arc = node.Arcs[arcUpto];
                if (arc.IsFinal != scratchArc.IsFinal ||
                    arc.Label != scratchArc.Label ||
                    ((Builder.CompiledNode)arc.Target).Node != scratchArc.Target ||
                    !(tIsValueType ? JCG.EqualityComparer <T> .Default.Equals(arc.Output, scratchArc.Output) : StructuralEqualityComparer.Default.Equals(arc.Output, scratchArc.Output)) ||
                    !(tIsValueType ? JCG.EqualityComparer <T> .Default.Equals(arc.NextFinalOutput, scratchArc.NextFinalOutput) : StructuralEqualityComparer.Default.Equals(arc.NextFinalOutput, scratchArc.NextFinalOutput))
                    )
                {
                    return(false);
                }

                if (scratchArc.IsLast)
                {
                    if (arcUpto == node.NumArcs - 1)
                    {
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
                fst.ReadNextRealArc(scratchArc, input);
            }

            return(false);
        }
コード例 #2
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);
                    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.Count / 3)
                    {
                        Rehash();
                    }
                    return(node);
                }
                else if (NodesEqual(nodeIn, v))
                {
                    // same node is already here
                    return(v);
                }

                // quadratic probe
                pos = (pos + (++c)) & mask;
            }
        }