You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucenenet.apache.org by ni...@apache.org on 2021/03/14 12:54:50 UTC
[lucenenet] branch master updated (11f1106 -> ec65e26)
This is an automated email from the ASF dual-hosted git repository.
nightowl888 pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/lucenenet.git.
from 11f1106 Directory.Build.Targets: Added FEATURE_DICTIONARY_REMOVE_CONTINUEENUMERATION so we can support this feature in .NET 5.x + when we add a target.
new 1fa9312 PERFORMANCE: Lucene.Net.Search.Suggest.Fst.FSTCompletion: Use Stack<T> rather than List<T>.Reverse(). Also, removed unnecessary lock in CheckExistingAndReorder(), as it is only used in a single thread at a time.
new ec65e26 PERFORMANCE: Lucene.Net.Search.Suggest.SortedInputEnumerator: Removed unnecessary call to Reverse() and allocation of HashSet<T> that had been added due to the fact our testing methodology didn't respect set equality (that is, it relied on the order of the collection).
The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
src/Lucene.Net.Suggest/Suggest/Fst/FSTCompletion.cs | 20 +++++++-------------
.../Suggest/SortedInputIterator.cs | 14 ++++----------
.../Suggest/DocumentValueSourceDictionaryTest.cs | 6 ++++++
3 files changed, 17 insertions(+), 23 deletions(-)
[lucenenet] 01/02: PERFORMANCE:
Lucene.Net.Search.Suggest.Fst.FSTCompletion: Use Stack rather than
List.Reverse(). Also,
removed unnecessary lock in CheckExistingAndReorder(),
as it is only used in a single thread at a time.
Posted by ni...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
nightowl888 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/lucenenet.git
commit 1fa93124ee701ed41b699b9717a420061725ee76
Author: Shad Storhaug <sh...@shadstorhaug.com>
AuthorDate: Sun Mar 14 16:35:20 2021 +0700
PERFORMANCE: Lucene.Net.Search.Suggest.Fst.FSTCompletion: Use Stack<T> rather than List<T>.Reverse(). Also, removed unnecessary lock in CheckExistingAndReorder(), as it is only used in a single thread at a time.
---
src/Lucene.Net.Suggest/Suggest/Fst/FSTCompletion.cs | 20 +++++++-------------
1 file changed, 7 insertions(+), 13 deletions(-)
diff --git a/src/Lucene.Net.Suggest/Suggest/Fst/FSTCompletion.cs b/src/Lucene.Net.Suggest/Suggest/Fst/FSTCompletion.cs
index 6cdc8a9..441f8b0 100644
--- a/src/Lucene.Net.Suggest/Suggest/Fst/FSTCompletion.cs
+++ b/src/Lucene.Net.Suggest/Suggest/Fst/FSTCompletion.cs
@@ -100,9 +100,6 @@ namespace Lucene.Net.Search.Suggest.Fst
/// <seealso cref="FSTCompletion(FST{object}, bool, bool)" />
private readonly bool higherWeightsFirst;
- // LUCENENET SPECIFIC: We need some thread safety to execute atomic list operations
- private readonly object syncLock = new object();
-
/// <summary>
/// Constructs an FSTCompletion, specifying higherWeightsFirst and exactFirst. </summary>
/// <param name="automaton">
@@ -146,13 +143,14 @@ namespace Lucene.Net.Search.Suggest.Fst
{
try
{
- List<FST.Arc<object>> rootArcs = new List<FST.Arc<object>>();
+ // LUCENENET specific: Using a stack rather than List, as we want the results in reverse
+ Stack<FST.Arc<object>> rootArcs = new Stack<FST.Arc<object>>();
FST.Arc<object> arc = automaton.GetFirstArc(new FST.Arc<object>());
FST.BytesReader fstReader = automaton.GetBytesReader();
automaton.ReadFirstTargetArc(arc, arc, fstReader);
while (true)
{
- rootArcs.Add((new FST.Arc<object>()).CopyFrom(arc));
+ rootArcs.Push(new FST.Arc<object>().CopyFrom(arc));
if (arc.IsLast)
{
break;
@@ -161,7 +159,6 @@ namespace Lucene.Net.Search.Suggest.Fst
}
// we want highest weights first.
- rootArcs.Reverse();
return rootArcs.ToArray();
}
catch (IOException e)
@@ -353,14 +350,11 @@ namespace Lucene.Net.Search.Suggest.Fst
// Key found. Unless already at i==0, remove it and push up front so
// that the ordering
// remains identical with the exception of the exact match.
- lock (syncLock)
+ if (key.Equals(list[i].Utf8))
{
- if (key.Equals(list[i].Utf8))
- {
- var element = list[i];
- list.Remove(element);
- list.Insert(0, element);
- }
+ var element = list[i];
+ list.Remove(element);
+ list.Insert(0, element);
}
return true;
}
[lucenenet] 02/02: PERFORMANCE:
Lucene.Net.Search.Suggest.SortedInputEnumerator: Removed unnecessary call
to Reverse() and allocation of HashSet that had been added due to the
fact our testing methodology didn't respect set equality (that is,
it relied on the order of the collection).
Posted by ni...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
nightowl888 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/lucenenet.git
commit ec65e26c1c89c80b7194860bf5d1b7eafbee757e
Author: Shad Storhaug <sh...@shadstorhaug.com>
AuthorDate: Sun Mar 14 16:59:25 2021 +0700
PERFORMANCE: Lucene.Net.Search.Suggest.SortedInputEnumerator: Removed unnecessary call to Reverse() and allocation of HashSet<T> that had been added due to the fact our testing methodology didn't respect set equality (that is, it relied on the order of the collection).
---
src/Lucene.Net.Suggest/Suggest/SortedInputIterator.cs | 14 ++++----------
.../Suggest/DocumentValueSourceDictionaryTest.cs | 6 ++++++
2 files changed, 10 insertions(+), 10 deletions(-)
diff --git a/src/Lucene.Net.Suggest/Suggest/SortedInputIterator.cs b/src/Lucene.Net.Suggest/Suggest/SortedInputIterator.cs
index 5154192..45be895 100644
--- a/src/Lucene.Net.Suggest/Suggest/SortedInputIterator.cs
+++ b/src/Lucene.Net.Suggest/Suggest/SortedInputIterator.cs
@@ -2,10 +2,8 @@
using Lucene.Net.Support;
using Lucene.Net.Support.IO;
using Lucene.Net.Util;
-using System;
using System.Collections.Generic;
using System.IO;
-using System.Linq;
using JCG = J2N.Collections.Generic;
namespace Lucene.Net.Search.Suggest
@@ -297,7 +295,6 @@ namespace Lucene.Net.Search.Suggest
tmpInput.SkipBytes(scratch.Length - 2); //skip to context set size
ushort ctxSetSize = (ushort)tmpInput.ReadInt16();
scratch.Length -= 2;
-
var contextSet = new JCG.HashSet<BytesRef>();
for (ushort i = 0; i < ctxSetSize; i++)
{
@@ -311,13 +308,10 @@ namespace Lucene.Net.Search.Suggest
contextSet.Add(contextSpare);
scratch.Length -= curContextLength;
}
-
- // LUCENENET TODO: We are writing the data forward.
- // Not sure exactly why, but when we read it back it
- // is reversed. So, we need to fix that before returning the result.
- // If the underlying problem is found and fixed, then this line can just be
- // return contextSet;
- return new JCG.HashSet<BytesRef>(contextSet.Reverse());
+ // LUCENENET NOTE: The result was at one point reversed because of test failures, but since we are
+ // using JCG.HashSet<T> now (whose Equals() implementation respects set equality),
+ // we have reverted back to the original implementation.
+ return contextSet;
}
/// <summary>
diff --git a/src/Lucene.Net.Tests.Suggest/Suggest/DocumentValueSourceDictionaryTest.cs b/src/Lucene.Net.Tests.Suggest/Suggest/DocumentValueSourceDictionaryTest.cs
index c96ec7b..bb8fc9f 100644
--- a/src/Lucene.Net.Tests.Suggest/Suggest/DocumentValueSourceDictionaryTest.cs
+++ b/src/Lucene.Net.Tests.Suggest/Suggest/DocumentValueSourceDictionaryTest.cs
@@ -161,6 +161,12 @@ namespace Lucene.Net.Search.Suggest
assertTrue(inputIterator.Current.equals(new BytesRef(doc.Get(FIELD_NAME))));
assertEquals(inputIterator.Weight, (w1 + w2 + w3));
assertTrue(inputIterator.Payload.equals(doc.GetField(PAYLOAD_FIELD_NAME).GetBinaryValue()));
+
+ // LUCENENET NOTE: This test was once failing because we used SCG.HashSet<T> whose
+ // Equals() implementation does not check for set equality. As a result SortedInputEnumerator
+ // had been modified to reverse the results to get the test to pass. However, using JCG.HashSet<T>
+ // ensures that set equality (that is equality that doesn't care about order of items) is respected.
+ // SortedInputEnumerator has also had the specific sorting removed.
ISet<BytesRef> originalCtxs = new JCG.HashSet<BytesRef>();
foreach (IIndexableField ctxf in doc.GetFields(CONTEXTS_FIELD_NAME))
{