private void Check(IBytesRefSorter sorter) { for (int i = 0; i < 100; i++) { byte[] current = new byte[Random.nextInt(256)]; Random.NextBytes(current); sorter.Add(new BytesRef(current)); } // Create two iterators and check that they're aligned with each other. IBytesRefIterator i1 = sorter.GetIterator(); IBytesRefIterator i2 = sorter.GetIterator(); // Verify sorter contract. try { sorter.Add(new BytesRef(new byte[1])); fail("expected contract violation."); } catch (InvalidOperationException /*e*/) { // Expected. } BytesRef spare1; BytesRef spare2; while ((spare1 = i1.Next()) != null && (spare2 = i2.Next()) != null) { assertEquals(spare1, spare2); } assertNull(i1.Next()); assertNull(i2.Next()); }
/// <summary> /// Builds the final automaton from a list of entries. /// </summary> private FST <object> BuildAutomaton(IBytesRefSorter sorter) { // Build the automaton. Outputs <object> outputs = NoOutputs.Singleton; object empty = outputs.NoOutput; Builder <object> builder = new Builder <object>(FST.INPUT_TYPE.BYTE1, 0, 0, true, true, shareMaxTailLength, outputs, null, false, PackedInt32s.DEFAULT, true, 15); BytesRef scratch = new BytesRef(); BytesRef entry; Int32sRef scratchIntsRef = new Int32sRef(); int count = 0; IBytesRefIterator iter = sorter.GetIterator(); while ((entry = iter.Next()) != null) { count++; if (scratch.CompareTo(entry) != 0) { builder.Add(Util.Fst.Util.ToInt32sRef(entry, scratchIntsRef), empty); scratch.CopyBytes(entry); } } return(count == 0 ? null : builder.Finish()); }