Skip to content

Commit

Permalink
Logos and dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkCiliaVincenti committed Nov 24, 2024
1 parent 7f406e8 commit 2ee5ec7
Show file tree
Hide file tree
Showing 10 changed files with 185 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project>
<PropertyGroup>
<LangVersion>preview</LangVersion>
<LangVersion>latest</LangVersion>
<SuppressNETCoreSdkPreviewMessage>true</SuppressNETCoreSdkPreviewMessage>
<CheckNotRecommendedTargetFramework>false</CheckNotRecommendedTargetFramework>
<CheckEolTargetFramework>false</CheckEolTargetFramework>
Expand Down
21 changes: 11 additions & 10 deletions Directory.Packages.props
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>
1 change: 1 addition & 0 deletions ReadHeavyCollections.sln
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
ProjectSection(SolutionItems) = preProject
Directory.Build.props = Directory.Build.props
Directory.Packages.props = Directory.Packages.props
Versions.props = Versions.props
EndProjectSection
EndProject
Global
Expand Down
7 changes: 5 additions & 2 deletions ReadHeavyCollections/ReadHeavyCollections.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net6.0;net7.0;net9.0</TargetFrameworks>
<TargetFrameworks>net6.0;net7.0;net8.0;net9.0</TargetFrameworks>
<Authors>Mark Cilia Vincenti</Authors>
<RepositoryUrl>https://github.com/MarkCiliaVincenti/AsyncKeyedLock.git</RepositoryUrl>
<PackageProjectUrl>https://github.com/MarkCiliaVincenti/AsyncKeyedLock</PackageProjectUrl>
Expand Down Expand Up @@ -60,7 +60,10 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Backport.System.Threading.Lock" Condition="!$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net9.0'))" />
<PackageReference Condition="!$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net9.0'))" Include="Backport.System.Threading.Lock">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>analyzers</IncludeAssets>
</PackageReference>
<PackageReference Include="System.Collections.Immutable" />
</ItemGroup>

Expand Down
77 changes: 76 additions & 1 deletion ReadHeavyCollections/ReadHeavyDictionary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,82 @@ public bool Remove(TKey key, [MaybeNullWhen(false)] out TValue value)
}
return removed;
}
#endregion

#if NET9_0_OR_GREATER
/// <summary>
/// <inheritdoc cref="Dictionary{TKey, TValue}.Capacity"/>
/// </summary>
public int Capacity
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get => _dictionary.Capacity;
}
#endif

/// <summary>
/// <inheritdoc cref="FrozenDictionary{TKey, TValue}.Comparer"/>
/// </summary>
public IEqualityComparer<TKey> Comparer
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get => _frozenDictionary.Comparer;
}

/// <summary>
/// Determines whether the <see cref="ReadHeavyDictionary{TKey, TValue}"/> contains a specific value.
/// </summary>
/// <param name="value">The value to locate in the <see cref="ReadHeavyDictionary{TKey, TValue}"/>. The value can be null for reference types.</param>
/// <returns>true if the <see cref="ReadHeavyDictionary{TKey, TValue}"/> contains an element with the specified value; otherwise, false.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool ContainsValue(TValue value) => _frozenDictionary.Values.Contains(value);

/// <summary>
/// <inheritdoc cref="Dictionary{TKey, TValue}.EnsureCapacity(int)"/>
/// </summary>
/// <param name="capacity"><inheritdoc cref="Dictionary{TKey, TValue}.EnsureCapacity(int)"/></param>
/// <returns>The current capacity of the <see cref="ReadHeavyDictionary{TKey, TValue}"/>.</returns>
/// <exception cref="ArgumentOutOfRangeException" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public int EnsureCapacity(int capacity) => _dictionary.EnsureCapacity(capacity);

/// <summary>
/// <inheritdoc cref="Dictionary{TKey, TValue}.TrimExcess()"/>
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void TrimExcess() => _dictionary.TrimExcess();

