Skip to content

Commit

Permalink
BREAKING: Refactored CharArraySet and CharArrayMap (now CharArrayDict…
Browse files Browse the repository at this point in the history
…ionary) (#762)

* BUG: Lucene.Net.Analysis.Util (CharArraySet + CharArrayMap): Fixed IsReadOnly flag to return the proper value reflecting read-only state. Added tests.

* Lucene.Net.Analysis.Util (CharArraySet + CharArrayMap): Don't call overridable members in constructor (See #670). Added some missing guard clauses.

* BREAKING: Lucene.Net.Analysis.Util (CharArraySet + CharArrayMap): Removed Remove(), IntersectWith(), ExceptWith(), SymmetricExceptWith(), Contains(KeyValuePair) from public APIs by implementing collection interfaces explicitly.

* Lucene.Net.Analysis.Util (CharArraySet + CharArrayMap): Added ToCharArraySet() and ToCharArrayMap() methods and extension methods to make copying collections easier.

* BREAKING: Lucene.Net.Analysis.Util.CharArrayMap: Renamed EntryIterator > Enumerator, removed HasNext, NextKey(), and NextKeyString(), added CurrentKey and CurrentKeyString properties. Removed EntrySet_ class, EntrySet() method.

* BREAKING: Lucene.Net.Analysis.Util: Renamed CharArrayMap > CharArrayDictionary.

* BREAKING: Lucene.Net.Analysis.Util.CharArrayDictionary: Removed EmptyMap() method and created public Empty static field to replace it.

* BREAKING: Lucene.Net.Analysis.Util.CharArraySet: Renamed EMPTY_SET > Empty.

* Lucene.Net.Analysis.Util.CharArrayDictionary: Added missing guard clauses and updated documentation.

* PERFORMANCE: Lucene.Net.Analysis.Util.CharArrayMap: Use CurrentKeyString and CurrentKeyValue to avoid allocation of KeyValuePair

* BUG: Lucene.Net.Analysis.Util.CharArrayMap::Equals(): Use JCG.EqualityComparer when comparing values for equality.

* Lucene.Net.Analysis.Util.CharArraySet: Added missing guard clauses and added documentation.

* PERFORMANCE/BUG: Lucene.Net.Analysis.Util.CharArrayDictionary: Added cases for string and ICharSequence to object overload of PutImpl, ContainsKey, Get, and TryGetValue. Convert unknown types to string in invariant context.

* PERFORMANCE: Lucene.Net.Analysis.Util.CharArrayDictionary: Added optimized PutImpl(string, MapValue) implementation that only allocates a char[] if it is required.

* PERFORMANCE: Lucene.Net.Analysis.Util.CharArrayDictionary: Added Set/SetImpl methods that don't look up the previous value for use in the CharArrayDictionary.this[] overloads.

* Lucene.Net.Analysis.Util.CharArraySet: Changed signature of UnionWith(IEnumerable<string>) to return a bool instead of void. Added explicit interface implementation to adhere to the ISet<string> contract.

* BREAKING: Lucene.Net.Analysis.Util.CharArraySet: Marked ContainsAll() overloads obsolete, since this is duplicate functionality of ISet<T>.IsSupersetOf().

* BREAKING: Lucene.Net.Analysis.Util.CharArrayDictionary: Moved OriginalKeySet property from the public API to explicitly defined on the ICharArrayDictionary interface. Previously it was hidden from Intellisense, so this will have minimal impact.

* Lucene.Net.Analysis.Util (CharArrayDictionary + CharArraySet): Consolidated KeyCollection and UnmodifiableCharArraySet into a single KeyCollection enumerator. Migrated KeyCollection.KeyEnumerator to CharArraySet and renamed it Enumerator. Added ICharArrayDictionaryEnumerator so the necessary members are visible without using generics.

* Lucene.Net.Analysis.Util.CharArrayDictionary: Added documentation to Put() methods that accept a value indicating that this[key] = value is more efficient if the return value is unused.

* PERFORMANCE: Lucene.Net.Analysis.Common: Updated all classes that use CharArrayDictionary<TValue>.Put() and discard the value to use CharArrayDictionary<TValue>.this[] instead.

* Lucene.Net.Analysis.CharArrayDictionary: Added Set() overloads to use to populate CharArraySet

* BREAKING: Lucene.Net.Analysis.Util.CharArraySet::ctor(): Renamed parameter from c > collection.

* Lucene.Net.Analysis.Util.CharArraySet: Added constructor overloads for ICollection<char[]> and ICollection<ICharSequence>.

* Lucene.Net.Analysis.Util.CharArrayDictionary::Copy(): Use pattern matching when converting to CharArrayDictionary<TValue>

* PERFORMANCE: Lucene.Net.Analysis.Util.CharArrayDictionary: Fixed enumerators to use CurrentKey and CurrentValue where appropriate to reduce allocations

* Lucene.Net.Analysis.Util.CharArrayDictionary: Added KeyValuePair<char[], TValue> overload of CopyTo

* Lucene.Net.Analysis.Util.CharArraySet: Fixed implementation of SetEquals() so it matches any IEnumerable<T> type with the same values (accounting for case sensitivity). Added overloads for IEnumerable<char[]>, IEnumerable<ICharSequence> and IEnumerable<T> (object). Added tests.

* Lucene.Net.Analysis.Util.CharArrayDictionary<TValue>: Added error checking to ensure enumerator instances throw InvalidOperationException when the collection state is mutated, or the enumerator is positioned before or after the bounds of the collection.

* Lucene.Net.Analysis.Util.CharArraySet: Added overloads for IEnumerable<char[]> and IEnumerable<ICharSequence> for IsSubset(), IsSuperset(), IsProperSubset() and IsProperSuperset() + tests.

* Lucene.Net.Analysis.Util.CharArraySet: Added overloads of CopyTo() for IList<char[]> and ICharSequence[].

* Lucene.Net.Analysis.Util.CharArraySet: Added tests for IsSubset(), IsProperSubset(), IsSuperset(), IsProperSuperset(), Overlaps(), SetEquals() with null values in the comparison set. Added overloads of char[] and ICharSequence for Overlaps().

* Lucene.Net.Analysis.Util.CharArrayDictionary: Added CopyTo() overload for ICharSequence + added tests for all 3 overloads

* BREAKING: Lucene.Net.Analysis.Util (CharArraySet + CharArrayDictionary<TValue>): Renamed constructor parameters c > collection, startSize > capacity. Changed type of collection from ICollection<T> to IEnumerable<T> to match .NET collections.

* Lucene.Net.Analysis.Util.CharArrayDictionary<TValue>::ToString(): Print "null" when there is a null value to match Java.

* BREAKING: Lucene.Net.Analysis.Util.CharArraySet: Changed parameter type of Copy() and CopySet() methods from ICollection<T> to IEnumerable<T>. Renamed the parameter from set > collection.

* BUG: Lucene.Net.Analysis.Util.CharArrayDictionary<TValue>::ctor(): Don't call virtual methods in the constructor.

* Lucene.Net.Analysis.Util (CharArraySet + CharArrayDictionary): Implemented standard interfaces for collections and enumerators. Consolidated error messages in new SR class.

* BREAKING: Lucene.Net.Analysis.Util.CharArrayDictionary: Removed Get() overloads from the public API. Refactored them to throw KeyNotFoundException instead of returning default(TValue). Enabled nullable reference type support and fixed warnings.

* BREAKING: Lucene.Net.Analysis.Util.CharArrayDictionary: Refactored Put() overloads allow for value types without requiring them to be made nullable. The signature was changed to return a bool and the previousValue (that was returned before) was made into an out parameter.

* BREAKING: Lucene.Net.Analysis.Util (CharArraySet + CharArrayDictionary): Changed all object overloads of common methods from object to T to allow passing through value types without boxing.

* Lucene.Net.Analysis.Util (CharArraySet + CharArrayDictionary): Reworked ConvertObjectToChars() and optimized ICharSequence paths. Fixed both to check ICharSequence.HasValue before using and throw ArgumentNullException if it is not true when setting keys.

* BREAKING: Removed Lucene.Net.Analysis.Util.CharArraySetExtensions. These are edge cases that are now handled by ConvertObjectToChars().

* BREAKING: Removed Lucene.Net.Analysis.Util.CharArrayDictionaryExtensions. These are edge cases that are now handled by ConvertObjectToChars().

* PERFORMANCE: Lucene.Net.Analysis.Util.CharArrayDictionary::Copy(): Use Span<T> when copying the dictionary/set.

* Lucene.Net.Analysis.Util.CharArrayDictionary.Enumerator::CurrentValue: Set to MaybeNull to match SetValue()

* Lucene.Net.Analysis.Util (CharArraySet + CharArrayDictionary): Added documentation for public members

* Lucene.Net.Analysis.Util.CharArrayDictionary: Renamed UnmodifiableCharArrayDictionary > ReadOnlyCharArrayDictionary to conform with .NET conventions.

* BREAKING: Lucene.Net.Analysis.Util (CharArraySet + CharArrayDictionary): Renamed all method parameters to be consistently using text (instead of key) and startIndex (instead of offset)

* BUG: Lucene.Net.Analysis.Util: Fixed this[char[], int, int] setter so it will correctly set an array representing startIndex and length as the key. Added overloads of Put() to allow setting slices of char[].

* Lucene.Net.Analysis.Util.CharArraySet: Added overloads of Add() to allow setting slices of char[].

* Lucene.Net.Analysis.Util.CharArrayDictionary: Fixed Set() and Add() overloads

* BREAKING: Lucene.Net.Analysis.Util: Removed Put() overloads that don't accept a value from the public API. They were only intended to be used by CharArraySet.

* BREAKING: Removed Add(KeyValuePair<string, TValue>) overload from the public API.

* Lucene.Net.Analysis.Util.CharArrayDictionary: Added constructor overloads for char[] and ICharSequence.

* BUG: Lucene.Net.Analysis.Util.CharArraySet::Empty: Changed empty generic closing type for the related CharArrayDictionary from string to object.

* Lucene.Net.Analysis.Util: Changed extension methods to use IEnumerable<T> for better interop with LINQ.
  • Loading branch information
NightOwl888 authored Nov 17, 2022
1 parent 71adb4d commit 987274e
Show file tree
Hide file tree
Showing 61 changed files with 5,403 additions and 2,680 deletions.
18 changes: 13 additions & 5 deletions Directory.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,23 @@

<Import Project=".build/dependencies.props" Condition="Exists('.build/dependencies.props')" />

<!-- Features in .NET 6.x only -->
<PropertyGroup Condition=" $(TargetFramework.StartsWith('net6.')) ">

<DefineConstants>$(DefineConstants);FEATURE_SPANFORMATTABLE</DefineConstants>

</PropertyGroup>

<!-- Features in .NET 5.x and .NET 6.x only -->
<PropertyGroup Condition=" $(TargetFramework.StartsWith('net5.')) Or $(TargetFramework.StartsWith('net6.')) ">

<DefineConstants>$(DefineConstants);FEATURE_ASPNETCORE_ENDPOINT_CONFIG</DefineConstants>
<DefineConstants>$(DefineConstants);FEATURE_READONLYSET</DefineConstants>

</PropertyGroup>

<!-- Features in .NET Core 3.x, .NET 5.x, and .NET 6.x only -->
<PropertyGroup Condition=" $(TargetFramework.StartsWith('netcoreapp3.')) Or $(TargetFramework.StartsWith('net5.')) Or '$(TargetFramework)' == 'net6.0' ">
<PropertyGroup Condition=" $(TargetFramework.StartsWith('netcoreapp3.')) Or $(TargetFramework.StartsWith('net5.')) Or $(TargetFramework.StartsWith('net6.')) ">

<DefineConstants>$(DefineConstants);FEATURE_ARGITERATOR</DefineConstants>
<DefineConstants>$(DefineConstants);FEATURE_DICTIONARY_REMOVE_CONTINUEENUMERATION</DefineConstants>
Expand All @@ -39,7 +47,7 @@
</PropertyGroup>

<!-- Features in .NET Standard, .NET Core, .NET 5.x, and .NET 6.x only (no .NET Framework support) -->
<PropertyGroup Condition=" $(TargetFramework.StartsWith('netstandard')) Or $(TargetFramework.StartsWith('netcoreapp')) Or '$(TargetFramework)' == 'net5.0' Or '$(TargetFramework)' == 'net6.0' ">
<PropertyGroup Condition=" $(TargetFramework.StartsWith('netstandard')) Or $(TargetFramework.StartsWith('netcoreapp')) Or $(TargetFramework.StartsWith('net5.')) Or $(TargetFramework.StartsWith('net6.')) ">

<DefineConstants>$(DefineConstants);NETSTANDARD</DefineConstants>
<DefineConstants>$(DefineConstants);FEATURE_ARRAYEMPTY</DefineConstants>
Expand All @@ -50,7 +58,7 @@
</PropertyGroup>

<!-- Features in .NET Standard 2.1, .NET 5.x, and .NET 6.x only -->
<PropertyGroup Condition=" '$(TargetFramework)' == 'netstandard2.1' Or $(TargetFramework.StartsWith('netcoreapp3.')) Or '$(TargetFramework)' == 'net5.0' Or '$(TargetFramework)' == 'net6.0' ">
<PropertyGroup Condition=" '$(TargetFramework)' == 'netstandard2.1' Or $(TargetFramework.StartsWith('netcoreapp3.')) Or $(TargetFramework.StartsWith('net5.')) Or $(TargetFramework.StartsWith('net6.')) ">

<DefineConstants>$(DefineConstants);FEATURE_CONDITIONALWEAKTABLE_ENUMERATOR</DefineConstants>
<DefineConstants>$(DefineConstants);FEATURE_CONDITIONALWEAKTABLE_ADDORUPDATE</DefineConstants>
Expand All @@ -61,14 +69,14 @@
</PropertyGroup>

<!-- Features in .NET Standard 2.x, .NET Core 2.x, .NET Core 3.x, .NET 5.x, and .NET 6.x -->
<PropertyGroup Condition=" $(TargetFramework.StartsWith('netstandard2.')) Or $(TargetFramework.StartsWith('netcoreapp2.')) Or $(TargetFramework.StartsWith('netcoreapp3.')) Or '$(TargetFramework)' == 'net5.0' Or '$(TargetFramework)' == 'net6.0' ">
<PropertyGroup Condition=" $(TargetFramework.StartsWith('netstandard2.')) Or $(TargetFramework.StartsWith('netcoreapp2.')) Or $(TargetFramework.StartsWith('netcoreapp3.')) Or $(TargetFramework.StartsWith('net5.')) Or $(TargetFramework.StartsWith('net6.')) ">

<DefineConstants>$(DefineConstants);FEATURE_ICONFIGURATIONROOT_PROVIDERS</DefineConstants>

</PropertyGroup>

<!-- Features in .NET Framework 4.5+, .NET Standard 2.x, .NET Core 2.x, .NET Core 3.x, .NET 5.x, and .NET 6.x -->
<PropertyGroup Condition=" $(TargetFramework.StartsWith('net4')) Or $(TargetFramework.StartsWith('netstandard2.')) Or $(TargetFramework.StartsWith('netcoreapp2.')) Or $(TargetFramework.StartsWith('netcoreapp3.')) Or '$(TargetFramework)' == 'net5.0' Or '$(TargetFramework)' == 'net6.0' ">
<PropertyGroup Condition=" $(TargetFramework.StartsWith('net4')) Or $(TargetFramework.StartsWith('netstandard2.')) Or $(TargetFramework.StartsWith('netcoreapp2.')) Or $(TargetFramework.StartsWith('netcoreapp3.')) Or $(TargetFramework.StartsWith('net5.')) Or $(TargetFramework.StartsWith('net6.')) ">

<DefineConstants>$(DefineConstants);FEATURE_ASSEMBLY_GETCALLINGASSEMBLY</DefineConstants>
<DefineConstants>$(DefineConstants);FEATURE_FILESTREAM_LOCK</DefineConstants>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public ArabicAnalyzer(LuceneVersion matchVersion)
/// <param name="stopwords">
/// a stopword set </param>
public ArabicAnalyzer(LuceneVersion matchVersion, CharArraySet stopwords)
: this(matchVersion, stopwords, CharArraySet.EMPTY_SET)
: this(matchVersion, stopwords, CharArraySet.Empty)
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public BulgarianAnalyzer(LuceneVersion matchVersion)
/// Builds an analyzer with the given stop words.
/// </summary>
public BulgarianAnalyzer(LuceneVersion matchVersion, CharArraySet stopwords)
: this(matchVersion, stopwords, CharArraySet.EMPTY_SET)
: this(matchVersion, stopwords, CharArraySet.Empty)
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ private static CharArraySet LoadDefaultStopSet() // LUCENENET: Avoid static cons
/// <summary>
/// Contains words that should be indexed but not stemmed.
/// </summary>
private CharArraySet excltable = CharArraySet.EMPTY_SET;
private CharArraySet excltable = CharArraySet.Empty;

/// <summary>
/// Builds an analyzer with the default stop words (<see cref="DefaultStopSet"/>).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public CatalanAnalyzer(LuceneVersion matchVersion)
/// <param name="matchVersion"> lucene compatibility version </param>
/// <param name="stopwords"> a stopword set </param>
public CatalanAnalyzer(LuceneVersion matchVersion, CharArraySet stopwords)
: this(matchVersion, stopwords, CharArraySet.EMPTY_SET)
: this(matchVersion, stopwords, CharArraySet.Empty)
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30688,13 +30688,13 @@ private static readonly IDictionary<string, string> upperCaseVariantsAccepted
{"amp", "AMP" },
};

