Rename because it is ordered
This commit is contained in:
parent
b5b363ae9f
commit
e3cec3423b
28 changed files with 104 additions and 104 deletions
|
|
@ -2,7 +2,7 @@
|
|||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{B0432C7A-80E2-4EA6-8FAB-B8F23A8C39DE}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PersistentMap", "PersistentMap\PersistentMap.csproj", "{CA49AA3C-0CE6-4735-887F-FB3631D63CEE}"
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PersistentOrderedMap", "PersistentOrderedMap\PersistentOrderedMap.csproj", "{CA49AA3C-0CE6-4735-887F-FB3631D63CEE}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestProject1", "TestProject1\TestProject1.csproj", "{9E499000-5E37-42F8-89D2-E18A53F0EF0C}"
|
||||
EndProject
|
||||
|
|
@ -2,7 +2,7 @@ using System.Numerics;
|
|||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace PersistentMap
|
||||
namespace PersistentOrderedMap
|
||||
{
|
||||
public static class BTreeFunctions
|
||||
{
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
using System.Collections;
|
||||
|
||||
namespace PersistentMap;
|
||||
namespace PersistentOrderedMap;
|
||||
|
||||
public abstract class BaseOrderedMap<K, V, TStrategy> : IEnumerable<KeyValuePair<K, V>> where TStrategy : IKeyStrategy<K>
|
||||
{
|
||||
|
|
@ -37,17 +37,17 @@ public abstract class BaseOrderedMap<K, V, TStrategy> : IEnumerable<KeyValuePair
|
|||
// Bootstrap / Factory Helpers
|
||||
// ---------------------------------------------------------
|
||||
|
||||
public static PersistentMap<K, V, TStrategy> Create(TStrategy strategy)
|
||||
public static PersistentOrderedMap<K, V, TStrategy> Create(TStrategy strategy)
|
||||
{
|
||||
// Start with an empty leaf owned by None so the first write triggers CoW.
|
||||
var emptyRoot = new LeafNode<K, V>(OwnerId.None, strategy.UsesPrefixes);
|
||||
return new PersistentMap<K, V, TStrategy>(emptyRoot, strategy, 0);
|
||||
return new PersistentOrderedMap<K, V, TStrategy>(emptyRoot, strategy, 0);
|
||||
}
|
||||
|
||||
public static TransientMap<K, V, TStrategy> CreateTransient(TStrategy strategy)
|
||||
public static TransientOrderedMap<K, V, TStrategy> CreateTransient(TStrategy strategy)
|
||||
{
|
||||
var emptyRoot = new LeafNode<K, V>(OwnerId.None, strategy.UsesPrefixes);
|
||||
return new TransientMap<K, V, TStrategy>(emptyRoot, strategy,0);
|
||||
return new TransientOrderedMap<K, V, TStrategy>(emptyRoot, strategy,0);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
using System.Collections;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace PersistentMap;
|
||||
namespace PersistentOrderedMap;
|
||||
|
||||
|
||||
|
||||
|
|
@ -3,7 +3,7 @@ using System.Runtime.CompilerServices;
|
|||
using System.Runtime.Intrinsics;
|
||||
using System.Runtime.Intrinsics.X86;
|
||||
|
||||
namespace PersistentMap;
|
||||
namespace PersistentOrderedMap;
|
||||
|
||||
using System;
|
||||
using System.Buffers.Binary;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
namespace PersistentMap;
|
||||
namespace PersistentOrderedMap;
|
||||
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
namespace PersistentMap;
|
||||
namespace PersistentOrderedMap;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
public struct DoubleStrategy : IKeyStrategy<double>
|
||||
|
|
@ -3,7 +3,7 @@ using System.Runtime.CompilerServices;
|
|||
using System.Runtime.Intrinsics;
|
||||
using System.Runtime.Intrinsics.X86;
|
||||
|
||||
namespace PersistentMap;
|
||||
namespace PersistentOrderedMap;
|
||||
|
||||
public static class IntScanner
|
||||
{
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
namespace PersistentMap;
|
||||
namespace PersistentOrderedMap;
|
||||
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
namespace PersistentMap;
|
||||
namespace PersistentOrderedMap;
|
||||
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.Intrinsics;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
namespace PersistentMap;
|
||||
namespace PersistentOrderedMap;
|
||||
|
||||
using System.Runtime.CompilerServices;
|
||||
/// <summary>
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace PersistentMap;
|
||||
namespace PersistentOrderedMap;
|
||||
|
||||
[Flags]
|
||||
public enum NodeFlags : byte
|
||||
|
|
@ -1,25 +1,25 @@
|
|||
using System.Collections;
|
||||
|
||||
namespace PersistentMap;
|
||||
namespace PersistentOrderedMap;
|
||||
|
||||
public sealed class PersistentMap<K, V, TStrategy> : BaseOrderedMap<K, V, TStrategy>, IEnumerable, IEnumerable<KeyValuePair<K, V>> where TStrategy : IKeyStrategy<K>
|
||||
public sealed class PersistentOrderedMap<K, V, TStrategy> : BaseOrderedMap<K, V, TStrategy>, IEnumerable, IEnumerable<KeyValuePair<K, V>> where TStrategy : IKeyStrategy<K>
|
||||
{
|
||||
internal PersistentMap(Node<K> root, TStrategy strategy, int count)
|
||||
internal PersistentOrderedMap(Node<K> root, TStrategy strategy, int count)
|
||||
: base(root, strategy, count) { }
|
||||
|
||||
// ---------------------------------------------------------
|
||||
// Immutable Write API (Returns new Map)
|
||||
// ---------------------------------------------------------
|
||||
public PersistentMap<K, V, TStrategy> Set(K key, V value)
|
||||
public PersistentOrderedMap<K, V, TStrategy> Set(K key, V value)
|
||||
{
|
||||
// OPTIMIZATION: Use OwnerId.None (0).
|
||||
// This signals EnsureEditable to always copy the root path,
|
||||
// producing a new tree of nodes that also have OwnerId.None.
|
||||
var newRoot = BTreeFunctions.Set(_root, key, value, _strategy, OwnerId.None, out bool countChanged);
|
||||
return new PersistentMap<K, V, TStrategy>(newRoot, _strategy, countChanged ? Count + 1 : Count);
|
||||
return new PersistentOrderedMap<K, V, TStrategy>(newRoot, _strategy, countChanged ? Count + 1 : Count);
|
||||
}
|
||||
|
||||
public static PersistentMap<K, V, TStrategy> Empty(TStrategy strategy)
|
||||
public static PersistentOrderedMap<K, V, TStrategy> Empty(TStrategy strategy)
|
||||
{
|
||||
// Create an empty Leaf Node.
|
||||
// 'default(OwnerId)' (usually 0) marks this node as Immutable/Persistent.
|
||||
|
|
@ -27,18 +27,18 @@ public sealed class PersistentMap<K, V, TStrategy> : BaseOrderedMap<K, V, TStrat
|
|||
// instead of modifying it in place.
|
||||
var emptyRoot = new LeafNode<K, V>(default(OwnerId), strategy.UsesPrefixes);
|
||||
|
||||
return new PersistentMap<K, V, TStrategy>(emptyRoot, strategy, 0);
|
||||
return new PersistentOrderedMap<K, V, TStrategy>(emptyRoot, strategy, 0);
|
||||
}
|
||||
|
||||
public PersistentMap<K, V, TStrategy> Remove(K key)
|
||||
public PersistentOrderedMap<K, V, TStrategy> Remove(K key)
|
||||
{
|
||||
var newRoot = BTreeFunctions.Remove<K,V, TStrategy>(_root, key, _strategy, OwnerId.None, out bool removed);
|
||||
if (!removed) return this;
|
||||
return new PersistentMap<K, V, TStrategy>(newRoot, _strategy, Count - 1);
|
||||
return new PersistentOrderedMap<K, V, TStrategy>(newRoot, _strategy, Count - 1);
|
||||
}
|
||||
|
||||
public TransientMap<K, V, TStrategy> ToTransient()
|
||||
public TransientOrderedMap<K, V, TStrategy> ToTransient()
|
||||
{
|
||||
return new TransientMap<K, V, TStrategy>(_root, _strategy, Count);
|
||||
return new TransientOrderedMap<K, V, TStrategy>(_root, _strategy, Count);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,13 +1,13 @@
|
|||
using System.Collections;
|
||||
|
||||
namespace PersistentMap;
|
||||
namespace PersistentOrderedMap;
|
||||
|
||||
public sealed class TransientMap<K, V, TStrategy> : BaseOrderedMap<K, V, TStrategy> where TStrategy : IKeyStrategy<K>
|
||||
public sealed class TransientOrderedMap<K, V, TStrategy> : BaseOrderedMap<K, V, TStrategy> where TStrategy : IKeyStrategy<K>
|
||||
{
|
||||
// This is mutable, but we treat it as readonly for the ID generation logic usually.
|
||||
private OwnerId _transactionId;
|
||||
|
||||
public TransientMap(Node<K> root, TStrategy strategy, int count)
|
||||
public TransientOrderedMap(Node<K> root, TStrategy strategy, int count)
|
||||
: base(root, strategy, count)
|
||||
{
|
||||
_transactionId = OwnerId.Next();
|
||||
|
|
@ -25,13 +25,13 @@ public sealed class TransientMap<K, V, TStrategy> : BaseOrderedMap<K, V, TStrate
|
|||
if (removed) Count--;
|
||||
}
|
||||
|
||||
public PersistentMap<K, V, TStrategy> ToPersistent()
|
||||
public PersistentOrderedMap<K, V, TStrategy> ToPersistent()
|
||||
{
|
||||
// 1. Create the snapshot by copying all relevant information
|
||||
|
||||
var snapshot = new PersistentMap<K, V, TStrategy>(_root, _strategy, Count);
|
||||
var snapshot = new PersistentOrderedMap<K, V, TStrategy>(_root, _strategy, Count);
|
||||
|
||||
// 2. Protect the snapshot from THIS TransientMap by getting a new ownerId
|
||||
// 2. Protect the snapshot from THIS TransientOrderedMap by getting a new ownerId
|
||||
// so that future edits will be done by CoW
|
||||
_transactionId = OwnerId.Next();
|
||||
|
||||
|
|
@ -3,7 +3,7 @@ using System.Collections.Generic;
|
|||
using System.Linq;
|
||||
using Xunit;
|
||||
using Xunit.Abstractions;
|
||||
using PersistentMap;
|
||||
using PersistentOrderedMap;
|
||||
|
||||
public class BTreeFuzzTests
|
||||
{
|
||||
|
|
@ -137,7 +137,7 @@ public class BTreeFuzzTests
|
|||
}
|
||||
}
|
||||
|
||||
private void AssertConsistency(SortedDictionary<int, int> expected, TransientMap<int, int, IntStrategy> actual)
|
||||
private void AssertConsistency(SortedDictionary<int, int> expected, TransientOrderedMap<int, int, IntStrategy> actual)
|
||||
{
|
||||
// 1. Count
|
||||
if (expected.Count != actual.Count)
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ using System.Collections.Generic;
|
|||
using System.Linq;
|
||||
using Xunit;
|
||||
using Xunit.Abstractions;
|
||||
using PersistentMap;
|
||||
using PersistentOrderedMap;
|
||||
|
||||
public class BTreeFuzzTestStandardStrategy
|
||||
{
|
||||
|
|
@ -137,7 +137,7 @@ public class BTreeFuzzTestStandardStrategy
|
|||
}
|
||||
}
|
||||
|
||||
private void AssertConsistency(SortedDictionary<int, int> expected, TransientMap<int, int, StandardStrategy<int>> actual)
|
||||
private void AssertConsistency(SortedDictionary<int, int> expected, TransientOrderedMap<int, int, StandardStrategy<int>> actual)
|
||||
{
|
||||
// 1. Count
|
||||
if (expected.Count != actual.Count)
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
using Xunit;
|
||||
using PersistentMap;
|
||||
using PersistentOrderedMap;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
|
||||
|
|
@ -8,8 +8,8 @@ public class EnumeratorTests
|
|||
// Use IntStrategy for simple numeric testing
|
||||
private readonly IntStrategy _strategy = new();
|
||||
|
||||
// Helper to create a populated PersistentMap quickly
|
||||
private PersistentMap<int, int, IntStrategy> CreateMap(params int[] keys)
|
||||
// Helper to create a populated PersistentOrderedMap quickly
|
||||
private PersistentOrderedMap<int, int, IntStrategy> CreateMap(params int[] keys)
|
||||
{
|
||||
var map = BaseOrderedMap<int, int, IntStrategy>.CreateTransient(_strategy);
|
||||
foreach (var k in keys)
|
||||
|
|
@ -22,7 +22,7 @@ public class EnumeratorTests
|
|||
[Fact]
|
||||
public void EmptyMap_EnumeratesNothing()
|
||||
{
|
||||
var map = PersistentMap<int, int, IntStrategy>.Empty(_strategy);
|
||||
var map = PersistentOrderedMap<int, int, IntStrategy>.Empty(_strategy);
|
||||
var list = new List<int>();
|
||||
|
||||
foreach(var kv in map) list.Add(kv.Key);
|
||||
|
|
|
|||
|
|
@ -1,13 +1,13 @@
|
|||
using System.Linq;
|
||||
using Xunit;
|
||||
using PersistentMap;
|
||||
using PersistentOrderedMap;
|
||||
|
||||
namespace PersistentMap.Tests
|
||||
{
|
||||
public class BTreeExtendedOperationsTests
|
||||
{
|
||||
// Helper to quickly spin up a populated map
|
||||
private TransientMap<int, string, IntStrategy> CreateMap(params int[] keys)
|
||||
private TransientOrderedMap<int, string, IntStrategy> CreateMap(params int[] keys)
|
||||
{
|
||||
var map = BaseOrderedMap<int, string, IntStrategy>.CreateTransient(new IntStrategy());
|
||||
foreach (var key in keys)
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
namespace TestProject1;
|
||||
using PersistentMap;
|
||||
using PersistentOrderedMap;
|
||||
public class PersistenceTests
|
||||
{
|
||||
private readonly UnicodeStrategy _strategy = new UnicodeStrategy();
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
namespace PersistentMap.Tests;
|
||||
using PersistentMap;
|
||||
using PersistentOrderedMap;
|
||||
using System.Linq;
|
||||
using Xunit;
|
||||
public class StandardStrategy
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
namespace TestProject1;
|
||||
|
||||
using PersistentMap;
|
||||
using PersistentOrderedMap;
|
||||
|
||||
public class StressTests
|
||||
{
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@
|
|||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\PersistentMap\PersistentMap.csproj" />
|
||||
<ProjectReference Include="..\PersistentOrderedMap\PersistentOrderedMap.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
namespace TestProject1;
|
||||
|
||||
using Xunit;
|
||||
using PersistentMap;
|
||||
using PersistentOrderedMap;
|
||||
|
||||
public class BasicTests
|
||||
{
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@
|
|||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\PersistentMap\PersistentMap.csproj" />
|
||||
<ProjectReference Include="..\..\PersistentOrderedMap\PersistentOrderedMap.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ using System.Linq;
|
|||
using BenchmarkDotNet.Attributes;
|
||||
using BenchmarkDotNet.Running;
|
||||
using LanguageExt;
|
||||
using PersistentMap;
|
||||
using PersistentOrderedMap;
|
||||
|
||||
namespace MapBenchmarks;
|
||||
|
||||
|
|
@ -26,7 +26,7 @@ public class IntMapBenchmarks
|
|||
private ImmutableSortedDictionary<int, int> _immSortedDict;
|
||||
private LanguageExt.Map<int, int> _extMap;
|
||||
private LanguageExt.HashMap<int, int> _extHashMap;
|
||||
private PersistentMap<int, int, IntStrategy> _persistentMap;
|
||||
private PersistentOrderedMap<int, int, IntStrategy> _persistentOrderedMap;
|
||||
|
||||
private readonly IntStrategy _intStrategy = new IntStrategy();
|
||||
|
||||
|
|
@ -65,7 +65,7 @@ public class IntMapBenchmarks
|
|||
|
||||
var transient = BaseOrderedMap<int, int, IntStrategy>.CreateTransient(_intStrategy);
|
||||
foreach (var k in _allKeys) transient.Set(k, k);
|
||||
_persistentMap = transient.ToPersistent();
|
||||
_persistentOrderedMap = transient.ToPersistent();
|
||||
}
|
||||
|
||||
// --- 1. BUILD ---
|
||||
|
|
@ -103,15 +103,15 @@ public class IntMapBenchmarks
|
|||
}
|
||||
|
||||
[Benchmark]
|
||||
public PersistentMap<int, int, IntStrategy> Build_PersistentMap()
|
||||
public PersistentOrderedMap<int, int, IntStrategy> Build_PersistentMap()
|
||||
{
|
||||
var map = PersistentMap<int, int, IntStrategy>.Empty(_intStrategy);
|
||||
var map = PersistentOrderedMap<int, int, IntStrategy>.Empty(_intStrategy);
|
||||
foreach (var k in _allKeys) map = map.Set(k, k);
|
||||
return map;
|
||||
}
|
||||
|
||||
[Benchmark]
|
||||
public PersistentMap<int, int, IntStrategy> Build_TransientMap()
|
||||
public PersistentOrderedMap<int, int, IntStrategy> Build_TransientMap()
|
||||
{
|
||||
var map = BaseOrderedMap<int, int, IntStrategy>.CreateTransient(_intStrategy);
|
||||
foreach (var k in _allKeys) map.Set(k, k);
|
||||
|
|
@ -161,7 +161,7 @@ public class IntMapBenchmarks
|
|||
{
|
||||
int count = 0;
|
||||
foreach (var k in _retrieveKeys)
|
||||
if (_persistentMap.TryGetValue(k, out _)) count++;
|
||||
if (_persistentOrderedMap.TryGetValue(k, out _)) count++;
|
||||
return count;
|
||||
}
|
||||
|
||||
|
|
@ -176,17 +176,17 @@ public class IntMapBenchmarks
|
|||
}
|
||||
|
||||
[Benchmark]
|
||||
public PersistentMap<int, int, IntStrategy> Update_PersistentMap()
|
||||
public PersistentOrderedMap<int, int, IntStrategy> Update_PersistentMap()
|
||||
{
|
||||
var map = _persistentMap;
|
||||
var map = _persistentOrderedMap;
|
||||
foreach (var k in _updateKeys) map = map.Set(k, 999);
|
||||
return map;
|
||||
}
|
||||
|
||||
[Benchmark]
|
||||
public PersistentMap<int, int, IntStrategy> Update_TransientMap()
|
||||
public PersistentOrderedMap<int, int, IntStrategy> Update_TransientMap()
|
||||
{
|
||||
var transient = _persistentMap.ToTransient();
|
||||
var transient = _persistentOrderedMap.ToTransient();
|
||||
foreach (var k in _updateKeys) transient.Set(k, 999);
|
||||
return transient.ToPersistent();
|
||||
}
|
||||
|
|
@ -226,17 +226,17 @@ public class IntMapBenchmarks
|
|||
}
|
||||
|
||||
[Benchmark]
|
||||
public PersistentMap<int, int, IntStrategy> UpdateSet_PersistentMap()
|
||||
public PersistentOrderedMap<int, int, IntStrategy> UpdateSet_PersistentMap()
|
||||
{
|
||||
var map = _persistentMap;
|
||||
var map = _persistentOrderedMap;
|
||||
foreach (var k in _mixedKeys) map = map.Set(k, 999);
|
||||
return map;
|
||||
}
|
||||
|
||||
[Benchmark]
|
||||
public PersistentMap<int, int, IntStrategy> UpdateSet_TransientMap()
|
||||
public PersistentOrderedMap<int, int, IntStrategy> UpdateSet_TransientMap()
|
||||
{
|
||||
var transient = _persistentMap.ToTransient();
|
||||
var transient = _persistentOrderedMap.ToTransient();
|
||||
foreach (var k in _mixedKeys) transient.Set(k, 999);
|
||||
return transient.ToPersistent();
|
||||
}
|
||||
|
|
@ -279,7 +279,7 @@ public class IntMapBenchmarks
|
|||
public int Iterate_PersistentMap()
|
||||
{
|
||||
int sum = 0;
|
||||
foreach (var kvp in _persistentMap) sum += kvp.Value;
|
||||
foreach (var kvp in _persistentOrderedMap) sum += kvp.Value;
|
||||
return sum;
|
||||
}
|
||||
|
||||
|
|
@ -319,16 +319,16 @@ public class IntMapBenchmarks
|
|||
}
|
||||
|
||||
[Benchmark]
|
||||
public PersistentMap<int, int, IntStrategy> Remove_PersistentMap()
|
||||
public PersistentOrderedMap<int, int, IntStrategy> Remove_PersistentMap()
|
||||
{
|
||||
var map = _persistentMap;
|
||||
var map = _persistentOrderedMap;
|
||||
foreach (var k in _removeKeys) map = map.Remove(k);
|
||||
return map;
|
||||
}
|
||||
[Benchmark]
|
||||
public PersistentMap<int, int, IntStrategy> Remove_TransientMap()
|
||||
public PersistentOrderedMap<int, int, IntStrategy> Remove_TransientMap()
|
||||
{
|
||||
var transient = _persistentMap.ToTransient();
|
||||
var transient = _persistentOrderedMap.ToTransient();
|
||||
foreach (var k in _removeKeys) transient.Remove(k);
|
||||
return transient.ToPersistent();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ using System.Collections.Immutable;
|
|||
using System.Linq;
|
||||
using BenchmarkDotNet.Attributes;
|
||||
using LanguageExt;
|
||||
using PersistentMap;
|
||||
using PersistentOrderedMap;
|
||||
using System.Runtime.CompilerServices;
|
||||
namespace MapBenchmarks;
|
||||
|
||||
|
|
@ -34,8 +34,8 @@ public class StringMapBenchmarks
|
|||
private LanguageExt.Map<string, int> _extMap;
|
||||
private LanguageExt.HashMap<string, int> _extHashMap;
|
||||
|
||||
private PersistentMap<string, int, StandardStrategy2<string, OrdinalComparer>> _persistentMapStandard;
|
||||
private PersistentMap<string, int, UnicodeStrategy> _persistentMapUnicode;
|
||||
private PersistentOrderedMap<string, int, StandardStrategy2<string, OrdinalComparer>> _persistentOrderedMapStandard;
|
||||
private PersistentOrderedMap<string, int, UnicodeStrategy> _persistentOrderedMapUnicode;
|
||||
|
||||
private readonly StandardStrategy2<string, OrdinalComparer> _stdStrategy = new StandardStrategy2<string, OrdinalComparer>(new OrdinalComparer());
|
||||
private readonly UnicodeStrategy _uniStrategy = new UnicodeStrategy();
|
||||
|
|
@ -84,8 +84,8 @@ public class StringMapBenchmarks
|
|||
transStd.Set(_allKeys[i], i);
|
||||
transUni.Set(_allKeys[i], i);
|
||||
}
|
||||
_persistentMapStandard = transStd.ToPersistent();
|
||||
_persistentMapUnicode = transUni.ToPersistent();
|
||||
_persistentOrderedMapStandard = transStd.ToPersistent();
|
||||
_persistentOrderedMapUnicode = transUni.ToPersistent();
|
||||
}
|
||||
|
||||
private static string GenerateRandomString(int length, Random rnd)
|
||||
|
|
@ -97,7 +97,7 @@ public class StringMapBenchmarks
|
|||
// --- 1. BUILD ---
|
||||
|
||||
[Benchmark]
|
||||
public PersistentMap<string, int, StandardStrategy2<string,OrdinalComparer>> Build_TransientMap_Standard()
|
||||
public PersistentOrderedMap<string, int, StandardStrategy2<string,OrdinalComparer>> Build_TransientMap_Standard()
|
||||
{
|
||||
var map = BaseOrderedMap<string, int, StandardStrategy2<string,OrdinalComparer>>.CreateTransient(_stdStrategy);
|
||||
for (int i = 0; i < _allKeys.Length; i++) map.Set(_allKeys[i], i);
|
||||
|
|
@ -105,7 +105,7 @@ public class StringMapBenchmarks
|
|||
}
|
||||
|
||||
[Benchmark]
|
||||
public PersistentMap<string, int, UnicodeStrategy> Build_TransientMap_Unicode()
|
||||
public PersistentOrderedMap<string, int, UnicodeStrategy> Build_TransientMap_Unicode()
|
||||
{
|
||||
var map = BaseOrderedMap<string, int, UnicodeStrategy>.CreateTransient(_uniStrategy);
|
||||
for (int i = 0; i < _allKeys.Length; i++) map.Set(_allKeys[i], i);
|
||||
|
|
@ -162,7 +162,7 @@ public class StringMapBenchmarks
|
|||
{
|
||||
int count = 0;
|
||||
foreach (var k in _retrieveKeys)
|
||||
if (_persistentMapStandard.TryGetValue(k, out _)) count++;
|
||||
if (_persistentOrderedMapStandard.TryGetValue(k, out _)) count++;
|
||||
return count;
|
||||
}
|
||||
|
||||
|
|
@ -171,7 +171,7 @@ public class StringMapBenchmarks
|
|||
{
|
||||
int count = 0;
|
||||
foreach (var k in _retrieveKeys)
|
||||
if (_persistentMapUnicode.TryGetValue(k, out _)) count++;
|
||||
if (_persistentOrderedMapUnicode.TryGetValue(k, out _)) count++;
|
||||
return count;
|
||||
}
|
||||
[Benchmark]
|
||||
|
|
@ -213,32 +213,32 @@ public class StringMapBenchmarks
|
|||
}
|
||||
|
||||
[Benchmark]
|
||||
public PersistentMap<string, int, StandardStrategy2<string, OrdinalComparer>> Update_PersistentMap_Standard()
|
||||
public PersistentOrderedMap<string, int, StandardStrategy2<string, OrdinalComparer>> Update_PersistentMap_Standard()
|
||||
{
|
||||
var map = _persistentMapStandard;
|
||||
var map = _persistentOrderedMapStandard;
|
||||
foreach (var k in _updateKeys) map = map.Set(k, 999);
|
||||
return map;
|
||||
}
|
||||
[Benchmark]
|
||||
public PersistentMap<string, int, UnicodeStrategy> Update_PersistentMap_Unicode()
|
||||
public PersistentOrderedMap<string, int, UnicodeStrategy> Update_PersistentMap_Unicode()
|
||||
{
|
||||
var map = _persistentMapUnicode;
|
||||
var map = _persistentOrderedMapUnicode;
|
||||
foreach (var k in _updateKeys) map = map.Set(k, 999);
|
||||
return map;
|
||||
}
|
||||
|
||||
[Benchmark]
|
||||
public PersistentMap<string, int, StandardStrategy2<string, OrdinalComparer>> Update_TransientMap_Standard()
|
||||
public PersistentOrderedMap<string, int, StandardStrategy2<string, OrdinalComparer>> Update_TransientMap_Standard()
|
||||
{
|
||||
var transient = _persistentMapStandard.ToTransient();
|
||||
var transient = _persistentOrderedMapStandard.ToTransient();
|
||||
foreach (var k in _updateKeys) transient.Set(k, 999);
|
||||
return transient.ToPersistent();
|
||||
}
|
||||
|
||||
[Benchmark]
|
||||
public PersistentMap<string, int, UnicodeStrategy> Update_TransientMap_Unicode()
|
||||
public PersistentOrderedMap<string, int, UnicodeStrategy> Update_TransientMap_Unicode()
|
||||
{
|
||||
var transient = _persistentMapUnicode.ToTransient();
|
||||
var transient = _persistentOrderedMapUnicode.ToTransient();
|
||||
foreach (var k in _updateKeys) transient.Set(k, 999);
|
||||
return transient.ToPersistent();
|
||||
}
|
||||
|
|
@ -278,33 +278,33 @@ public class StringMapBenchmarks
|
|||
}
|
||||
|
||||
[Benchmark]
|
||||
public PersistentMap<string, int, StandardStrategy2<string, OrdinalComparer>> UpdateSet_PersistentMap_Standard()
|
||||
public PersistentOrderedMap<string, int, StandardStrategy2<string, OrdinalComparer>> UpdateSet_PersistentMap_Standard()
|
||||
{
|
||||
var map = _persistentMapStandard;
|
||||
var map = _persistentOrderedMapStandard;
|
||||
foreach (var k in _mixedKeys) map = map.Set(k, 999);
|
||||
return map;
|
||||
}
|
||||
|
||||
[Benchmark]
|
||||
public PersistentMap<string, int, UnicodeStrategy> UpdateSet_PersistentMap_Unicode()
|
||||
public PersistentOrderedMap<string, int, UnicodeStrategy> UpdateSet_PersistentMap_Unicode()
|
||||
{
|
||||
var map = _persistentMapUnicode;
|
||||
var map = _persistentOrderedMapUnicode;
|
||||
foreach (var k in _mixedKeys) map = map.Set(k, 999);
|
||||
return map;
|
||||
}
|
||||
|
||||
[Benchmark]
|
||||
public PersistentMap<string, int, StandardStrategy2<string, OrdinalComparer>> UpdateSet_TransientMap_Standard()
|
||||
public PersistentOrderedMap<string, int, StandardStrategy2<string, OrdinalComparer>> UpdateSet_TransientMap_Standard()
|
||||
{
|
||||
var transient = _persistentMapStandard.ToTransient();
|
||||
var transient = _persistentOrderedMapStandard.ToTransient();
|
||||
foreach (var k in _mixedKeys) transient.Set(k, 999);
|
||||
return transient.ToPersistent();
|
||||
}
|
||||
|
||||
[Benchmark]
|
||||
public PersistentMap<string, int, UnicodeStrategy> UpdateSet_TransientMap_Unicode()
|
||||
public PersistentOrderedMap<string, int, UnicodeStrategy> UpdateSet_TransientMap_Unicode()
|
||||
{
|
||||
var transient = _persistentMapUnicode.ToTransient();
|
||||
var transient = _persistentOrderedMapUnicode.ToTransient();
|
||||
foreach (var k in _mixedKeys) transient.Set(k, 999);
|
||||
return transient.ToPersistent();
|
||||
}
|
||||
|
|
@ -347,7 +347,7 @@ public class StringMapBenchmarks
|
|||
public int Iterate_PersistentMap_Standard()
|
||||
{
|
||||
int sum = 0;
|
||||
foreach (var kvp in _persistentMapStandard) sum += kvp.Value;
|
||||
foreach (var kvp in _persistentOrderedMapStandard) sum += kvp.Value;
|
||||
return sum;
|
||||
}
|
||||
|
||||
|
|
@ -379,7 +379,7 @@ public class StringMapBenchmarks
|
|||
public int Iterate_PersistentMap_Unicode()
|
||||
{
|
||||
int sum = 0;
|
||||
foreach (var kvp in _persistentMapUnicode) sum += kvp.Value;
|
||||
foreach (var kvp in _persistentOrderedMapUnicode) sum += kvp.Value;
|
||||
return sum;
|
||||
}
|
||||
|
||||
|
|
@ -394,33 +394,33 @@ public class StringMapBenchmarks
|
|||
}
|
||||
|
||||
[Benchmark]
|
||||
public PersistentMap<string, int, StandardStrategy2<string, OrdinalComparer>> Remove_PersistentMap_Standard()
|
||||
public PersistentOrderedMap<string, int, StandardStrategy2<string, OrdinalComparer>> Remove_PersistentMap_Standard()
|
||||
{
|
||||
var map = _persistentMapStandard;
|
||||
var map = _persistentOrderedMapStandard;
|
||||
foreach (var k in _removeKeys) map = map.Remove(k);
|
||||
return map;
|
||||
}
|
||||
|
||||
[Benchmark]
|
||||
public PersistentMap<string, int, UnicodeStrategy> Remove_PersistentMap_Unicode()
|
||||
public PersistentOrderedMap<string, int, UnicodeStrategy> Remove_PersistentMap_Unicode()
|
||||
{
|
||||
var map = _persistentMapUnicode;
|
||||
var map = _persistentOrderedMapUnicode;
|
||||
foreach (var k in _removeKeys) map = map.Remove(k);
|
||||
return map;
|
||||
}
|
||||
|
||||
[Benchmark]
|
||||
public PersistentMap<string, int, StandardStrategy2<string, OrdinalComparer>> Remove_TransientMap_Standard()
|
||||
public PersistentOrderedMap<string, int, StandardStrategy2<string, OrdinalComparer>> Remove_TransientMap_Standard()
|
||||
{
|
||||
var transient = _persistentMapStandard.ToTransient();
|
||||
var transient = _persistentOrderedMapStandard.ToTransient();
|
||||
foreach (var k in _removeKeys) transient.Remove(k);
|
||||
return transient.ToPersistent();
|
||||
}
|
||||
|
||||
[Benchmark]
|
||||
public PersistentMap<string, int, UnicodeStrategy> Remove_TransientMap_Unicode()
|
||||
public PersistentOrderedMap<string, int, UnicodeStrategy> Remove_TransientMap_Unicode()
|
||||
{
|
||||
var transient = _persistentMapUnicode.ToTransient();
|
||||
var transient = _persistentOrderedMapUnicode.ToTransient();
|
||||
foreach (var k in _removeKeys) transient.Remove(k);
|
||||
return transient.ToPersistent();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue