Skip to content

Commit

Permalink
Merge pull request #33 from dadhi/tree234
Browse files Browse the repository at this point in the history
  • Loading branch information
dadhi authored Jun 25, 2020
2 parents ed0bbb3 + 4951022 commit 47078cf
Show file tree
Hide file tree
Showing 9 changed files with 1,319 additions and 101 deletions.
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: 2.0.0-preview-{build}
version: 2.1.0-preview-{build}
os: Visual Studio 2017

test: off
Expand Down
2 changes: 1 addition & 1 deletion nuspecs/ImTools.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata minClientVersion="3.3.0">
<id>ImTools</id>
<version>2.0.0</version>
<version>2.1.0-preview-01</version>
<authors>Maksim Volkau</authors>
<copyright>Copyright © 2016-2020 Maksim Volkau</copyright>
<projectUrl>https://github.com/dadhi/ImTools</projectUrl>
Expand Down
310 changes: 281 additions & 29 deletions playground/ImTools.Benchmarks/ImMapBenchmarks.cs

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions playground/ImTools.Benchmarks/ImTools.Benchmarks.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
<TargetFramework Condition="'$(TravisCI)' == 'true'">netcoreapp2.1</TargetFramework>
<Description>Benchmarks and sandbox for experiments.</Description>
<NoWarn>1701;1702;AD0001;NU1608</NoWarn>
<TieredCompilation>false</TieredCompilation>
<!--skip tiering jitting for the fare benchmarks -->
<DebugType>pdbonly</DebugType>
<DebugSymbols>true</DebugSymbols>
</PropertyGroup>
<ItemGroup>
<Compile Remove="HashVsImHashMap.cs" />
Expand Down
5 changes: 3 additions & 2 deletions playground/ImTools.Benchmarks/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ static void Main()
//b.ImMap_FixedData4();

//BenchmarkRunner.Run<ImMapBenchmarks.Populate>();
//BenchmarkRunner.Run<ImMapBenchmarks.Lookup>();
BenchmarkRunner.Run<ImMapBenchmarks.Lookup>();
//BenchmarkRunner.Run<ImMapBenchmarks.LookupMissing>();
//BenchmarkRunner.Run<ImMapBenchmarks.Enumerate>();

BenchmarkRunner.Run<ImHashMapBenchmarks.Populate>();
// BenchmarkRunner.Run<ImHashMapBenchmarks.Populate>();
//BenchmarkRunner.Run<ImHashMapBenchmarks.Lookup>();
//BenchmarkRunner.Run<ImHashMapBenchmarks.Enumerate>();

Expand Down
968 changes: 902 additions & 66 deletions src/ImTools/ImTools.Experimental.cs

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/ImTools/ImTools.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
<TargetFrameworks Condition="'$(LocalBuild)' == 'true'">net40;net45;netstandard1.0;netstandard1.3;netstandard2.0</TargetFrameworks>

<Product>ImTools</Product>
<VersionPrefix>2.0.0</VersionPrefix>
<VersionSuffix></VersionSuffix>
<VersionPrefix>2.1.0</VersionPrefix>
<VersionSuffix>preview-01</VersionSuffix>

<AssemblyName>$(Product)</AssemblyName>
<AssemblyTitle>$(AssemblyName) $(TargetFramework)</AssemblyTitle>
Expand Down
125 changes: 125 additions & 0 deletions test/ImTools.UnitTests/Experimental.ImMap234Tests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
using System;
using NUnit.Framework;

