/// <summary> /// hash code for an unfrozen node. this must be identical /// to the frozen case (below)!! /// </summary> private long Hash(Builder.UnCompiledNode <T> node) { const int PRIME = 31; //System.out.println("hash unfrozen"); long h = 0; // TODO: maybe if number of arcs is high we can safely subsample? for (int arcIdx = 0; arcIdx < node.NumArcs; arcIdx++) { Builder.Arc <T> arc = node.Arcs[arcIdx]; h = PRIME * h + arc.Label; long n = ((Builder.CompiledNode)arc.Target).Node; h = PRIME * h + (int)(n ^ (n >> 32)); // LUCENENET specific - optimize the Hash methods // by only calling StructuralEqualityComparer.GetHashCode() if the value is a reference type h = PRIME * h + (tIsValueType ? JCG.EqualityComparer <T> .Default.GetHashCode(arc.Output) : StructuralEqualityComparer.Default.GetHashCode(arc.Output)); h = PRIME * h + (tIsValueType ? JCG.EqualityComparer <T> .Default.GetHashCode(arc.NextFinalOutput) : StructuralEqualityComparer.Default.GetHashCode(arc.NextFinalOutput)); if (arc.IsFinal) { h += 17; } } //System.out.println(" ret " + (h&Integer.MAX_VALUE)); return(h & long.MaxValue); }
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.Label != scratchArc.Label || !arc.Output.Equals(scratchArc.Output) || ((Builder.CompiledNode)arc.Target).Node != scratchArc.Target || !arc.NextFinalOutput.Equals(scratchArc.NextFinalOutput) || arc.IsFinal != scratchArc.IsFinal) { return(false); } if (scratchArc.IsLast) { if (arcUpto == node.NumArcs - 1) { return(true); } else { return(false); } } fst.ReadNextRealArc(scratchArc, input); } return(false); }