Skip to content

Commit c00eabb

Browse files
Replace LinkedHashSet<T> with OrderedHashSet<T>, #1272 (#1313)
1 parent 8c57a0f commit c00eabb

8 files changed

Lines changed: 31 additions & 17 deletions

File tree

src/Lucene.Net.Analysis.Phonetic/Language/Bm/PhoneticEngine.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ public static PhonemeBuilder Empty(LanguageSet languages)
7272

7373
private PhonemeBuilder(Phoneme phoneme)
7474
{
75-
this.phonemes = new JCG.LinkedHashSet<Phoneme>
75+
// LUCENENET specific: OrderedHashSet<T> is a replacement for LinkedHashSet<E> in the JDK
76+
this.phonemes = new JCG.OrderedHashSet<Phoneme>
7677
{
7778
phoneme
7879
};
@@ -131,7 +132,8 @@ public void Append(StringBuilder str)
131132
/// <param name="maxPhonemes">The maximum number of phonemes to build up.</param>
132133
public void Apply(IPhonemeExpr phonemeExpr, int maxPhonemes)
133134
{
134-
ISet<Phoneme> newPhonemes = new JCG.LinkedHashSet<Phoneme>(maxPhonemes);
135+
// LUCENENET specific: OrderedHashSet<T> is a replacement for LinkedHashSet<E> in the JDK
136+
ISet<Phoneme> newPhonemes = new JCG.OrderedHashSet<Phoneme>(maxPhonemes);
135137

136138
//EXPR_continue:
137139
foreach (Phoneme left in this.phonemes)

src/Lucene.Net.Highlighter/VectorHighlight/FieldQuery.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,9 @@ public class FieldQuery
4848
internal FieldQuery(Query query, IndexReader reader, bool phraseHighlight, bool fieldMatch)
4949
{
5050
this.fieldMatch = fieldMatch;
51-
// LUCENENET NOTE: LinkedHashSet cares about insertion order
52-
ISet<Query> flatQueries = new JCG.LinkedHashSet<Query>();
51+
// LUCENENET specific: OrderedHashSet<T> is a replacement for LinkedHashSet<E> in the JDK
52+
// (insertion order is significant here)
53+
ISet<Query> flatQueries = new JCG.OrderedHashSet<Query>();
5354
Flatten(query, reader, flatQueries);
5455
SaveTerms(flatQueries, reader);
5556
ICollection<Query> expandQueries = Expand(flatQueries);
@@ -189,7 +190,8 @@ protected virtual Query ApplyParentBoost(Query query, Query parent)
189190
/// <returns></returns>
190191
internal ICollection<Query> Expand(ICollection<Query> flatQueries)
191192
{
192-
ISet<Query> expandQueries = new JCG.LinkedHashSet<Query>();
193+
// LUCENENET specific: OrderedHashSet<T> is a replacement for LinkedHashSet<E> in the JDK
194+
ISet<Query> expandQueries = new JCG.OrderedHashSet<Query>();
193195

194196
for (int i = 0; i < flatQueries.Count;)
195197
{

src/Lucene.Net.Tests.Spatial/Prefix/SpatialOpRecursivePrefixTreeTest.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -316,8 +316,10 @@ private void doTest(SpatialOperation operation)
316316
// We ensure true-positive matches (if the predicate on the raw shapes match
317317
// then the search should find those same matches).
318318
// approximations, false-positive matches
319-
ISet<string> expectedIds = new JCG.LinkedHashSet<string>();//true-positives
320-
ISet<string> secondaryIds = new JCG.LinkedHashSet<string>();//false-positives (unless disjoint)
319+
// LUCENENET specific: OrderedHashSet<T> is a replacement for LinkedHashSet<E> in the JDK
320+
ISet<string> expectedIds = new JCG.OrderedHashSet<string>();//true-positives
321+
// LUCENENET specific: OrderedHashSet<T> is a replacement for LinkedHashSet<E> in the JDK
322+
ISet<string> secondaryIds = new JCG.OrderedHashSet<string>();//false-positives (unless disjoint)
321323
foreach (var entry in indexedShapes)
322324
{
323325
string id = entry.Key;
@@ -368,7 +370,8 @@ private void doTest(SpatialOperation operation)
368370
args.DistErrPct = (0.0);//a hack; we want to be more detailed than gridSnap(queryShape)
369371
Query query = strategy.MakeQuery(args);
370372
SearchResults got = executeQuery(query, 100);
371-
ISet<String> remainingExpectedIds = new JCG.LinkedHashSet<string>(expectedIds);
373+
// LUCENENET specific: OrderedHashSet<T> is a replacement for LinkedHashSet<E> in the JDK
374+
ISet<String> remainingExpectedIds = new JCG.OrderedHashSet<string>(expectedIds);
372375
foreach (SearchResult result in got.results)
373376
{
374377
String id = result.GetId();

src/Lucene.Net.Tests/Search/TestFieldCache.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,8 @@ public virtual void Test()
362362
{
363363
termOrds.SetDocument(i);
364364
// this will remove identical terms. A DocTermOrds doesn't return duplicate ords for a docId
365-
ISet<BytesRef> values = new JCG.LinkedHashSet<BytesRef>(multiValued[i]);
365+
// LUCENENET specific: OrderedHashSet<T> is a replacement for LinkedHashSet<E> in the JDK
366+
ISet<BytesRef> values = new JCG.OrderedHashSet<BytesRef>(multiValued[i]);
366367
foreach (BytesRef v in values)
367368
{
368369
if (v is null)

src/Lucene.Net.Tests/Support/BaseConcurrentSetTestCase.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -399,12 +399,13 @@ public void TestSynchronizedSet()
399399
}
400400

401401
/// <summary>
402-
/// Runs the synchronized set tests using <see cref="J2N.Collections.Generic.LinkedHashSet{T}"/> as the inner set type.
402+
/// Runs the synchronized set tests using <see cref="J2N.Collections.Generic.OrderedHashSet{T}"/> as the inner set type.
403403
/// </summary>
404404
[Test]
405-
public void TestSynchronizedSet_LinkedHashSet()
405+
public void TestSynchronizedSet_OrderedHashSet()
406406
{
407-
BaseTestSynchronizedSet(() => new JCG.LinkedHashSet<object?>());
407+
// LUCENENET specific: OrderedHashSet<T> is a replacement for LinkedHashSet<E> in the JDK
408+
BaseTestSynchronizedSet(() => new JCG.OrderedHashSet<object?>());
408409
}
409410

410411
protected void BaseTestSynchronizedSet(Func<ISet<object?>> innerSetFactory)

src/Lucene.Net.Tests/Support/TestConcurrentSet.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,9 @@ namespace Lucene.Net
3838
/// </remarks>
3939
public class TestConcurrentSet : BaseConcurrentSetTestCase
4040
{
41+
// LUCENENET specific: OrderedHashSet<T> is a replacement for LinkedHashSet<E> in the JDK
4142
protected override ISet<T> NewSet<T>()
42-
=> new ConcurrentSet<T>(new JCG.LinkedHashSet<T>());
43+
=> new ConcurrentSet<T>(new JCG.OrderedHashSet<T>());
4344

4445
protected override ISet<T> NewSet<T>(ISet<T> set)
4546
=> new ConcurrentSet<T>(set);
@@ -51,7 +52,8 @@ protected override ISet<T> NewSet<T>(ISet<T> set)
5152
[Test, LuceneNetSpecific]
5253
public async Task TestSyncRoot()
5354
{
54-
var innerSet = new JCG.LinkedHashSet<int>();
55+
// LUCENENET specific: OrderedHashSet<T> is a replacement for LinkedHashSet<E> in the JDK
56+
var innerSet = new JCG.OrderedHashSet<int>();
5557
var set = new ConcurrentSet<int>(innerSet);
5658
Assert.IsNotNull(set.SyncRoot);
5759

@@ -97,7 +99,8 @@ public async Task TestSyncRoot()
9799
[Test, LuceneNetSpecific]
98100
public void TestGetEnumerator()
99101
{
100-
var innerSet = new JCG.LinkedHashSet<int>();
102+
// LUCENENET specific: OrderedHashSet<T> is a replacement for LinkedHashSet<E> in the JDK
103+
var innerSet = new JCG.OrderedHashSet<int>();
101104
var set = new ConcurrentSet<int>(innerSet);
102105
for (int i = 0; i < 100; i++)
103106
{

src/Lucene.Net/Index/IndexReader.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,8 @@ private protected IndexReader() // LUCENENET: Changed from internal to private p
9999

100100
// LUCENENET specific - de-nested IReaderClosedListener and renamed to IReaderDisposedListener
101101

102-
private readonly ISet<IReaderDisposedListener> readerDisposedListeners = new JCG.LinkedHashSet<IReaderDisposedListener>().AsConcurrent();
102+
// LUCENENET specific: OrderedHashSet<T> is a replacement for LinkedHashSet<E> in the JDK
103+
private readonly ISet<IReaderDisposedListener> readerDisposedListeners = new JCG.OrderedHashSet<IReaderDisposedListener>().AsConcurrent();
103104

104105
private readonly ConditionalWeakTable<IndexReader, object> parentReaders = new ConditionalWeakTable<IndexReader, object>();
105106

src/Lucene.Net/Index/SegmentCoreReaders.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ internal sealed class SegmentCoreReaders
7070
internal readonly DisposableThreadLocal<TermVectorsReader> termVectorsLocal;
7171
internal readonly DisposableThreadLocal<IDictionary<string, object>> normsLocal =
7272
new DisposableThreadLocal<IDictionary<string, object>>(() => new JCG.Dictionary<string, object>());
73-
private readonly ISet<ICoreDisposedListener> coreClosedListeners = new JCG.LinkedHashSet<ICoreDisposedListener>().AsConcurrent();
73+
// LUCENENET specific: OrderedHashSet<T> is a replacement for LinkedHashSet<E> in the JDK
74+
private readonly ISet<ICoreDisposedListener> coreClosedListeners = new JCG.OrderedHashSet<ICoreDisposedListener>().AsConcurrent();
7475

7576
internal SegmentCoreReaders(SegmentReader owner, Directory dir, SegmentCommitInfo si, IOContext context, int termsIndexDivisor)
7677
{

0 commit comments

Comments
 (0)