Skip to content

Commit

Permalink
Cleanup and optimizations, update changelog
Browse files Browse the repository at this point in the history
  • Loading branch information
mikernet committed Mar 12, 2024
1 parent e329d0b commit 2a993bb
Show file tree
Hide file tree
Showing 10 changed files with 16 additions and 23 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Singulink Collections Version History

## V3.0
### Singulink.Collections
- Breaking change: Deprecated `Singulink.Collections.Abstractions` package. Types have been merged into the main `Singulink.Collections` package.
- Performance improvements to `ListDictionary<,>.ValueList` and `HashSetDictionary<,>.ValueSet`.
- Minor documentation fixes.

## V2.0
### All packages
- Removed support for end-of-life .NET and .NET Framework runtimes with a build warning if used on an unsupported runtime
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ The following collections are included in the package:
- `Map`: Collection of two types of values that map between each other in a bidirectional one-to-one relationship.
- `ReadOnlyHashSet`: Fast read-only wrapper around a HashSet (instead of going through `ISet<>`).
- `ReadOnlyList`: Fast read-only wrapper around a List (instead of going through `IList<>`).
- A full set of interfaces for the new collections as well as an `IReadOnlySet<>` polyfill for .NET Standard.
- A full set of interfaces and read-only wrappers for the new collections as well as an `IReadOnlySet<>` polyfill for .NET Standard.

**Singulink.Collections.Weak** provides a set of collection classes that store weak references to values so that the garbage collector is free to reclaim the memory they use when they aren't being referenced anymore. The values returned by the collections will never be `null` - if the value was garbage collected then the collection behaves as if the value was removed from the collection.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Singulink.Collections;
public partial class HashSetDictionary<TKey, TValue>
{
/// <summary>
/// Represents a synchronized read-only set of values associcated with a key in a <see cref="HashSetDictionary{TKey, TValue}"/>.
/// Represents a synchronized read-only set of values associated with a key in a <see cref="HashSetDictionary{TKey, TValue}"/>.
/// </summary>
public class ReadOnlyValueSet : ISet<TValue>, IReadOnlySet<TValue>, IEquatable<ReadOnlyValueSet>
{
Expand Down Expand Up @@ -133,13 +133,8 @@ private protected HashSet<TValue> GetSet()
HashSet<TValue> UpdateAndGetValues()
{
if (_dictionary.TryGetValues(_key, out var valueSet))
{
_lastSet = valueSet._lastSet;

if (_transientReadOnlySet != null)
_transientReadOnlySet.WrappedSet = _lastSet;
}

return _lastSet;
}
}
Expand Down
2 changes: 1 addition & 1 deletion Source/Singulink.Collections/HashSetDictionary.ValueSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace Singulink.Collections;
public partial class HashSetDictionary<TKey, TValue>
{
/// <summary>
/// Represents a dictionary synchronized set of values associcated with a key in a <see cref="HashSetDictionary{TKey, TValue}"/>.
/// Represents a dictionary synchronized set of values associated with a key in a <see cref="HashSetDictionary{TKey, TValue}"/>.
/// </summary>
public sealed class ValueSet : ReadOnlyValueSet, ISet<TValue>, IReadOnlyCollectionProvider<TValue>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Singulink.Collections;
public partial class ListDictionary<TKey, TValue>
{
/// <summary>
/// Represents a synchronized read-only list of values associcated with a key in a <see cref="ListDictionary{TKey, TValue}"/>.
/// Represents a synchronized read-only list of values associated with a key in a <see cref="ListDictionary{TKey, TValue}"/>.
/// </summary>
public class ReadOnlyValueList : IList<TValue>, IReadOnlyList<TValue>, IEquatable<ReadOnlyValueList>
{
Expand Down Expand Up @@ -219,17 +219,11 @@ private protected List<TValue> GetList()
{
return _lastList.Count > 0 ? _lastList : UpdateAndGetValues();

[MethodImpl(MethodImplOptions.NoInlining)]
List<TValue> UpdateAndGetValues()
{
if (_dictionary.TryGetValues(_key, out var valueList))
{
_lastList = valueList._lastList;

if (_transientReadOnlyList != null)
_transientReadOnlyList.WrappedList = _lastList;
}

return _lastList;
}
}
Expand Down
4 changes: 2 additions & 2 deletions Source/Singulink.Collections/ListDictionary.ValueList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ namespace Singulink.Collections;
public partial class ListDictionary<TKey, TValue>
{
/// <summary>
/// Represents a dictionary synchronized list of values associcated with a key in a <see cref="ListDictionary{TKey, TValue}"/>.
/// Represents a dictionary synchronized list of values associated with a key in a <see cref="ListDictionary{TKey, TValue}"/>.
/// </summary>
public sealed class ValueList : ReadOnlyValueList, IList<TValue>, IReadOnlyCollectionProvider<TValue>
{
private ReadOnlyValueList? _readOnlyValueList;

internal ValueList(ListDictionary<TKey, TValue> dictionary, TKey key) : base(dictionary, key, new()) { }
internal ValueList(ListDictionary<TKey, TValue> dictionary, TKey key) : base(dictionary, key, []) { }

/// <summary>
/// Gets or sets the item at the specified index.
Expand Down
4 changes: 2 additions & 2 deletions Source/Singulink.Collections/ListDictionary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ public int GetValueCount(TKey key)
/// Ensures that the dictionary can hold up to a specified number of key/value list pairs without any further expansion of its backing storage.
/// </summary>
/// <param name="capacity">The number of key/value list pairs.</param>
/// <returns>The currect capacity of the dictionary.</returns>
/// <returns>The current capacity of the dictionary.</returns>
/// <exception cref="ArgumentOutOfRangeException">Capacity specified is less than 0.</exception>
public int EnsureCapacity(int capacity)
{
Expand Down Expand Up @@ -299,7 +299,7 @@ private static void DebugValid(ValueList valueList)
/// </summary>
bool ICollection<KeyValuePair<TKey, IList<TValue>>>.Contains(KeyValuePair<TKey, IList<TValue>> item)
{
return item.Value is ValueList valueList && TryGetValues(item.Key, out var exisingValueList) && valueList == exisingValueList;
return TryGetValues(item.Key, out var valueList) && valueList.Equals(item.Value);
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion Source/Singulink.Collections/ReadOnlyHashSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class ReadOnlyHashSet<T> : ISet<T>, IReadOnlySet<T>
/// <summary>
/// Gets an empty read-only hash set.
/// </summary>
public static ReadOnlyHashSet<T> Empty { get; } = new ReadOnlyHashSet<T>(new HashSet<T>());
public static ReadOnlyHashSet<T> Empty { get; } = new ReadOnlyHashSet<T>([]);

private HashSet<T> _set;

Expand Down
2 changes: 1 addition & 1 deletion Source/Singulink.Collections/ReadOnlyList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class ReadOnlyList<T> : IList<T>, IReadOnlyList<T>
/// <summary>
/// Gets an empty read-only list.
/// </summary>
public static ReadOnlyList<T> Empty { get; } = new ReadOnlyList<T>(new List<T>());
public static ReadOnlyList<T> Empty { get; } = new ReadOnlyList<T>([]);

private List<T> _list;

Expand Down
2 changes: 0 additions & 2 deletions Tests/Singulink.Collections.Weak.Tests/NoGCRegion.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#pragma warning disable CA1815 // Override equals and operator equals on value types

using System.Security.Cryptography;

namespace Singulink.Collections.Weak.Tests;

public struct NoGCRegion : IDisposable
Expand Down

0 comments on commit 2a993bb

Please sign in to comment.