private static readonly CharArrayMap<char> entityValues = LoadEntityValues();
private static readonly CharArrayDictionary<char> entityValues = LoadEntityValues();

private static CharArrayMap<char> LoadEntityValues() // LUCENENET: Avoid static constructors (see https://github.com/apache/lucenenet/pull/224#issuecomment-469284006)
private static CharArrayDictionary<char> LoadEntityValues() // LUCENENET: Avoid static constructors (see https://github.com/apache/lucenenet/pull/224#issuecomment-469284006)
{
CharArrayMap<char> entityValues
CharArrayDictionary<char> entityValues
#pragma warning disable 612, 618
= new CharArrayMap<char>(LuceneVersion.LUCENE_CURRENT, 253, false);
= new CharArrayDictionary<char>(LuceneVersion.LUCENE_CURRENT, 253, false);
#pragma warning restore 612, 618
string[] entities = {
"AElig", "\u00C6", "Aacute", "\u00C1", "Acirc", "\u00C2",
Expand Down Expand Up @@ -30774,10 +30774,10 @@ CharArrayMap<char> entityValues
for (int i = 0; i < entities.Length; i += 2)
{
var value = entities[i + 1][0];
entityValues.Put(entities[i], value);
entityValues[entities[i]] = value;
if (upperCaseVariantsAccepted.TryGetValue(entities[i], out string upperCaseVariant) && upperCaseVariant != null)
{
entityValues.Put(upperCaseVariant, value);
entityValues[upperCaseVariant] = value;
}
}
return entityValues;
Expand Down Expand Up @@ -31611,7 +31611,7 @@ private int NextChar()
int length = YyLength;
inputSegment.Write(zzBuffer, zzStartRead, length);
entitySegment.Clear();
char ch = entityValues.Get(zzBuffer, zzStartRead, length);
char ch = entityValues[zzBuffer, zzStartRead, length];
entitySegment.Append(ch);
outputSegment = entitySegment;
YyBegin(CHARACTER_REFERENCE_TAIL);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public SoraniAnalyzer(LuceneVersion matchVersion)
/// <param name="matchVersion"> lucene compatibility version </param>
/// <param name="stopwords"> a stopword set </param>
public SoraniAnalyzer(LuceneVersion matchVersion, CharArraySet stopwords)
: this(matchVersion, stopwords, CharArraySet.EMPTY_SET)
: this(matchVersion, stopwords, CharArraySet.Empty)
{
}

Expand Down
16 changes: 15 additions & 1 deletion src/Lucene.Net.Analysis.Common/Analysis/Core/StopFilter.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Lucene version compatibility level 4.8.1
// Lucene version compatibility level 4.8.1
using Lucene.Net.Analysis.TokenAttributes;
using Lucene.Net.Analysis.Util;
using Lucene.Net.Util;
Expand Down Expand Up @@ -115,6 +115,20 @@ public static CharArraySet MakeStopSet<T1>(LuceneVersion matchVersion, IList<T1>
return stopSet;
}

/// <summary>
/// Creates a stopword set from the given stopword list. </summary>
/// <param name="matchVersion"> <see cref="LuceneVersion"/> to enable correct Unicode 4.0 behavior in the returned set if Version > 3.0 </param>
/// <param name="stopWords"> A List of <see cref="string"/>s or <see cref="T:char[]"/> or any other ToString()-able list representing the stopwords </param>
/// <param name="ignoreCase"> if true, all words are lower cased first </param>
/// <returns> A Set (<see cref="CharArraySet"/>) containing the words </returns>
// LUCENENET specific - Optimization to go through the string version of UnionWith
public static CharArraySet MakeStopSet(LuceneVersion matchVersion, IList<string> stopWords, bool ignoreCase)
{
var stopSet = new CharArraySet(matchVersion, stopWords.Count, ignoreCase);
stopSet.UnionWith(stopWords);
return stopSet;
}

/// <summary>
/// Returns the next input Token whose Term is not a stop word.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public CzechAnalyzer(LuceneVersion matchVersion)
/// <param name="matchVersion"> <see cref="LuceneVersion"/> to match </param>
/// <param name="stopwords"> a stopword set </param>
public CzechAnalyzer(LuceneVersion matchVersion, CharArraySet stopwords)
: this(matchVersion, stopwords, CharArraySet.EMPTY_SET)
: this(matchVersion, stopwords, CharArraySet.Empty)
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public DanishAnalyzer(LuceneVersion matchVersion)
/// <param name="matchVersion"> lucene compatibility version </param>
/// <param name="stopwords"> a stopword set </param>
public DanishAnalyzer(LuceneVersion matchVersion, CharArraySet stopwords)
: this(matchVersion, stopwords, CharArraySet.EMPTY_SET)
: this(matchVersion, stopwords, CharArraySet.Empty)
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public GermanAnalyzer(LuceneVersion matchVersion)
/// <param name="stopwords">
/// a stopword set </param>
public GermanAnalyzer(LuceneVersion matchVersion, CharArraySet stopwords)
: this(matchVersion, stopwords, CharArraySet.EMPTY_SET)
: this(matchVersion, stopwords, CharArraySet.Empty)
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public EnglishAnalyzer(LuceneVersion matchVersion)
/// <param name="matchVersion"> lucene compatibility version </param>
/// <param name="stopwords"> a stopword set </param>
public EnglishAnalyzer(LuceneVersion matchVersion, CharArraySet stopwords)
: this(matchVersion, stopwords, CharArraySet.EMPTY_SET)
: this(matchVersion, stopwords, CharArraySet.Empty)
{
}

Expand Down
45 changes: 21 additions & 24 deletions src/Lucene.Net.Analysis.Common/Analysis/En/KStemmer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -339,11 +339,11 @@ internal DictEntry(string root, bool isException)
}
}

