private void Check(IBytesRefSorter sorter) { for (int i = 0; i < 100; i++) { byte[] current = new byte[Random.Next(256)]; Random.NextBytes(current); sorter.Add(new BytesRef(current)); } // Create two iterators and check that they're aligned with each other. IBytesRefEnumerator i1 = sorter.GetEnumerator(); IBytesRefEnumerator i2 = sorter.GetEnumerator(); // Verify sorter contract. try { sorter.Add(new BytesRef(new byte[1])); fail("expected contract violation."); } catch (Exception e) when(e.IsIllegalStateException()) { // Expected. } while (i1.MoveNext() && i2.MoveNext()) { assertEquals(i1.Current, i2.Current); } assertFalse(i1.MoveNext()); assertFalse(i2.MoveNext()); }
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. BytesRefIterator i1 = sorter.GetEnumerator(); BytesRefIterator i2 = sorter.GetEnumerator(); // 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; IBytesRefEnumerator iter = sorter.GetEnumerator(); while (iter.MoveNext()) { entry = iter.Current; count++; if (scratch.CompareTo(entry) != 0) { builder.Add(Util.Fst.Util.ToInt32sRef(entry, scratchIntsRef), empty); scratch.CopyBytes(entry); } } return(count == 0 ? null : builder.Finish()); }