-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7f406e8
commit 2ee5ec7
Showing
10 changed files
with
185 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,13 @@ | ||
<Project> | ||
<PropertyGroup> | ||
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<PackageVersion Include="Backport.System.Threading.Lock" Version="2.0.5" /> | ||
<PackageVersion Include="BenchmarkDotNet" Version="0.14.0" /> | ||
<PackageVersion Include="DotNet.ReproducibleBuilds" Version="1.2.25" /> | ||
<PackageVersion Include="NonBlocking" Version="2.1.2" /> | ||
<PackageVersion Include="System.Collections.Immutable" Version="8.0.0" /> | ||
</ItemGroup> | ||
<Import Project="Versions.props" /> | ||
<PropertyGroup> | ||
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<PackageVersion Include="Backport.System.Threading.Lock" Version="3.0.1" /> | ||
<PackageVersion Include="BenchmarkDotNet" Version="0.14.0" /> | ||
<PackageVersion Include="DotNet.ReproducibleBuilds" Version="1.2.25" /> | ||
<PackageVersion Include="NonBlocking" Version="2.1.2" /> | ||
<PackageVersion Include="System.Collections.Immutable" Version="$(SystemCollectionsImmutableVersion)" /> | ||
</ItemGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
using System; | ||
using System.Collections.Frozen; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
namespace ReadHeavyCollections; | ||
|
||
/// <summary> | ||
/// Provides a set of initialization methods for instances of the <see cref="ReadHeavyDictionary{TKey, TValue}"/> class. | ||
/// </summary> | ||
public static class ReadHeavyDictionary | ||
{ | ||
/// <summary>Creates a <see cref="ReadHeavyDictionary{TKey, TValue}"/> with the specified key/value pairs.</summary> | ||
/// <param name="source">The key/value pairs to use to populate the dictionary.</param> | ||
/// <param name="comparer">The comparer implementation to use to compare keys for equality. If null, <see cref="EqualityComparer{TKey}.Default"/> is used.</param> | ||
/// <typeparam name="TKey">The type of the keys in the dictionary.</typeparam> | ||
/// <typeparam name="TValue">The type of the values in the dictionary.</typeparam> | ||
/// <remarks> | ||
/// If the same key appears multiple times in the input, the latter one in the sequence takes precedence. This differs from | ||
/// <see cref="M:System.Linq.Enumerable.ToDictionary"/>, with which multiple duplicate keys will result in an exception. | ||
/// </remarks> | ||
/// <returns>A <see cref="ReadHeavyDictionary{TKey, TValue}"/> that contains the specified keys and values.</returns> | ||
public static ReadHeavyDictionary<TKey, TValue> ToReadHeavyDictionary<TKey, TValue>(this IEnumerable<KeyValuePair<TKey, TValue>> source, IEqualityComparer<TKey>? comparer = null) | ||
Check warning on line 23 in ReadHeavyCollections/ReadHeavyDictionaryExtensions.cs GitHub Actions / build
|
||
where TKey : notnull => | ||
comparer is null ? new ReadHeavyDictionary<TKey, TValue>(source) : new ReadHeavyDictionary<TKey, TValue>(source, comparer); | ||
|
||
/// <summary>Creates a <see cref="FrozenDictionary{TKey, TSource}"/> from an <see cref="IEnumerable{TSource}"/> according to specified key selector function.</summary> | ||
/// <typeparam name="TSource">The type of the elements of <paramref name="source"/>.</typeparam> | ||
/// <typeparam name="TKey">The type of the key returned by <paramref name="keySelector"/>.</typeparam> | ||
/// <param name="source">An <see cref="IEnumerable{TSource}"/> from which to create a <see cref="FrozenDictionary{TKey, TSource}"/>.</param> | ||
/// <param name="keySelector">A function to extract a key from each element.</param> | ||
/// <param name="comparer">An <see cref="IEqualityComparer{TKey}"/> to compare keys.</param> | ||
/// <returns>A <see cref="FrozenDictionary{TKey, TElement}"/> that contains the keys and values selected from the input sequence.</returns> | ||
public static ReadHeavyDictionary<TKey, TSource> ToReadHeavyDictionary<TSource, TKey>( | ||
this IEnumerable<TSource> source, Func<TSource, TKey> keySelector, IEqualityComparer<TKey>? comparer = null) | ||
Check warning on line 35 in ReadHeavyCollections/ReadHeavyDictionaryExtensions.cs GitHub Actions / build
|
||
where TKey : notnull => | ||
comparer is null ? source.ToDictionary(keySelector).ToReadHeavyDictionary() : source.ToDictionary(keySelector, comparer).ToReadHeavyDictionary(comparer); | ||
|
||
/// <summary>Creates a <see cref="FrozenDictionary{TKey, TElement}"/> from an <see cref="IEnumerable{TSource}"/> according to specified key selector and element selector functions.</summary> | ||
/// <typeparam name="TSource">The type of the elements of <paramref name="source"/>.</typeparam> | ||
/// <typeparam name="TKey">The type of the key returned by <paramref name="keySelector"/>.</typeparam> | ||
/// <typeparam name="TElement">The type of the value returned by <paramref name="elementSelector"/>.</typeparam> | ||
/// <param name="source">An <see cref="IEnumerable{TSource}"/> from which to create a <see cref="FrozenDictionary{TKey, TElement}"/>.</param> | ||
/// <param name="keySelector">A function to extract a key from each element.</param> | ||
/// <param name="elementSelector">A transform function to produce a result element value from each element.</param> | ||
/// <param name="comparer">An <see cref="IEqualityComparer{TKey}"/> to compare keys.</param> | ||
/// <returns>A <see cref="FrozenDictionary{TKey, TElement}"/> that contains the keys and values selected from the input sequence.</returns> | ||
public static ReadHeavyDictionary<TKey, TElement> ToReadHeavyDictionary<TSource, TKey, TElement>( | ||
this IEnumerable<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, TElement> elementSelector, IEqualityComparer<TKey>? comparer = null) | ||
Check warning on line 49 in ReadHeavyCollections/ReadHeavyDictionaryExtensions.cs GitHub Actions / build
|
||
where TKey : notnull => | ||
comparer is null ? source.ToDictionary(keySelector, elementSelector).ToReadHeavyDictionary() : source.ToDictionary(keySelector, elementSelector, comparer).ToReadHeavyDictionary(comparer); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace ReadHeavyCollections; | ||
|
||
/// <summary> | ||
/// Provides a set of initialization methods for instances of the <see cref="ReadHeavySet{T}"/> class. | ||
/// </summary> | ||
public static class ReadHeavySet | ||
{ | ||
/// <summary>Creates a <see cref="ReadHeavySet{T}"/> with the specified values.</summary> | ||
/// <param name="source">The values to use to populate the set.</param> | ||
/// <typeparam name="T">The type of the values in the set.</typeparam> | ||
/// <returns>A ReadHeavy set.</returns> | ||
public static ReadHeavySet<T> Create<T>(params ReadOnlySpan<T> source) => source.ToArray().ToReadHeavySet(); | ||
|
||
/// <summary>Creates a <see cref="ReadHeavySet{T}"/> with the specified values.</summary> | ||
/// <param name="source">The values to use to populate the set.</param> | ||
/// <param name="equalityComparer">The comparer implementation to use to compare values for equality. If null, <see cref="EqualityComparer{T}.Default"/> is used.</param> | ||
/// <typeparam name="T">The type of the values in the set.</typeparam> | ||
/// <returns>A ReadHeavy set.</returns> | ||
public static ReadHeavySet<T> Create<T>(IEqualityComparer<T>? equalityComparer, params ReadOnlySpan<T> source) => source.ToArray().ToReadHeavySet(equalityComparer); | ||
Check warning on line 22 in ReadHeavyCollections/ReadHeavySetExtensions.cs GitHub Actions / build
|
||
|
||
/// <summary>Creates a <see cref="ReadHeavySet{T}"/> with the specified values.</summary> | ||
/// <param name="source">The values to use to populate the set.</param> | ||
/// <param name="comparer">The comparer implementation to use to compare values for equality. If null, <see cref="EqualityComparer{T}.Default"/> is used.</param> | ||
/// <typeparam name="T">The type of the values in the set.</typeparam> | ||
/// <returns>A ReadHeavy set.</returns> | ||
public static ReadHeavySet<T> ToReadHeavySet<T>(this IEnumerable<T> source, IEqualityComparer<T>? comparer = null) => | ||
Check warning on line 29 in ReadHeavyCollections/ReadHeavySetExtensions.cs GitHub Actions / build
|
||
(comparer is null) ? new ReadHeavySet<T>(source) : new ReadHeavySet<T>(source, comparer); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<Project DefaultTargets="Build"> | ||
<PropertyGroup Condition="!$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net8.0'))"> | ||
<SystemCollectionsImmutableVersion>8.0.0</SystemCollectionsImmutableVersion> | ||
</PropertyGroup> | ||
<PropertyGroup Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net8.0'))"> | ||
<SystemCollectionsImmutableVersion>9.0.0</SystemCollectionsImmutableVersion> | ||
</PropertyGroup> | ||
</Project> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.