namespace ImTools.Experimental.UnitTests
{
[TestFixture]
public class ImMap234Tests
{
[Test]
public void Adding_keys_from_1_to_10_and_checking_the_tree_shape_on_each_addition()
{
var m = ImMap234<int>.Empty;
Assert.AreEqual(default(int), m.GetValueOrDefault(0));
Assert.AreEqual(default(int), m.GetValueOrDefault(13));

m = m.AddOrUpdate(1, 1);
Assert.IsInstanceOf<ImMap234<int>.Entry>(m);
Assert.AreEqual(1, m.GetValueOrDefault(1));

m = m.AddOrUpdate(2, 2);
Assert.IsInstanceOf<ImMap234<int>.Leaf2>(m);
Assert.AreEqual(2, m.GetValueOrDefault(2));

m = m.AddOrUpdate(3, 3);
Assert.IsInstanceOf<ImMap234<int>.Leaf3>(m);
Assert.AreEqual(3, m.GetValueOrDefault(3));

m = m.AddOrUpdate(4, 4);
Assert.IsInstanceOf<ImMap234<int>.Leaf4>(m);
Assert.AreEqual(4, m.GetValueOrDefault(4));
Assert.AreEqual(3, m.GetValueOrDefault(3));
Assert.AreEqual(2, m.GetValueOrDefault(2));
Assert.AreEqual(1, m.GetValueOrDefault(1));

m = m.AddOrUpdate(5, 5);
Assert.IsInstanceOf<ImMap234<int>.Leaf5>(m);
Assert.AreEqual(5, m.GetValueOrDefault(5));

m = m.AddOrUpdate(6, 6);
Assert.IsInstanceOf<ImMap234<int>.Branch2>(m);
Assert.IsInstanceOf<ImMap234<int>.Leaf3>(((ImMap234<int>.Branch2)m).Left);
Assert.IsInstanceOf<ImMap234<int>.Leaf2>(((ImMap234<int>.Branch2)m).Right);
Assert.AreEqual(3, m.GetValueOrDefault(3));
Assert.AreEqual(5, m.GetValueOrDefault(5));
Assert.AreEqual(6, m.GetValueOrDefault(6));

m = m.AddOrUpdate(7, 7);
Assert.IsInstanceOf<ImMap234<int>.Branch2>(m);
Assert.AreEqual(7, m.GetValueOrDefault(7));

m = m.AddOrUpdate(8, 8);
Assert.IsInstanceOf<ImMap234<int>.Branch2>(m);
Assert.AreEqual(8, m.GetValueOrDefault(8));

m = m.AddOrUpdate(9, 9);
Assert.AreEqual(9, m.GetValueOrDefault(9));

m = m.AddOrUpdate(10, 10);
Assert.AreEqual(10, m.GetValueOrDefault(10));
}

[Test]
public void Adding_1000_keys_and_randomly_checking()
{
var m = ImMap234<int>.Empty;
for (var i = 0; i < 1000; i++)
{
m = m.AddOrUpdate(i, i);
}

Assert.AreEqual(1, m.GetValueOrDefault(1));
Assert.AreEqual(0, m.GetValueOrDefault(0));
Assert.AreEqual(13, m.GetValueOrDefault(13));
Assert.AreEqual(66, m.GetValueOrDefault(66));
Assert.AreEqual(555, m.GetValueOrDefault(555));
Assert.AreEqual(333, m.GetValueOrDefault(333));
Assert.AreEqual(999, m.GetValueOrDefault(999));

// non-existing keys
Assert.AreEqual(0, m.GetValueOrDefault(1000));
Assert.AreEqual(0, m.GetValueOrDefault(-1));
}

[Test]
public void Adding_1000_keys_descending_and_randomly_checking()
{
var m = ImMap234<int>.Empty;
for (var i = 1000 - 1; i >= 0; i--)
{
m = m.AddOrUpdate(i, i);
}

Assert.AreEqual(1, m.GetValueOrDefault(1));
Assert.AreEqual(0, m.GetValueOrDefault(0));
Assert.AreEqual(13, m.GetValueOrDefault(13));
Assert.AreEqual(66, m.GetValueOrDefault(66));
Assert.AreEqual(555, m.GetValueOrDefault(555));
Assert.AreEqual(333, m.GetValueOrDefault(333));
Assert.AreEqual(999, m.GetValueOrDefault(999));

// non-existing keys
Assert.AreEqual(0, m.GetValueOrDefault(1000));
Assert.AreEqual(0, m.GetValueOrDefault(-1));
}

[Test]
public void Adding_1000_keys_randomly_and_randomly_checking()
{
var rnd = new Random();

var m = ImMap234<int>.Empty;
for (var i = 0; i < 100; i++)
{
var n = rnd.Next(0, 1000);
m = m.AddOrUpdate(n, n);
Assert.AreEqual(n, m.GetValueOrDefault(n));
}

// non-existing keys
Assert.AreEqual(0, m.GetValueOrDefault(1000));
Assert.AreEqual(0, m.GetValueOrDefault(-1));
}

}
}

0 comments on commit 47078cf

Please sign in to comment.