Rename because it is ordered

This commit is contained in:
Linus Björnstam 2026-05-07 07:44:55 +02:00
parent b5b363ae9f
commit e3cec3423b
28 changed files with 104 additions and 104 deletions

View file

@ -0,0 +1,40 @@
using System.Collections;
namespace PersistentOrderedMap;
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 TransientOrderedMap(Node<K> root, TStrategy strategy, int count)
: base(root, strategy, count)
{
_transactionId = OwnerId.Next();
}
public void Set(K key, V value)
{
_root = BTreeFunctions.Set(_root, key, value, _strategy, _transactionId, out bool countChanged);
if (countChanged) Count++;
}
public void Remove(K key)
{
_root = BTreeFunctions.Remove<K,V, TStrategy>(_root, key, _strategy, _transactionId, out bool removed);
if (removed) Count--;
}
public PersistentOrderedMap<K, V, TStrategy> ToPersistent()
{
// 1. Create the snapshot by copying all relevant information
var snapshot = new PersistentOrderedMap<K, V, TStrategy>(_root, _strategy, Count);
// 2. Protect the snapshot from THIS TransientOrderedMap by getting a new ownerId
// so that future edits will be done by CoW
_transactionId = OwnerId.Next();
return snapshot;
}
}