Skip to content

Commit ba45208

Browse files
Reformat/Cleanup.
1 parent 9819c73 commit ba45208

File tree

98 files changed

+8393
-8393
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

98 files changed

+8393
-8393
lines changed

Trie/ITrie.cs

Lines changed: 79 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -8,107 +8,107 @@ namespace Open.Collections;
88
/// Interface for implementing a Trie.
99
/// </summary>
1010
public interface ITrie<TKey, TValue>
11-
where TKey : notnull
11+
where TKey : notnull
1212
{
13-
// NOTE: Path suffixed methods are provided to avoid ambiguity.
13+
// NOTE: Path suffixed methods are provided to avoid ambiguity.
1414

15-
internal ITrieNode<TKey, TValue> EnsureNodes(ReadOnlySpan<TKey> key);
15+
internal ITrieNode<TKey, TValue> EnsureNodes(ReadOnlySpan<TKey> key);
1616

17-
/// <summary>
18-
/// Adds an entry to the Trie.
19-
/// </summary>
20-
/// <returns>Returns <see langword="true"/> if added; otherwise <see langword="false"/> if already exists.</returns>
21-
bool Add(ReadOnlySpan<TKey> key, in TValue value);
17+
/// <summary>
18+
/// Adds an entry to the Trie.
19+
/// </summary>
20+
/// <returns>Returns <see langword="true"/> if added; otherwise <see langword="false"/> if already exists.</returns>
21+
bool Add(ReadOnlySpan<TKey> key, in TValue value);
2222

23-
/// <inheritdoc cref="Add(ReadOnlySpan{TKey}, in TValue)"/>
24-
bool AddPath(IEnumerable<TKey> key, in TValue value);
23+
/// <inheritdoc cref="Add(ReadOnlySpan{TKey}, in TValue)"/>
24+
bool AddPath(IEnumerable<TKey> key, in TValue value);
2525

26-
/// <summary>
27-
/// Resets the trie.
28-
/// </summary>
29-
void Clear();
26+
/// <summary>
27+
/// Resets the trie.
28+
/// </summary>
29+
void Clear();
3030

31-
/// <summary>
32-
/// Determines if a the specified <typeparamref name="TKey"/> exists.
33-
/// </summary>
34-
/// <returns><see langword="true"/> if found; otherwise <see langword="false"/>.</returns>
35-
bool ContainsKey(ReadOnlySpan<TKey> key);
31+
/// <summary>
32+
/// Determines if a the specified <typeparamref name="TKey"/> exists.
33+
/// </summary>
34+
/// <returns><see langword="true"/> if found; otherwise <see langword="false"/>.</returns>
35+
bool ContainsKey(ReadOnlySpan<TKey> key);
3636

37-
/// <inheritdoc cref="ContainsKey(ReadOnlySpan{TKey})"/>
38-
bool ContainsKeyFromPath(ICollection<TKey> key);
37+
/// <inheritdoc cref="ContainsKey(ReadOnlySpan{TKey})"/>
38+
bool ContainsKeyFromPath(ICollection<TKey> key);
3939

40-
/// <inheritdoc cref="ContainsKey(ReadOnlySpan{TKey})"/>
41-
bool ContainsKeyFromPath(IEnumerable<TKey> key);
40+
/// <inheritdoc cref="ContainsKey(ReadOnlySpan{TKey})"/>
41+
bool ContainsKeyFromPath(IEnumerable<TKey> key);
4242

43-
/// <summary>
44-
/// Returns the value if found, otherwise adds using the provided factory function and then returns that value.
45-
/// </summary>
46-
TValue GetOrAdd(ReadOnlySpan<TKey> key, Func<TValue> factory);
43+
/// <summary>
44+
/// Returns the value if found, otherwise adds using the provided factory function and then returns that value.
45+
/// </summary>
46+
TValue GetOrAdd(ReadOnlySpan<TKey> key, Func<TValue> factory);
4747

48-
/// <summary>
49-
/// Returns the value if found, otherwise adds it and returns the value provided.
50-
/// </summary>
51-
TValue GetOrAdd(ReadOnlySpan<TKey> key, in TValue value);
48+
/// <summary>
49+
/// Returns the value if found, otherwise adds it and returns the value provided.
50+
/// </summary>
51+
TValue GetOrAdd(ReadOnlySpan<TKey> key, in TValue value);
5252

53-
/// <inheritdoc cref="GetOrAdd(ReadOnlySpan{TKey}, Func{TValue})"/>
54-
TValue GetOrAddFromPath(ICollection<TKey> key, Func<TValue> factory);
53+
/// <inheritdoc cref="GetOrAdd(ReadOnlySpan{TKey}, Func{TValue})"/>
54+
TValue GetOrAddFromPath(ICollection<TKey> key, Func<TValue> factory);
5555

56-
/// <inheritdoc cref="GetOrAdd(ReadOnlySpan{TKey}, in TValue)"/>
57-
TValue GetOrAddFromPath(ICollection<TKey> key, in TValue value);
56+
/// <inheritdoc cref="GetOrAdd(ReadOnlySpan{TKey}, in TValue)"/>
57+
TValue GetOrAddFromPath(ICollection<TKey> key, in TValue value);
5858

59-
/// <inheritdoc cref="GetOrAdd(ReadOnlySpan{TKey}, Func{TValue})"/>
60-
TValue GetOrAddFromPath(IEnumerable<TKey> key, Func<TValue> factory);
59+
/// <inheritdoc cref="GetOrAdd(ReadOnlySpan{TKey}, Func{TValue})"/>
60+
TValue GetOrAddFromPath(IEnumerable<TKey> key, Func<TValue> factory);
6161

62-
/// <inheritdoc cref="GetOrAdd(ReadOnlySpan{TKey}, in TValue)"/>
63-
TValue GetOrAddFromPath(IEnumerable<TKey> key, in TValue value);
62+
/// <inheritdoc cref="GetOrAdd(ReadOnlySpan{TKey}, in TValue)"/>
63+
TValue GetOrAddFromPath(IEnumerable<TKey> key, in TValue value);
6464

65-
/// <summary>
66-
/// Tries to get a value using the key and sets the <paramref name="value"/> with it if found.
67-
/// </summary>
68-
/// <returns><see langword="true"/> if found; otherwise <see langword="false"/>.</returns>
69-
bool TryGetValue(ReadOnlySpan<TKey> key, [MaybeNullWhen(false)] out TValue value);
65+
/// <summary>
66+
/// Tries to get a value using the key and sets the <paramref name="value"/> with it if found.
67+
/// </summary>
68+
/// <returns><see langword="true"/> if found; otherwise <see langword="false"/>.</returns>
69+
bool TryGetValue(ReadOnlySpan<TKey> key, [MaybeNullWhen(false)] out TValue value);
7070

71-
/// <inheritdoc cref="TryGetValue(ReadOnlySpan{TKey}, out TValue)"/>
72-
bool TryGetValueFromPath(ICollection<TKey> key, [MaybeNullWhen(false)] out TValue value);
71+
/// <inheritdoc cref="TryGetValue(ReadOnlySpan{TKey}, out TValue)"/>
72+
bool TryGetValueFromPath(ICollection<TKey> key, [MaybeNullWhen(false)] out TValue value);
7373

74-
/// <inheritdoc cref="TryGetValue(ReadOnlySpan{TKey}, out TValue)"/>
75-
bool TryGetValueFromPath(IEnumerable<TKey> key, [MaybeNullWhen(false)] out TValue value);
74+
/// <inheritdoc cref="TryGetValue(ReadOnlySpan{TKey}, out TValue)"/>
75+
bool TryGetValueFromPath(IEnumerable<TKey> key, [MaybeNullWhen(false)] out TValue value);
7676
}
7777

