// NOTE: while it's tempting to make this public, since // caller's parser likely knows the // numInput/numOutputWords, sneaky exceptions, much later // on, will result if these values are wrong; so we always // recompute ourselves to be safe: internal virtual void add(CharsRef input, int numInputWords, CharsRef output, int numOutputWords, bool includeOrig) { // first convert to UTF-8 if (numInputWords <= 0) { throw new System.ArgumentException("numInputWords must be > 0 (got " + numInputWords + ")"); } if (input.length <= 0) { throw new System.ArgumentException("input.length must be > 0 (got " + input.length + ")"); } if (numOutputWords <= 0) { throw new System.ArgumentException("numOutputWords must be > 0 (got " + numOutputWords + ")"); } if (output.length <= 0) { throw new System.ArgumentException("output.length must be > 0 (got " + output.length + ")"); } Debug.Assert(!hasHoles(input), "input has holes: " + input); Debug.Assert(!hasHoles(output), "output has holes: " + output); //System.out.println("fmap.add input=" + input + " numInputWords=" + numInputWords + " output=" + output + " numOutputWords=" + numOutputWords); UnicodeUtil.UTF16toUTF8(output.chars, output.offset, output.length, utf8Scratch); // lookup in hash int ord = words.add(utf8Scratch); if (ord < 0) { // already exists in our hash ord = (-ord) - 1; //System.out.println(" output=" + output + " old ord=" + ord); } else { //System.out.println(" output=" + output + " new ord=" + ord); } MapEntry e = workingSet[input]; if (e == null) { e = new MapEntry(); workingSet[CharsRef.deepCopyOf(input)] = e; // make a copy, since we will keep around in our map } e.ords.Add(ord); e.includeOrig |= includeOrig; maxHorizontalContext = Math.Max(maxHorizontalContext, numInputWords); maxHorizontalContext = Math.Max(maxHorizontalContext, numOutputWords); }