diff --git a/.editorconfig b/.editorconfig
index 76e37ea..a9c857c 100644
--- a/.editorconfig
+++ b/.editorconfig
@@ -223,9 +223,20 @@ dotnet_naming_style.begins_with_i.capitalization = pascal_case
# IDE0057: Use range operator
dotnet_diagnostic.IDE0057.severity = silent
+# VSSpell001: Spell Check
+dotnet_diagnostic.VSSpell001.severity = none
+
+# VSSpell002: Spell Check
+dotnet_diagnostic.VSSpell002.severity = none
+
+# IDE0306: Simplify collection initialization
+dotnet_diagnostic.IDE0306.severity = silent
+
dotnet_diagnostic.CS1591.severity = suggestion
csharp_style_prefer_method_group_conversion = true:silent
csharp_style_prefer_top_level_statements = true:silent
+csharp_style_prefer_primary_constructors = true:suggestion
+csharp_prefer_system_threading_lock = true:suggestion
#dotnet_diagnostic.SA0001.severity = suggestion
[*.{cs,vb}]
dotnet_style_coalesce_expression = true:warning
@@ -234,4 +245,10 @@ tab_width = 4
indent_size = 4
end_of_line = crlf
dotnet_style_null_propagation = true:warning
-indent_style = tab
\ No newline at end of file
+indent_style = tab
+dotnet_style_prefer_is_null_check_over_reference_equality_method = true:warning
+dotnet_style_prefer_auto_properties = true:suggestion
+dotnet_style_object_initializer = true:suggestion
+dotnet_style_collection_initializer = true:suggestion
+dotnet_style_prefer_simplified_boolean_expressions = true:warning
+dotnet_diagnostic.CA2007.severity = error
\ No newline at end of file
diff --git a/Trie/ConcurrentTrie.cs b/Trie/ConcurrentTrie.cs
index c360d65..2f7d096 100644
--- a/Trie/ConcurrentTrie.cs
+++ b/Trie/ConcurrentTrie.cs
@@ -6,22 +6,13 @@ namespace Open.Collections;
///
/// A generic Trie collection.
///
-public sealed class ConcurrentTrie
- : TrieBase
+public sealed class ConcurrentTrie(
+ IEqualityComparer? equalityComparer = null)
+ : TrieBase(() => new Node(equalityComparer))
where TKey : notnull
{
- ///
- /// Constructs a .
- ///
- public ConcurrentTrie(IEqualityComparer? equalityComparer = null)
- : base(() => new Node(equalityComparer))
- { }
-
- private sealed class Node : NodeBase
+ private sealed class Node(IEqualityComparer? equalityComparer) : NodeBase
{
- public Node(IEqualityComparer? equalityComparer)
- => _equalityComparer = equalityComparer;
-
private readonly object _valueSync = new();
protected override void SetValue(TValue value)
@@ -31,7 +22,7 @@ protected override void SetValue(TValue value)
private readonly object _childSync = new();
- private readonly IEqualityComparer? _equalityComparer;
+ private readonly IEqualityComparer? _equalityComparer = equalityComparer;
private ConcurrentDictionary>? _children;
protected override void UpdateRecent(TKey key, ITrieNode child)
diff --git a/Trie/Open.Collections.Trie.csproj b/Trie/Open.Collections.Trie.csproj
index ca0fdee..aa1f8a0 100644
--- a/Trie/Open.Collections.Trie.csproj
+++ b/Trie/Open.Collections.Trie.csproj
@@ -26,6 +26,7 @@
snupkg
logo.png
README.md
+ IDE0130;
@@ -44,11 +45,11 @@
-
+
-
+
\ No newline at end of file
diff --git a/Trie/StringJoinPool.cs b/Trie/StringJoinPool.cs
index 1280e0a..1905883 100644
--- a/Trie/StringJoinPool.cs
+++ b/Trie/StringJoinPool.cs
@@ -12,22 +12,12 @@ namespace Open.Collections;
///
/// Useful for (re)generating cache keys.
///
-public class StringJoinPool
+public class StringJoinPool(
+ ITrie pool, ReadOnlyMemory separator)
{
- private readonly ReadOnlyMemory _separator;
- private readonly ITrie _pool;
+ private readonly ITrie _pool = pool ?? throw new ArgumentNullException(nameof(pool));
private StringBuilder? _reusableBuilder;
- ///
- /// Constructs a .
- ///
- /// If the supplied pool is null.
- public StringJoinPool(ITrie pool, ReadOnlyMemory separator)
- {
- _pool = pool ?? throw new ArgumentNullException(nameof(pool));
- _separator = separator;
- }
-
///
public StringJoinPool(ITrie pool, string? separator = null)
: this(pool, separator is null ? ReadOnlyMemory.Empty : separator.AsMemory())
@@ -75,7 +65,7 @@ string Build(ReadOnlySpan segments)
int len = segments.Length;
try
{
- if (_separator.IsEmpty)
+ if (separator.IsEmpty)
{
for (int i = 0; i < len; i++)
AppendSegment(sb, segments[i]);
@@ -85,7 +75,7 @@ string Build(ReadOnlySpan segments)
Debug.Assert(segments.Length != 0);
AppendSegment(sb, segments[0]);
- var sepSpan = _separator.Span;
+ var sepSpan = separator.Span;
int sLen = sepSpan.Length;
for (int i = 1; i < len; i++)
diff --git a/Trie/System.Diagnostics.CodeAnalysis/MaybeNullWhenAttribute.cs b/Trie/System.Diagnostics.CodeAnalysis/MaybeNullWhenAttribute.cs
index a8f0c0c..ce5e8ea 100644
--- a/Trie/System.Diagnostics.CodeAnalysis/MaybeNullWhenAttribute.cs
+++ b/Trie/System.Diagnostics.CodeAnalysis/MaybeNullWhenAttribute.cs
@@ -1,4 +1,5 @@
#if NETSTANDARD2_0
+
namespace System.Diagnostics.CodeAnalysis;
// Use a shim for simplicity.
@@ -6,18 +7,15 @@ namespace System.Diagnostics.CodeAnalysis;
///
/// Indicates that the output may be null even if the corresponding type disallows it.
///
+///
+/// Constructs a .
+///
[AttributeUsage(AttributeTargets.Parameter, Inherited = false)]
-internal sealed class MaybeNullWhenAttribute : Attribute
+internal sealed class MaybeNullWhenAttribute(bool returnValue) : Attribute
{
- ///
- /// Constructs a .
- ///
- public MaybeNullWhenAttribute(bool returnValue)
- => ReturnValue = returnValue;
-
///
/// The return value condition.
///
- public bool ReturnValue { get; }
+ public bool ReturnValue { get; } = returnValue;
}
#endif
\ No newline at end of file
diff --git a/Trie/Trie.cs b/Trie/Trie.cs
index 9ac5a8b..393c47d 100644
--- a/Trie/Trie.cs
+++ b/Trie/Trie.cs
@@ -4,34 +4,25 @@ namespace Open.Collections;
///
/// A generic Trie collection.
///
-public sealed class Trie
- : TrieBase
+public sealed class Trie(
+ IEqualityComparer? equalityComparer = null)
+ : TrieBase(() => new Node(equalityComparer))
where TKey : notnull
{
- ///
- /// Constructs a .
- ///
- public Trie(IEqualityComparer? equalityComparer = null)
- : base(() => new Node(equalityComparer))
- { }
-
- private sealed class Node : NodeBase
+ private sealed class Node(IEqualityComparer? equalityComparer)
+ : NodeBase
{
- private readonly IEqualityComparer? _equalityComparer;
private Dictionary>? _children;
- public Node(IEqualityComparer? equalityComparer)
- => _equalityComparer = equalityComparer;
-
public override ITrieNode GetOrAddChild(TKey key)
{
var children = _children;
if (children is null)
- Children = _children = children = _equalityComparer is null ? new() : new(_equalityComparer);
+ Children = _children = children = equalityComparer is null ? new() : new(equalityComparer);
else if (TryGetChildFrom(children, key, out var c))
return c;
- var child = new Node(_equalityComparer);
+ var child = new Node(equalityComparer);
children[key] = child;
return child;
}
diff --git a/Trie/TrieBase.cs b/Trie/TrieBase.cs
index 77c5dd2..0e65568 100644
--- a/Trie/TrieBase.cs
+++ b/Trie/TrieBase.cs
@@ -221,34 +221,23 @@ internal abstract class NodeBase : ITrieNode
{
protected IDictionary>? Children;
- private readonly struct ValueContainer
+ private readonly struct ValueContainer(bool isSet, TValue value)
{
- public ValueContainer(bool isSet, TValue value)
- {
- IsSet = isSet;
- Value = value;
- }
-
public ValueContainer(TValue value)
: this(true, value) { }
- public bool IsSet { get; }
- public TValue Value { get; }
+ public bool IsSet { get; } = isSet;
+ public TValue Value { get; } = value;
}
private ValueContainer _value;
- private readonly struct Recent
+ private readonly struct Recent(
+ bool exists, TKey key, ITrieNode child)
{
- public Recent(bool exists, TKey key, ITrieNode child)
- {
- Exists = exists;
- Key = key;
- Child = child;
- }
- public bool Exists { get; }
- public TKey Key { get; }
- public ITrieNode Child { get; }
+ public bool Exists { get; } = exists;
+ public TKey Key { get; } = key;
+ public ITrieNode Child { get; } = child;
}
// It's not uncommon to have a 'hot path' that will be requested frequently.
diff --git a/benchmarking/Benchmarks/CollectionBenchmark.cs b/benchmarking/Benchmarks/CollectionBenchmark.cs
index 184f2d2..3d002bf 100644
--- a/benchmarking/Benchmarks/CollectionBenchmark.cs
+++ b/benchmarking/Benchmarks/CollectionBenchmark.cs
@@ -72,13 +72,9 @@ protected override IEnumerable TestOnceInternal()
}
}
-public class CollectionBenchmark : CollectionBenchmark