7878
/// <summary>
7979
/// Extensions for special cases for a Trie where some .NET versions may not have implicit span conversions for strings.
8080
/// </summary>
8181
public static class TrieExtensions
8282
{
83-
/// <inheritdoc cref="ITrie{TKey, TValue}.Add(ReadOnlySpan{TKey}, in TValue)"/>
84-
[MethodImpl(MethodImplOptions.AggressiveInlining)]
85-
[ExcludeFromCodeCoverage]
86-
public static bool Add<T>(this ITrie<char, T> target, string key, T value)
87-
=> target.Add(key.AsSpan(), value);
88-
89-
/// <inheritdoc cref="ITrie{TKey, TValue}.TryGetValue(ReadOnlySpan{TKey}, out TValue)"/>
90-
[MethodImpl(MethodImplOptions.AggressiveInlining)]
91-
[ExcludeFromCodeCoverage]
92-
public static bool TryGetValue<T>(this ITrie<char, T> target, string key, [MaybeNullWhen(false)] out T value)
93-
=> target.TryGetValue(key.AsSpan(), out value);
94-
95-
/// <inheritdoc cref="ITrie{TKey, TValue}.ContainsKey(ReadOnlySpan{TKey})"/>
96-
[MethodImpl(MethodImplOptions.AggressiveInlining)]
97-
[ExcludeFromCodeCoverage]
98-
public static bool ContainsKey<T>(this ITrie<char, T> target, string key)
99-
=> target.ContainsKey(key.AsSpan());
100-
101-
/// <summary>
102-
/// Gets the string instance representing the key.
103-
/// </summary>
104-
/// <remarks>Useful for using as a string pool.</remarks>
105-
public static string Get(this ITrie<char, string> target, ReadOnlySpan<char> key)
106-
{
107-
var node = target.EnsureNodes(key);
108-
if (node.TryGetValue(out string? v))
109-
return v;
110-
111-
string value = key.ToString();
112-
return node.GetOrAdd(in value);
113-
}
83+
/// <inheritdoc cref="ITrie{TKey, TValue}.Add(ReadOnlySpan{TKey}, in TValue)"/>
84+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
85+
[ExcludeFromCodeCoverage]
86+
public static bool Add<T>(this ITrie<char, T> target, string key, T value)
87+
=> target.Add(key.AsSpan(), value);
88+
89+
/// <inheritdoc cref="ITrie{TKey, TValue}.TryGetValue(ReadOnlySpan{TKey}, out TValue)"/>
90+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
91+
[ExcludeFromCodeCoverage]
92+
public static bool TryGetValue<T>(this ITrie<char, T> target, string key, [MaybeNullWhen(false)] out T value)
93+
=> target.TryGetValue(key.AsSpan(), out value);
94+
95+
/// <inheritdoc cref="ITrie{TKey, TValue}.ContainsKey(ReadOnlySpan{TKey})"/>
96+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
97+
[ExcludeFromCodeCoverage]
98+
public static bool ContainsKey<T>(this ITrie<char, T> target, string key)
99+
=> target.ContainsKey(key.AsSpan());
100+
101+
/// <summary>
102+
/// Gets the string instance representing the key.
103+
/// </summary>
104+
/// <remarks>Useful for using as a string pool.</remarks>
105+
public static string Get(this ITrie<char, string> target, ReadOnlySpan<char> key)
106+
{
107+
var node = target.EnsureNodes(key);
108+
if (node.TryGetValue(out string? v))
109+
return v;
110+
111+
string value = key.ToString();
112+
return node.GetOrAdd(in value);
113+
}
114114
}

