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

@ -5,27 +5,27 @@ namespace PersistentOrderedMap;
public struct BTreeEnumerable<K, V, TStrategy> : IEnumerable<KeyValuePair<K, V>>
where TStrategy : IKeyStrategy<K>
public struct BTreeEnumerable<TK, TV, TStrategy> : IEnumerable<KeyValuePair<TK, TV>>
where TStrategy : IKeyStrategy<TK>
{
private readonly Node<K> _root;
private readonly Node<TK> _root;
private readonly TStrategy _strategy;
private readonly K _min, _max;
private readonly TK _min, _max;
private readonly bool _hasMin, _hasMax;
public BTreeEnumerable(Node<K> root, TStrategy strategy, bool hasMin, K min, bool hasMax, K max)
public BTreeEnumerable(Node<TK> root, TStrategy strategy, bool hasMin, TK min, bool hasMax, TK max)
{
_root = root; _strategy = strategy;
_hasMin = hasMin; _min = min;
_hasMax = hasMax; _max = max;
}
public BTreeEnumerator<K, V, TStrategy> GetEnumerator()
public BTreeEnumerator<TK, TV, TStrategy> GetEnumerator()
{
return new BTreeEnumerator<K, V, TStrategy>(_root, _strategy, _hasMin, _min, _hasMax, _max);
return new BTreeEnumerator<TK, TV, TStrategy>(_root, _strategy, _hasMin, _min, _hasMax, _max);
}
IEnumerator<KeyValuePair<K, V>> IEnumerable<KeyValuePair<K, V>>.GetEnumerator() => GetEnumerator();
IEnumerator<KeyValuePair<TK, TV>> IEnumerable<KeyValuePair<TK, TV>>.GetEnumerator() => GetEnumerator();
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
}
@ -35,52 +35,52 @@ where TStrategy : IKeyStrategy<K>
// all int-indexed data structures (or bit partitioned ones).
// This should be enough for anyone.
[InlineArray(16)]
internal struct IterNodeBuffer<K>
internal struct IterNodeBuffer<TK>
{
private Node<K> _element0;
private Node<TK> _element0;
}
[InlineArray(16)]
internal struct IterIndexBuffer<K>
internal struct IterIndexBuffer
{
private int _element0;
}
public struct BTreeEnumerator<K, V, TStrategy> : IEnumerator<KeyValuePair<K, V>>
where TStrategy : IKeyStrategy<K>
public struct BTreeEnumerator<TK, TV, TStrategy> : IEnumerator<KeyValuePair<TK, TV>>
where TStrategy : IKeyStrategy<TK>
{
private readonly TStrategy _strategy;
private readonly Node<K> _root;
private readonly Node<TK> _root;
// --- BOUNDS ---
private readonly bool _hasMax;
private readonly K _maxKey;
private readonly TK _maxKey;
private readonly bool _hasMin;
private readonly K _minKey;
private readonly TK _minKey;
// --- INLINE STACK ---
private IterNodeBuffer<K> _nodeStack;
private IterIndexBuffer<K> _indexStack;
private IterNodeBuffer<TK> _nodeStack;
private IterIndexBuffer _indexStack;
private int _depth;
// --- STATE ---
private LeafNode<K, V>? _currentLeaf;
private LeafNode<TK, TV>? _currentLeaf;
private int _currentLeafIndex;
private KeyValuePair<K, V> _current;
private KeyValuePair<TK, TV> _current;
// Unified Constructor
// We use boolean flags because 'K' might be a struct where 'null' is impossible.
public BTreeEnumerator(Node<K> root, TStrategy strategy, bool hasMin, K minKey, bool hasMax, K maxKey)
public BTreeEnumerator(Node<TK>? root, TStrategy strategy, bool hasMin, TK minKey, bool hasMax, TK maxKey)
{
_root = root;
_root = root!;
_strategy = strategy;
_hasMax = hasMax;
_maxKey = maxKey;
_hasMin = hasMin;
_minKey = minKey;
_nodeStack = new IterNodeBuffer<K>();
_indexStack = new IterIndexBuffer<K>(); // Explicit struct init
_nodeStack = new IterNodeBuffer<TK>();
_indexStack = new IterIndexBuffer(); // Explicit struct init
_depth = 0;
_currentLeaf = null;
_currentLeafIndex = -1;
@ -102,7 +102,7 @@ public struct BTreeEnumerator<K, V, TStrategy> : IEnumerator<KeyValuePair<K, V>>
// Logic 1: Unbounded Start (Go to very first item)
private void DiveLeft()
{
Node<K> node = _root;
Node<TK> node = _root;
_depth = 0;
while (!node.IsLeaf)
@ -114,14 +114,14 @@ public struct BTreeEnumerator<K, V, TStrategy> : IEnumerator<KeyValuePair<K, V>>
node = internalNode.Children[0]!;
}
_currentLeaf = node.AsLeaf<V>();
_currentLeaf = node.AsLeaf<TV>();
_currentLeafIndex = -1; // Position before the first element (0)
}
// Logic 2: Bounded Start (Go to specific key)
private void Seek(K key)
private void Seek(TK key)
{
Node<K> node = _root;
Node<TK> node = _root;
_depth = 0;
long keyPrefix = _strategy.UsesPrefixes ? _strategy.GetPrefix(key) : 0;
@ -130,7 +130,7 @@ public struct BTreeEnumerator<K, V, TStrategy> : IEnumerator<KeyValuePair<K, V>>
while (!node.IsLeaf)
{
var internalNode = node.AsInternal();
int idx = BTreeFunctions.FindRoutingIndex<K, TStrategy>(internalNode, key, keyPrefix, _strategy);
int idx = BTreeFunctions.FindRoutingIndex(internalNode, key, keyPrefix, _strategy);
_nodeStack[_depth] = internalNode;
_indexStack[_depth] = idx;
@ -140,8 +140,8 @@ public struct BTreeEnumerator<K, V, TStrategy> : IEnumerator<KeyValuePair<K, V>>
}
// Find index in Leaf
_currentLeaf = node.AsLeaf<V>();
int index = BTreeFunctions.FindIndex<K,V, TStrategy>(_currentLeaf, key, keyPrefix, _strategy);
_currentLeaf = node.AsLeaf<TV>();
int index = BTreeFunctions.FindIndex(_currentLeaf, key, keyPrefix, _strategy);
// Set position to (index - 1) so that the first MoveNext() lands on 'index'
_currentLeafIndex = index - 1;
@ -158,14 +158,14 @@ public struct BTreeEnumerator<K, V, TStrategy> : IEnumerator<KeyValuePair<K, V>>
if (_hasMax)
{
// If Current Key > Max Key, we are done.
if (_strategy.Compare(_currentLeaf.Keys[_currentLeafIndex], _maxKey) > 0)
if (_strategy.Compare(_currentLeaf.Keys![_currentLeafIndex], _maxKey) > 0)
{
_currentLeaf = null; // Close iterator
return false;
}
}
_current = new KeyValuePair<K, V>(_currentLeaf.Keys[_currentLeafIndex], _currentLeaf.Values[_currentLeafIndex]);
_current = new KeyValuePair<TK, TV>(_currentLeaf.Keys![_currentLeafIndex], _currentLeaf.Values[_currentLeafIndex]);
return true;
}
@ -176,14 +176,14 @@ public struct BTreeEnumerator<K, V, TStrategy> : IEnumerator<KeyValuePair<K, V>>
// Check Max Bound immediately for the first item
if (_hasMax)
{
if (_strategy.Compare(_currentLeaf!.Keys[0], _maxKey) > 0)
if (_strategy.Compare(_currentLeaf.Keys![0], _maxKey) > 0)
{
_currentLeaf = null;
return false;
}
}
_current = new KeyValuePair<K, V>(_currentLeaf.Keys[0], _currentLeaf.Values[0]);
_current = new KeyValuePair<TK, TV>(_currentLeaf.Keys![0], _currentLeaf.Values[0]);
return true;
}
@ -204,7 +204,7 @@ public struct BTreeEnumerator<K, V, TStrategy> : IEnumerator<KeyValuePair<K, V>>
_indexStack[_depth] = nextIndex;
_depth++;
Node<K> node = internalNode.Children[nextIndex]!;
Node<TK> node = internalNode.Children[nextIndex]!;
while (!node.IsLeaf)
{
_nodeStack[_depth] = node;
@ -213,7 +213,7 @@ public struct BTreeEnumerator<K, V, TStrategy> : IEnumerator<KeyValuePair<K, V>>
node = node.AsInternal().Children[0]!;
}
_currentLeaf = node.AsLeaf<V>();
_currentLeaf = node.AsLeaf<TV>();
_currentLeafIndex = 0;
return true;
}
@ -221,7 +221,7 @@ public struct BTreeEnumerator<K, V, TStrategy> : IEnumerator<KeyValuePair<K, V>>
return false;
}
public KeyValuePair<K, V> Current => _current;
public KeyValuePair<TK, TV> Current => _current;
object IEnumerator.Current => _current;
public void Reset()
{