Skip to content

Commit

Permalink
Minor
Browse files Browse the repository at this point in the history
  • Loading branch information
rampaa committed Jan 31, 2025
1 parent 84a6d68 commit 836db4d
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 4 deletions.
28 changes: 27 additions & 1 deletion JL.Core/Dicts/JMdict/KanjiElement.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,34 @@
namespace JL.Core.Dicts.JMdict;

internal sealed class KanjiElement(string keb, List<string> keInfList)
internal readonly struct KanjiElement(string keb, List<string> keInfList) : IEquatable<KanjiElement>
{
public string Keb { get; } = keb; // e.g. 娘
public List<string> KeInfList { get; } = keInfList; // e.g. Ateji.
// public List<string> KePriList { get; } // e.g. gai1

public override int GetHashCode()
{
unchecked
{
int hash = (17 * 37) + Keb.GetHashCode(StringComparison.Ordinal);
foreach (string keInf in KeInfList)
{
hash = (hash * 37) + keInf.GetHashCode(StringComparison.Ordinal);
}

return hash;
}
}

public override bool Equals(object? obj)
{
return obj is KanjiElement other
&& Keb == other.Keb
&& KeInfList.SequenceEqual(other.KeInfList);
}

public bool Equals(KanjiElement other)
{
return Keb == other.Keb && KeInfList.SequenceEqual(other.KeInfList);
}
}
36 changes: 35 additions & 1 deletion JL.Core/Dicts/JMdict/ReadingElement.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,44 @@
namespace JL.Core.Dicts.JMdict;

internal sealed class ReadingElement(string reb, List<string> reRestrList, List<string> reInfList)
internal readonly struct ReadingElement(string reb, List<string> reRestrList, List<string> reInfList) : IEquatable<ReadingElement>
{
public string Reb { get; } = reb; // Reading in kana. e.g. むすめ
public List<string> ReRestrList { get; } = reRestrList; // ReRestrList = Keb. The reading is only valid for this specific keb.
public List<string> ReInfList { get; } = reInfList; // e.g. gikun
// public bool ReNokanji { get; } // Is kana insufficient to notate the right spelling?
// public List<string> RePriList { get; } // e.g. ichi1

public override int GetHashCode()
{
unchecked
{
int hash = (17 * 37) + Reb.GetHashCode(StringComparison.Ordinal);
foreach (string reRestr in ReRestrList)
{
hash = (hash * 37) + reRestr.GetHashCode(StringComparison.Ordinal);
}

foreach (string reInf in ReInfList)
{
hash = (hash * 37) + reInf.GetHashCode(StringComparison.Ordinal);
}

return hash;
}
}

public override bool Equals(object? obj)
{
return obj is ReadingElement other
&& Reb == other.Reb
&& ReRestrList.SequenceEqual(other.ReRestrList)
&& ReInfList.SequenceEqual(other.ReInfList);
}

public bool Equals(ReadingElement other)
{
return Reb == other.Reb
&& ReRestrList.SequenceEqual(other.ReRestrList)
&& ReInfList.SequenceEqual(other.ReInfList);
}
}
33 changes: 32 additions & 1 deletion JL.Core/Dicts/JMnedict/Translation.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,39 @@
namespace JL.Core.Dicts.JMnedict;

internal sealed class Translation(List<string> nameTypeList, List<string> transDetList)
internal readonly struct Translation(List<string> nameTypeList, List<string> transDetList) : IEquatable<Translation>
{
public List<string> NameTypeList { get; } = nameTypeList;
public List<string> TransDetList { get; } = transDetList;
//public List<string> XRefList { get; }

public override int GetHashCode()
{
unchecked
{
int hash = 17 * 37;
foreach (string nameType in NameTypeList)
{
hash = (hash * 37) + nameType.GetHashCode(StringComparison.Ordinal);
}

foreach (string transDet in TransDetList)
{
hash = (hash * 37) + transDet.GetHashCode(StringComparison.Ordinal);
}

return hash;
}
}

public override bool Equals(object? obj)
{
return obj is Translation other
&& NameTypeList.SequenceEqual(other.NameTypeList)
&& TransDetList.SequenceEqual(other.TransDetList);
}

public bool Equals(Translation other)
{
return NameTypeList.SequenceEqual(other.NameTypeList) && TransDetList.SequenceEqual(other.TransDetList);
}
}
2 changes: 1 addition & 1 deletion JL.Core/Lookup/LookupFrequencyResult.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace JL.Core.Lookup;

public sealed class LookupFrequencyResult
public readonly record struct LookupFrequencyResult
{
internal string Name { get; }
public int Freq { get; }
Expand Down

0 comments on commit 836db4d

Please sign in to comment.