Skip to content

Commit

Permalink
created internal LinkHashMap class with allocation free iterators (#3486
Browse files Browse the repository at this point in the history
)

depricated LinkedHashMap class
made CollectionHelper.Remove method public (required fir unit tests) and removed it for netcore frameworks
  • Loading branch information
wilbit committed Feb 11, 2024
1 parent 6933bf0 commit d744821
Show file tree
Hide file tree
Showing 14 changed files with 1,141 additions and 446 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@


using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
Expand All @@ -19,37 +20,41 @@ namespace NHibernate.Test.UtilityTest
{
using System.Threading.Tasks;
[TestFixture]
public class LinkedHashMapFixtureAsync
public class LinkHashMapFixtureAsync
{
private static readonly Player[] players = {
new Player("12341", "Boeta Dippenaar"), new Player("23432", "Gary Kirsten"),
new Player("23411", "Graeme Smith"), new Player("55221", "Jonty Rhodes"),
new Player("61234", "Monde Zondeki"), new Player("23415", "Paul Adams")
};
private static readonly Player[] players =
{
new Player("12341", "Boeta Dippenaar"),
new Player("23432", "Gary Kirsten"),
new Player("23411", "Graeme Smith"),
new Player("55221", "Jonty Rhodes"),
new Player("61234", "Monde Zondeki"),
new Player("23415", "Paul Adams")
};

private static void Fill(IDictionary<string, Player> lhm)
{
foreach (Player player in players)
foreach (var player in players)
lhm.Add(player.Id, player);
}

[Test, Explicit]
public async Task ShowDiffAsync()
{
IDictionary<string, Player> dict = new Dictionary<string, Player>();
IDictionary<string, Player> lhm = new LinkedHashMap<string, Player>();
IDictionary<string, Player> lhm = new LinkHashMap<string, Player>();
Fill(dict);
Fill(lhm);
// Override the first element
Player o = new Player("12341", "Ovirride");
var o = new Player("12341", "Override");
dict[o.Id] = o;
lhm[o.Id] = o;
await (Console.Out.WriteLineAsync("Dictionary order:"));
foreach (KeyValuePair<string, Player> pair in dict)
{
Console.Out.WriteLine("Key->{0}", pair.Key);
}
await (Console.Out.WriteLineAsync("LinkedHashMap order:"));
await (Console.Out.WriteLineAsync("LinkHashMap order:"));
foreach (KeyValuePair<string, Player> pair in lhm)
{
Console.Out.WriteLine("Key->{0}", pair.Key);
Expand All @@ -65,18 +70,18 @@ public async Task PerformanceAsync()

int numOfEntries = Int16.MaxValue;

long[] dictPopulateTicks = new long[numOfRuns];
long[] dictItemTicks = new long[numOfRuns];
var dictPopulateTicks = new long[numOfRuns];
var dictItemTicks = new long[numOfRuns];

long[] linkPopulateTicks = new long[numOfRuns];
long[] linkItemTicks = new long[numOfRuns];
var linkPopulateTicks = new long[numOfRuns];
var linkItemTicks = new long[numOfRuns];

for (int runIndex = 0; runIndex < numOfRuns; runIndex++)
for (var runIndex = 0; runIndex < numOfRuns; runIndex++)
{
string key;
object value;
IDictionary<string, object> dictionary = new Dictionary<string, object>();
IDictionary<string, object> linked = new LinkedHashMap<string, object>();
IDictionary<string, object> linked = new LinkHashMap<string, object>();

long dictStart = DateTime.Now.Ticks;

Expand Down Expand Up @@ -118,12 +123,12 @@ public async Task PerformanceAsync()
linked.Clear();
}

for (int runIndex = 0; runIndex < numOfRuns; runIndex++)
for (var runIndex = 0; runIndex < numOfRuns; runIndex++)
{
decimal linkPopulateOverhead = (linkPopulateTicks[runIndex] / (decimal)dictPopulateTicks[runIndex]);
decimal linkItemOverhead = (linkItemTicks[runIndex] / (decimal)dictItemTicks[runIndex]);

string message = string.Format("LinkedHashMap vs Dictionary (Run-{0}) :",runIndex+1);
string message = string.Format("LinkHashMap vs Dictionary (Run-{0}) :",runIndex+1);
message += "\n POPULATE:";
message += "\n\t linked took " + linkPopulateTicks[runIndex] + " ticks.";
message += "\n\t dictionary took " + dictPopulateTicks[runIndex] + " ticks.";
Expand Down
1 change: 1 addition & 0 deletions src/NHibernate.Test/NHibernate.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
<Compile Include="..\NHibernate\Util\AsyncReaderWriterLock.cs">
<Link>UtilityTest\AsyncReaderWriterLock.cs</Link>
</Compile>
<Compile Include="..\NHibernate\Util\LinkHashMap.cs" Link="UtilityTest\LinkHashMap.cs" />
<Compile Include="..\NHibernate\Collection\Generic\SetHelpers\SetSnapShot.cs">
<Link>UtilityTest\SetSnapShot.cs</Link>
</Compile>
Expand Down
Loading

0 comments on commit d744821

Please sign in to comment.