Trie/ITrieNode.cs

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -6,45 +6,45 @@ namespace Open.Collections;
66
/// A node within a <see cref="ITrie{TKey, TValue}"/>.
77
/// </summary>
88
public interface ITrieNode<TKey, TValue>
9-
where TKey : notnull
9+
where TKey : notnull
1010
{
11-
/// <summary>
12-
/// <see langword="true"/> if the value is set; otherwise <see langword="false"/>.
13-
/// </summary>
14-
bool IsSet { get; }
15-
16-
/// <summary>
17-
/// Gets or adds a child node for the specified key.
18-
/// </summary>
19-
ITrieNode<TKey, TValue> GetOrAddChild(TKey key);
20-
21-
/// <summary>
22-
/// Tries to get the child node for the specified key.
23-
/// </summary>
24-
bool TryGetChild(TKey key, [MaybeNullWhen(false)] out ITrieNode<TKey, TValue> child);
25-
26-
/// <summary>
27-
/// Gets the child node for the specified key or throws if not found
28-
/// </summary>
29-
ITrieNode<TKey, TValue> GetChild(TKey key);
30-
31-
/// <summary>
32-
/// Tries to get the value if it is set.
33-
/// </summary>
34-
bool TryGetValue([MaybeNullWhen(false)] out TValue value);
35-
36-
/// <summary>
37-
/// Tries to set the value if it is not already set.
38-
/// </summary>
39-
bool TrySetValue(in TValue value);
40-
41-
/// <summary>
42-
/// Gets the value if it is set; otherwise adds it and returns the value provided.
43-
/// </summary>
44-
TValue GetOrAdd(in TValue value);
45-
46-
/// <summary>
47-
/// Gets the value.
48-
/// </summary>
49-
TValue? Value { get; }
11+
/// <summary>
12+
/// <see langword="true"/> if the value is set; otherwise <see langword="false"/>.
13+
/// </summary>
14+
bool IsSet { get; }
15+
16+
/// <summary>
17+
/// Gets or adds a child node for the specified key.
18+
/// </summary>
19+
ITrieNode<TKey, TValue> GetOrAddChild(TKey key);
20+
21+
/// <summary>
22+
/// Tries to get the child node for the specified key.
23+
/// </summary>
24+
bool TryGetChild(TKey key, [MaybeNullWhen(false)] out ITrieNode<TKey, TValue> child);
25+
26+
/// <summary>
27+
/// Gets the child node for the specified key or throws if not found
28+
/// </summary>
29+
ITrieNode<TKey, TValue> GetChild(TKey key);
30+
31+
/// <summary>
32+
/// Tries to get the value if it is set.
33+
/// </summary>
34+
bool TryGetValue([MaybeNullWhen(false)] out TValue value);
35+
36+
/// <summary>
37+
/// Tries to set the value if it is not already set.
38+
/// </summary>
39+
bool TrySetValue(in TValue value);
40+
41+
/// <summary>
42+
/// Gets the value if it is set; otherwise adds it and returns the value provided.
43+
/// </summary>
44+
TValue GetOrAdd(in TValue value);
45+
46+
/// <summary>
47+
/// Gets the value.
48+
/// </summary>
49+
TValue? Value { get; }
5050
}

0 commit comments

Comments
 (0)