Skip to content

Commit

Permalink
Lucene.Net.Util.Fst.Int32sRefFSTEnum: Added MoveNext() method and mar…
Browse files Browse the repository at this point in the history
…ked Next() method obsolete. See #279. This change had already been done to BytesRefFSTEnum, which made them inconsistent.
  • Loading branch information
NightOwl888 committed Dec 20, 2021
1 parent 82687a2 commit 26d65f2
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 23 deletions.
10 changes: 6 additions & 4 deletions src/Lucene.Net.TestFramework/Util/Fst/FSTTester.cs
Original file line number Diff line number Diff line change
Expand Up @@ -492,12 +492,13 @@ private void VerifyUnPruned(int inputMode, FST<T> fst)
Assert.IsTrue(OutputsEqual(pair.Output, output));

// verify enum's next
Int32sRefFSTEnum.InputOutput<T> t = fstEnum.Next();
Assert.IsTrue(fstEnum.MoveNext());
Int32sRefFSTEnum.InputOutput<T> t = fstEnum.Current;
Assert.IsNotNull(t);
Assert.AreEqual(term, t.Input, "expected input=" + InputToString(inputMode, term) + " but fstEnum returned " + InputToString(inputMode, t.Input));
Assert.IsTrue(OutputsEqual(pair.Output, t.Output));
}
Assert.IsNull(fstEnum.Next());
Assert.IsFalse(fstEnum.MoveNext());
}

IDictionary<Int32sRef, T> termsMap = new Dictionary<Int32sRef, T>();
Expand Down Expand Up @@ -686,7 +687,7 @@ private void VerifyUnPruned(int inputMode, FST<T> fst)
{
Console.WriteLine(" do next");
}
isDone = fstEnum_.Next() == null;
isDone = fstEnum_.MoveNext() == false;
}
else if (upto != -1 && upto < 0.75 * pairs.Count && random.NextBoolean())
{
Expand Down Expand Up @@ -974,8 +975,9 @@ private void VerifyPruned(int inputMode, FST<T> fst, int prune1, int prune2)
}
Int32sRefFSTEnum<T> fstEnum = new Int32sRefFSTEnum<T>(fst);
Int32sRefFSTEnum.InputOutput<T> current;
while ((current = fstEnum.Next()) != null)
while (fstEnum.MoveNext())
{
current = fstEnum.Current;
if (LuceneTestCase.Verbose)
{
Console.WriteLine(" fstEnum.next prefix=" + InputToString(inputMode, current.Input, false) + " output=" + outputs.OutputToString(current.Output));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ public void TestEnumerateAll()
Int32sRefFSTEnum<J2N.Numerics.Int64> fstEnum = new Int32sRefFSTEnum<J2N.Numerics.Int64>(fst);
Int32sRefFSTEnum.InputOutput<J2N.Numerics.Int64> mapping;
Int32sRef scratch = new Int32sRef();
while ((mapping = fstEnum.Next()) != null)
while (fstEnum.MoveNext())
{
mapping = fstEnum.Current;
numTerms++;
Int32sRef input = mapping.Input;
char[] chars = new char[input.Length];
Expand Down
24 changes: 6 additions & 18 deletions src/Lucene.Net.Tests/Util/Fst/Test2BFST.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,9 @@ public virtual void Test()
Arrays.Fill(ints2, 0);
r = new J2N.Randomizer(seed);
int upto = 0;
while (true)
while (fstEnum.MoveNext())
{
Int32sRefFSTEnum.InputOutput<object> pair = fstEnum.Next();
if (pair == null)
{
break;
}
Int32sRefFSTEnum.InputOutput<object> pair = fstEnum.Current;
for (int j = 10; j < ints2.Length; j++)
{
ints2[j] = r.Next(256);
Expand Down Expand Up @@ -201,13 +197,9 @@ public virtual void Test()
Arrays.Fill(ints, 0);
r = new J2N.Randomizer(seed);
int upto = 0;
while (true)
while (fstEnum.MoveNext())
{
Int32sRefFSTEnum.InputOutput<BytesRef> pair = fstEnum.Next();
if (pair == null)
{
break;
}
Int32sRefFSTEnum.InputOutput<BytesRef> pair = fstEnum.Current;
Assert.AreEqual(input, pair.Input);
r.NextBytes(outputBytes);
Assert.AreEqual(output, pair.Output);
Expand Down Expand Up @@ -294,13 +286,9 @@ public virtual void Test()
r = new J2N.Randomizer(seed);
int upto = 0;
output = 1;
while (true)
while (fstEnum.MoveNext())
{
Int32sRefFSTEnum.InputOutput<J2N.Numerics.Int64> pair = fstEnum.Next();
if (pair == null)
{
break;
}
Int32sRefFSTEnum.InputOutput<J2N.Numerics.Int64> pair = fstEnum.Current;
Assert.AreEqual(input, pair.Input);
Assert.AreEqual(output, pair.Output);
output += 1 + r.Next(10);
Expand Down
19 changes: 19 additions & 0 deletions src/Lucene.Net/Util/Fst/IntsRefFSTEnum.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Lucene.Net.Diagnostics;
using System;
using System.Runtime.CompilerServices;

namespace Lucene.Net.Util.Fst
Expand Down Expand Up @@ -50,6 +51,24 @@ public Int32sRefFSTEnum(FST<T> fst)

public Int32sRefFSTEnum.InputOutput<T> Current => result;

public bool MoveNext() // LUCENENET specific - replaced Next() with MoveNext()
{
//System.out.println(" enum.next");
DoNext();

if (m_upto == 0)
{
return false;
}
else
{
current.Length = m_upto - 1;
result.Output = m_output[m_upto];
return true;
}
}

[Obsolete("Use MoveNext() and Current instead. This method will be removed in 4.8.0 release candidate."), System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
public Int32sRefFSTEnum.InputOutput<T> Next()
{
//System.out.println(" enum.next");
Expand Down

0 comments on commit 26d65f2

Please sign in to comment.