Changed some formatting
This commit is contained in:
parent
a6e8ced7f7
commit
b5b363ae9f
3 changed files with 23 additions and 19 deletions
|
|
@ -10,9 +10,12 @@ namespace PersistentMap
|
||||||
// Public API
|
// Public API
|
||||||
// ---------------------------------------------------------
|
// ---------------------------------------------------------
|
||||||
|
|
||||||
|
/// <summary>TryGetValue tries to get the value at mapping key. If it finds the key it sets th
|
||||||
|
/// out var to value and returns true. </summary>
|
||||||
public static bool TryGetValue<K, V, TStrategy>(Node<K> root, K key, TStrategy strategy, out V value)
|
public static bool TryGetValue<K, V, TStrategy>(Node<K> root, K key, TStrategy strategy, out V value)
|
||||||
where TStrategy : IKeyStrategy<K>
|
where TStrategy : IKeyStrategy<K>
|
||||||
{
|
{
|
||||||
|
// We always get a strategy to avoid branching already here
|
||||||
long keyPrefix = strategy.UsesPrefixes ? strategy.GetPrefix(key) : 0;
|
long keyPrefix = strategy.UsesPrefixes ? strategy.GetPrefix(key) : 0;
|
||||||
|
|
||||||
Node<K> current = root;
|
Node<K> current = root;
|
||||||
|
|
@ -43,6 +46,7 @@ namespace PersistentMap
|
||||||
{
|
{
|
||||||
root = root.EnsureEditable(owner);
|
root = root.EnsureEditable(owner);
|
||||||
|
|
||||||
|
// Todo, this should really be made a tuple return value to not stress the GC
|
||||||
var splitResult = InsertRecursive(root, key, value, strategy, owner, out countChanged);
|
var splitResult = InsertRecursive(root, key, value, strategy, owner, out countChanged);
|
||||||
|
|
||||||
if (splitResult != null)
|
if (splitResult != null)
|
||||||
|
|
@ -212,7 +216,7 @@ namespace PersistentMap
|
||||||
where TStrategy : IKeyStrategy<K>
|
where TStrategy : IKeyStrategy<K>
|
||||||
{
|
{
|
||||||
|
|
||||||
if (typeof(K) == typeof(int))
|
if (typeof(K) == typeof(int))
|
||||||
{
|
{
|
||||||
Span<K> keys = node.GetKeys();
|
Span<K> keys = node.GetKeys();
|
||||||
ref K firstKeyRef = ref MemoryMarshal.GetReference(keys);
|
ref K firstKeyRef = ref MemoryMarshal.GetReference(keys);
|
||||||
|
|
@ -391,13 +395,13 @@ if (typeof(K) == typeof(int))
|
||||||
right.SetCount(moveCount);
|
right.SetCount(moveCount);
|
||||||
|
|
||||||
if (insertIndex < splitPoint || (splitPoint == 0 && insertIndex == 0))
|
if (insertIndex < splitPoint || (splitPoint == 0 && insertIndex == 0))
|
||||||
{
|
{
|
||||||
InsertIntoLeaf(left, insertIndex, key, value, strategy);
|
InsertIntoLeaf(left, insertIndex, key, value, strategy);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
InsertIntoLeaf(right, insertIndex - splitPoint, key, value, strategy);
|
InsertIntoLeaf(right, insertIndex - splitPoint, key, value, strategy);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new SplitResult<K>(right, right.Keys[0]);
|
return new SplitResult<K>(right, right.Keys[0]);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -135,7 +135,7 @@ public static class IntScanner
|
||||||
return LinearScanGreater(keys.Slice(i), target) + i;
|
return LinearScanGreater(keys.Slice(i), target) + i;
|
||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
private static unsafe int ScanAvx512Greater(ReadOnlySpan<int> keys, int target)
|
private static unsafe int ScanAvx512Greater(ReadOnlySpan<int> keys, int target)
|
||||||
{
|
{
|
||||||
var vTarget = Vector512.Create(target);
|
var vTarget = Vector512.Create(target);
|
||||||
|
|
|
||||||
|
|
@ -90,10 +90,10 @@ public abstract class Node<K>
|
||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public PrefixInternalNode<K> AsPrefixInternal()
|
public PrefixInternalNode<K> AsPrefixInternal()
|
||||||
{
|
{
|
||||||
return Unsafe.As<PrefixInternalNode<K>>(this);
|
return Unsafe.As<PrefixInternalNode<K>>(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public sealed class LeafNode<K, V> : Node<K>
|
public sealed class LeafNode<K, V> : Node<K>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue