Skip to content

Commit 687264a

Browse files
committed
Added Utf16Utf8Dictionary.
1 parent 7ccb426 commit 687264a

File tree

4 files changed

+584
-0
lines changed

4 files changed

+584
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
using System;
2+
using System.Runtime.CompilerServices;
3+
4+
namespace BTDB.Collections;
5+
6+
public readonly struct DerivedUtf16Utf8Dictionary<TDerivedValue, TValue>
7+
{
8+
readonly Utf16Utf8Dictionary<TValue> _parent;
9+
readonly TDerivedValue[] _values;
10+
11+
public DerivedUtf16Utf8Dictionary(Utf16Utf8Dictionary<TValue> parent)
12+
{
13+
_parent = parent;
14+
_values = new TDerivedValue[parent.Count];
15+
}
16+
17+
public Utf16Utf8Dictionary<TValue> Parent => _parent;
18+
19+
public ref TDerivedValue ValueRef(uint index)
20+
{
21+
return ref _values[index];
22+
}
23+
24+
public ref TDerivedValue GetValueRef(ReadOnlySpan<char> key, out bool found)
25+
{
26+
var index = _parent.GetIndex(key);
27+
if (index >= 0)
28+
{
29+
found = true;
30+
return ref _values[(uint)index];
31+
}
32+
33+
found = false;
34+
return ref Unsafe.NullRef<TDerivedValue>();
35+
}
36+
37+
public ref TDerivedValue GetValueRef(ReadOnlySpan<byte> key, out bool found)
38+
{
39+
var index = _parent.GetIndex(key);
40+
if (index >= 0)
41+
{
42+
found = true;
43+
return ref _values[(uint)index];
44+
}
45+
46+
found = false;
47+
return ref Unsafe.NullRef<TDerivedValue>();
48+
}
49+
50+
public bool TryGetValue(ReadOnlySpan<char> key, out TDerivedValue value)
51+
{
52+
var index = _parent.GetIndex(key);
53+
if (index >= 0)
54+
{
55+
value = _values[(uint)index];
56+
return true;
57+
}
58+
59+
value = default;
60+
return false;
61+
}
62+
63+
public bool TryGetValue(ReadOnlySpan<byte> key, out TDerivedValue value)
64+
{
65+
var index = _parent.GetIndex(key);
66+
if (index >= 0)
67+
{
68+
value = _values[(uint)index];
69+
return true;
70+
}
71+
72+
value = default;
73+
return false;
74+
}
75+
}

0 commit comments

Comments
 (0)