/// <summary>
/// <inheritdoc cref="Dictionary{TKey, TValue}.TrimExcess(int)"/>
/// </summary>
/// <param name="capacity"><inheritdoc cref="Dictionary{TKey, TValue}.TrimExcess(int)"/></param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void TrimExcess(int capacity) => _dictionary.TrimExcess(capacity);

#if NET9_0_OR_GREATER
/// <summary>
/// Gets an instance of a type that may be used to perform operations on the current <see cref="ReadHeavyDictionary{TKey, TValue}"/> using a <typeparamref name="TAlternateKey"/> as a key instead of a <typeparamref name="TKey"/>.
/// </summary>
/// <typeparam name="TAlternateKey">The alternate type of a key for performing lookups.</typeparam>
/// <param name="lookup">The created lookup instance when the method returns true, or a default instance that should not be used if the method returns false.</param>
/// <returns>true if a lookup could be created; otherwise, false.</returns>
/// <remarks>
/// The dictionary must be using a comparer that implements <see cref="IAlternateEqualityComparer{TAlternateKey, TKey}"/> with
/// <typeparamref name="TAlternateKey"/> and <typeparamref name="TKey"/>. If it doesn't, the method will return false.
/// </remarks>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool TryGetAlternateLookup<TAlternateKey>(
out Dictionary<TKey, TValue>.AlternateLookup<TAlternateKey> lookup)
where TAlternateKey : notnull, allows ref struct => _dictionary.TryGetAlternateLookup(out lookup);
#endif

/// <summary>
/// <inheritdoc cref="FrozenDictionary{TKey, TValue}.GetValueRefOrNullRef(TKey)"/>
/// </summary>
/// <param name="key"><inheritdoc cref="FrozenDictionary{TKey, TValue}.GetValueRefOrNullRef(TKey)"/></param>
/// <returns><inheritdoc cref="FrozenDictionary{TKey, TValue}.GetValueRefOrNullRef(TKey)"/></returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public ref readonly TValue GetValueRefOrNullRef(TKey key) => ref _frozenDictionary.GetValueRefOrNullRef(key);
#endregion

#region HelperMethods

Expand Down
52 changes: 52 additions & 0 deletions ReadHeavyCollections/ReadHeavyDictionaryExtensions.cs
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

View workflow job for this annotation

GitHub Actions / build

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 23 in ReadHeavyCollections/ReadHeavyDictionaryExtensions.cs

View workflow job for this annotation

GitHub Actions / build

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.
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

View workflow job for this annotation

GitHub Actions / build

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 35 in ReadHeavyCollections/ReadHeavyDictionaryExtensions.cs

View workflow job for this annotation

GitHub Actions / build

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.
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

View workflow job for this annotation

GitHub Actions / build

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 49 in ReadHeavyCollections/ReadHeavyDictionaryExtensions.cs

View workflow job for this annotation

GitHub Actions / build

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.
where TKey : notnull =>
comparer is null ? source.ToDictionary(keySelector, elementSelector).ToReadHeavyDictionary() : source.ToDictionary(keySelector, elementSelector, comparer).ToReadHeavyDictionary(comparer);
}
31 changes: 31 additions & 0 deletions ReadHeavyCollections/ReadHeavySetExtensions.cs
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

View workflow job for this annotation

GitHub Actions / build

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 22 in ReadHeavyCollections/ReadHeavySetExtensions.cs

View workflow job for this annotation

GitHub Actions / build

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

/// <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

View workflow job for this annotation

GitHub Actions / build

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 29 in ReadHeavyCollections/ReadHeavySetExtensions.cs

View workflow job for this annotation

GitHub Actions / build

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.
(comparer is null) ? new ReadHeavySet<T>(source) : new ReadHeavySet<T>(source, comparer);
}
8 changes: 8 additions & 0 deletions Versions.props
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>
Binary file added logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added logo32.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 2ee5ec7

Please sign in to comment.