private static readonly CharArrayMap<DictEntry> dict_ht = InitializeDictHash();
private static readonly CharArrayDictionary<DictEntry> dict_ht = InitializeDictHash();

// caching off
//
// private int maxCacheSize; private CharArrayMap{String} cache =
// private int maxCacheSize; private CharArrayDictionary{String} cache =
// null; private static final String SAME = "SAME"; // use if stemmed form is
// the same

Expand All @@ -357,7 +357,7 @@ internal DictEntry(string root, bool isException)
private int k;

// private void initializeStemHash() { if (maxCacheSize > 0) cache = new
// CharArrayMap<String>(maxCacheSize,false); }
// CharArrayDictionary<String>(maxCacheSize,false); }

private char FinalChar => word[k];

Expand Down Expand Up @@ -388,20 +388,20 @@ private bool IsCons(int index)
}
}

private static CharArrayMap<DictEntry> InitializeDictHash()
private static CharArrayDictionary<DictEntry> InitializeDictHash()
{
DictEntry defaultEntry;
DictEntry entry;

#pragma warning disable 612, 618
CharArrayMap<DictEntry> d = new CharArrayMap<DictEntry>(LuceneVersion.LUCENE_CURRENT, 1000, false);
CharArrayDictionary<DictEntry> d = new CharArrayDictionary<DictEntry>(LuceneVersion.LUCENE_CURRENT, 1000, false);
#pragma warning restore 612, 618
for (int i = 0; i < exceptionWords.Length; i++)
{
if (!d.ContainsKey(exceptionWords[i]))
{
entry = new DictEntry(exceptionWords[i], true);
d.Put(exceptionWords[i], entry);
d[exceptionWords[i]] = entry;
}
else
{
Expand All @@ -414,7 +414,7 @@ private static CharArrayMap<DictEntry> InitializeDictHash()
if (!d.ContainsKey(directConflations[i][0]))
{
entry = new DictEntry(directConflations[i][1], false);
d.Put(directConflations[i][0], entry);
d[directConflations[i][0]] = entry;
}
else
{
Expand All @@ -427,7 +427,7 @@ private static CharArrayMap<DictEntry> InitializeDictHash()
if (!d.ContainsKey(countryNationality[i][0]))
{
entry = new DictEntry(countryNationality[i][1], false);
d.Put(countryNationality[i][0], entry);
d[countryNationality[i][0]] = entry;
}
else
{
Expand All @@ -444,7 +444,7 @@ private static CharArrayMap<DictEntry> InitializeDictHash()
{
if (!d.ContainsKey(array[i]))
{
d.Put(array[i], defaultEntry);
d[array[i]] = defaultEntry;
}
else
{
Expand All @@ -457,7 +457,7 @@ private static CharArrayMap<DictEntry> InitializeDictHash()
{
if (!d.ContainsKey(array[i]))
{
d.Put(array[i], defaultEntry);
d[array[i]] = defaultEntry;
}
else
{
Expand All @@ -470,7 +470,7 @@ private static CharArrayMap<DictEntry> InitializeDictHash()
{
if (!d.ContainsKey(array[i]))
{
d.Put(array[i], defaultEntry);
d[array[i]] = defaultEntry;
}
else
{
Expand All @@ -483,7 +483,7 @@ private static CharArrayMap<DictEntry> InitializeDictHash()
{
if (!d.ContainsKey(array[i]))
{
d.Put(array[i], defaultEntry);
d[array[i]] = defaultEntry;
}
else
{
Expand All @@ -496,7 +496,7 @@ private static CharArrayMap<DictEntry> InitializeDictHash()
{
if (!d.ContainsKey(array[i]))
{
d.Put(array[i], defaultEntry);
d[array[i]] = defaultEntry;
}
else
{
Expand All @@ -509,7 +509,7 @@ private static CharArrayMap<DictEntry> InitializeDictHash()
{
if (!d.ContainsKey(array[i]))
{
d.Put(array[i], defaultEntry);
d[array[i]] = defaultEntry;
}
else
{
Expand All @@ -522,7 +522,7 @@ private static CharArrayMap<DictEntry> InitializeDictHash()
{
if (!d.ContainsKey(array[i]))
{
d.Put(array[i], defaultEntry);
d[array[i]] = defaultEntry;
}
else
{
Expand All @@ -534,7 +534,7 @@ private static CharArrayMap<DictEntry> InitializeDictHash()
{
if (!d.ContainsKey(KStemData8.data[i]))
{
d.Put(KStemData8.data[i], defaultEntry);
d[KStemData8.data[i]] = defaultEntry;
}
else
{
Expand All @@ -546,7 +546,7 @@ private static CharArrayMap<DictEntry> InitializeDictHash()
{
if (!d.ContainsKey(supplementDict[i]))
{
d.Put(supplementDict[i], defaultEntry);
d[supplementDict[i]] = defaultEntry;
}
else
{
Expand All @@ -558,7 +558,7 @@ private static CharArrayMap<DictEntry> InitializeDictHash()
{
if (!d.ContainsKey(properNouns[i]))
{
d.Put(properNouns[i], defaultEntry);
d[properNouns[i]] = defaultEntry;
}
else
{
Expand Down Expand Up @@ -651,8 +651,7 @@ private DictEntry WordInDict()
{
return matchedEntry;
}
DictEntry e = dict_ht.Get(word.Array, 0, word.Length);
if (e != null && !e.exception)
if (dict_ht.TryGetValue(word.Array, 0, word.Length, out DictEntry e) && e != null && !e.exception)
{
matchedEntry = e; // only cache if it's not an exception.
}
Expand Down Expand Up @@ -770,8 +769,7 @@ private bool Lookup()
// thisLookup); } else { // System.out.println("new lookup:" + thisLookup);
// }

matchedEntry = dict_ht.Get(word.Array, 0, word.Length);
return matchedEntry != null;
return dict_ht.TryGetValue(word.Array, 0, word.Length, out matchedEntry) && matchedEntry != null;
}

// Set<String> lookups = new HashSet<>();
Expand Down Expand Up @@ -1872,8 +1870,7 @@ internal virtual bool Stem(char[] term, int len)

// first check the stemmer dictionaries, and avoid using the
// cache if it's in there.
DictEntry entry = dict_ht.Get(term, 0, len);
if (entry != null)
if (dict_ht.TryGetValue(term, 0, len, out DictEntry entry) && entry != null)
{
if (entry.root != null)
{
Expand Down
Loading

0 comments on commit 987274e

Please sign in to comment.