surpressed all style warnings from the LSP server.

This commit is contained in:
Linus Björnstam 2026-05-21 13:13:22 +02:00
parent 7ee2238248
commit 23c4ac299e
13 changed files with 346 additions and 371 deletions

View file

@ -1,44 +1,43 @@
using System.Collections;
namespace PersistentOrderedMap;
public sealed class PersistentOrderedMap<K, V, TStrategy> : BaseOrderedMap<K, V, TStrategy>, IEnumerable, IEnumerable<KeyValuePair<K, V>> where TStrategy : IKeyStrategy<K>
public sealed class PersistentOrderedMap<TK, TV, TStrategy> : BaseOrderedMap<TK, TV, TStrategy> where TStrategy : IKeyStrategy<TK>
{
internal PersistentOrderedMap(Node<K> root, TStrategy strategy, int count)
internal PersistentOrderedMap(Node<TK> root, TStrategy strategy, int count)
: base(root, strategy, count) { }
// ---------------------------------------------------------
// Immutable Write API (Returns new Map)
// ---------------------------------------------------------
public PersistentOrderedMap<K, V, TStrategy> Set(K key, V value)
public PersistentOrderedMap<TK, TV, TStrategy> Set(TK key, TV 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 PersistentOrderedMap<K, V, TStrategy>(newRoot, _strategy, countChanged ? Count + 1 : Count);
var newRoot = BTreeFunctions.Set(Root, key, value, Strategy, OwnerId.None, out bool countChanged);
return new PersistentOrderedMap<TK, TV, TStrategy>(newRoot, Strategy, countChanged ? Count + 1 : Count);
}
public static PersistentOrderedMap<K, V, TStrategy> Empty(TStrategy strategy)
public static PersistentOrderedMap<TK, TV, TStrategy> Empty(TStrategy strategy)
{
// Create an empty Leaf Node.
// 'default(OwnerId)' (usually 0) marks this node as Immutable/Persistent.
// This ensures that any subsequent Set/Remove will clone this node
// instead of modifying it in place.
var emptyRoot = new LeafNode<K, V>(default(OwnerId), strategy.UsesPrefixes);
var emptyRoot = new LeafNode<TK, TV>(default(OwnerId), strategy.UsesPrefixes);
return new PersistentOrderedMap<K, V, TStrategy>(emptyRoot, strategy, 0);
return new PersistentOrderedMap<TK, TV, TStrategy>(emptyRoot, strategy, 0);
}
public PersistentOrderedMap<K, V, TStrategy> Remove(K key)
public PersistentOrderedMap<TK, TV, TStrategy> Remove(TK key)
{
var newRoot = BTreeFunctions.Remove<K,V, TStrategy>(_root, key, _strategy, OwnerId.None, out bool removed);
var newRoot = BTreeFunctions.Remove<TK,TV, TStrategy>(Root, key, Strategy, OwnerId.None, out bool removed);
if (!removed) return this;
return new PersistentOrderedMap<K, V, TStrategy>(newRoot, _strategy, Count - 1);
return new PersistentOrderedMap<TK, TV, TStrategy>(newRoot, Strategy, Count - 1);
}
public TransientOrderedMap<K, V, TStrategy> ToTransient()
public TransientOrderedMap<TK, TV, TStrategy> ToTransient()
{
return new TransientOrderedMap<K, V, TStrategy>(_root, _strategy, Count);
return new TransientOrderedMap<TK, TV, TStrategy>(Root, Strategy, Count);
}
}