Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
495 changes: 495 additions & 0 deletions src/DynamicDataVNext/Distinct/ChangeTrackingSet.cs

Large diffs are not rendered by default.

60 changes: 30 additions & 30 deletions src/DynamicDataVNext/Distinct/DistinctChangeSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public static DistinctChangeSet<T> Addition<T>(T item)
/// <typeparam name="T">The type of the items being added.</typeparam>
/// <param name="items">The items being added.</param>
/// <returns>A <see cref="DistinctChangeSet{T}"/> describing the addition of the given items.</returns>
public static DistinctChangeSet<T> Addition<T>(IEnumerable<T> items)
public static DistinctChangeSet<T> BulkAddition<T>(IEnumerable<T> items)
{
if (!items.TryGetNonEnumeratedCount(out var itemsCount))
itemsCount = 0;
Expand All @@ -47,8 +47,8 @@ public static DistinctChangeSet<T> Addition<T>(IEnumerable<T> items)
};
}

/// <inheritdoc cref="Addition{T}(IEnumerable{T})"/>
public static DistinctChangeSet<T> Addition<T>(ReadOnlySpan<T> items)
/// <inheritdoc cref="BulkAddition{T}(IEnumerable{T})"/>
public static DistinctChangeSet<T> BulkAddition<T>(ReadOnlySpan<T> items)
{
var changes = ImmutableArray.CreateBuilder<DistinctChange<T>>(initialCapacity: items.Length);

Expand All @@ -63,12 +63,12 @@ public static DistinctChangeSet<T> Addition<T>(ReadOnlySpan<T> items)
}

/// <summary>
/// Creates a new <see cref="DistinctChangeSet{T}"/> representing the clearing of a collection of distinct items.
/// Creates a new <see cref="DistinctChangeSet{T}"/> representing the removal of a range of items.
/// </summary>
/// <typeparam name="T">The type of the items being removed.</typeparam>
/// <param name="items">The items being removed.</param>
/// <returns>A <see cref="DistinctChangeSet{T}"/> describing the clearing of the collection.</returns>
public static DistinctChangeSet<T> Clear<T>(IEnumerable<T> items)
/// <returns>A <see cref="DistinctChangeSet{T}"/> describing the removal of the given items.</returns>
public static DistinctChangeSet<T> BulkRemoval<T>(IEnumerable<T> items)
{
if (!items.TryGetNonEnumeratedCount(out var itemsCount))
itemsCount = 0;
Expand All @@ -81,12 +81,12 @@ public static DistinctChangeSet<T> Clear<T>(IEnumerable<T> items)
return new()
{
Changes = changes.MoveToOrCreateImmutable(),
Type = ChangeSetType.Clear
Type = ChangeSetType.Update
};
}

/// <inheritdoc cref="Clear{T}(IEnumerable{T})"/>
public static DistinctChangeSet<T> Clear<T>(ReadOnlySpan<T> items)
/// <inheritdoc cref="BulkRemoval{T}(IEnumerable{T})"/>
public static DistinctChangeSet<T> BulkRemoval<T>(ReadOnlySpan<T> items)
{
var changes = ImmutableArray.CreateBuilder<DistinctChange<T>>(initialCapacity: items.Length);

Expand All @@ -96,30 +96,17 @@ public static DistinctChangeSet<T> Clear<T>(ReadOnlySpan<T> items)
return new()
{
Changes = changes.MoveToImmutable(),
Type = ChangeSetType.Clear
};
}

/// <summary>
/// Creates a new <see cref="DistinctChangeSet{T}"/> representing the removal of a single item.
/// </summary>
/// <typeparam name="T">The type of the item being removed.</typeparam>
/// <param name="item">The item being removed.</param>
/// <returns>A <see cref="DistinctChangeSet{T}"/> describing the removal of the given item.</returns>
public static DistinctChangeSet<T> Removal<T>(T item)
=> new()
{
Changes = ImmutableArray.Create(DistinctChange.Removal(item)),
Type = ChangeSetType.Update
};
}

/// <summary>
/// Creates a new <see cref="DistinctChangeSet{T}"/> representing the removal of a range of items.
/// Creates a new <see cref="DistinctChangeSet{T}"/> representing the clearing of a collection of distinct items.
/// </summary>
/// <typeparam name="T">The type of the items being removed.</typeparam>
/// <param name="items">The items being removed.</param>
/// <returns>A <see cref="DistinctChangeSet{T}"/> describing the removal of the given items.</returns>
public static DistinctChangeSet<T> Removal<T>(IEnumerable<T> items)
/// <returns>A <see cref="DistinctChangeSet{T}"/> describing the clearing of the collection.</returns>
public static DistinctChangeSet<T> Clear<T>(IEnumerable<T> items)
{
if (!items.TryGetNonEnumeratedCount(out var itemsCount))
itemsCount = 0;
Expand All @@ -132,12 +119,12 @@ public static DistinctChangeSet<T> Removal<T>(IEnumerable<T> items)
return new()
{
Changes = changes.MoveToOrCreateImmutable(),
Type = ChangeSetType.Update
Type = ChangeSetType.Clear
};
}

/// <inheritdoc cref="Removal{T}(IEnumerable{T})"/>
public static DistinctChangeSet<T> Removal<T>(ReadOnlySpan<T> items)
/// <inheritdoc cref="Clear{T}(IEnumerable{T})"/>
public static DistinctChangeSet<T> Clear<T>(ReadOnlySpan<T> items)
{
var changes = ImmutableArray.CreateBuilder<DistinctChange<T>>(initialCapacity: items.Length);

Expand All @@ -147,10 +134,23 @@ public static DistinctChangeSet<T> Removal<T>(ReadOnlySpan<T> items)
return new()
{
Changes = changes.MoveToImmutable(),
Type = ChangeSetType.Update
Type = ChangeSetType.Clear
};
}

/// <summary>
/// Creates a new <see cref="DistinctChangeSet{T}"/> representing the removal of a single item.
/// </summary>
/// <typeparam name="T">The type of the item being removed.</typeparam>
/// <param name="item">The item being removed.</param>
/// <returns>A <see cref="DistinctChangeSet{T}"/> describing the removal of the given item.</returns>
public static DistinctChangeSet<T> Removal<T>(T item)
=> new()
{
Changes = ImmutableArray.Create(DistinctChange.Removal(item)),
Type = ChangeSetType.Update
};

/// <summary>
/// Creates a new <see cref="DistinctChangeSet{T}"/> representing the resetting of items in a collection of distinct items.
/// </summary>
Expand Down
37 changes: 37 additions & 0 deletions src/DynamicDataVNext/Distinct/IExtendedSet.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using System;
using System.Collections.Generic;

namespace DynamicDataVNext;

/// <summary>
/// Describes an extended version of <see cref="ISet{T}"/>, supporting range operations.
/// </summary>
/// <typeparam name="T">The type of the items in the collection.</typeparam>
public interface IExtendedSet<T>
: ISet<T>
{
/// <inheritdoc cref="ISet{T}.ExceptWith(IEnumerable{T})"/>.
void ExceptWith(ReadOnlySpan<T> other);

/// <inheritdoc cref="ISet{T}.IntersectWith(IEnumerable{T})"/>.
void IntersectWith(ReadOnlySpan<T> other);

/// <summary>
/// Resets the items within the collection to the given set of items. I.E. clears and then re-populates the collection, as a single operation.
/// </summary>
/// <param name="items">The set of items with which to populate the collection.</param>
/// <exception cref="ArgumentNullException">Throws for <paramref name="items"/>.</exception>
void Reset(IEnumerable<T> items);

/// <summary>
/// Resets the items within the collection to the given set of items. I.E. clears and then re-populates the collection, as a single operation.
/// </summary>
/// <param name="items">The set of items with which to populate the collection.</param>
void Reset(ReadOnlySpan<T> items);

/// <inheritdoc cref="ISet{T}.SymmetricExceptWith(IEnumerable{T})"/>.
void SymmetricExceptWith(ReadOnlySpan<T> other);

/// <inheritdoc cref="ISet{T}.UnionWith(IEnumerable{T})"/>.
void UnionWith(ReadOnlySpan<T> other);
}
9 changes: 1 addition & 8 deletions src/DynamicDataVNext/Distinct/ISubjectSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,14 @@ namespace DynamicDataVNext;
/// </summary>
/// <typeparam name="T">The type of the items in the collection.</typeparam>
public interface ISubjectSet<T>
: ISet<T>,
: IExtendedSet<T>,
IObservable<DistinctChangeSet<T>>
{
/// <summary>
/// An event that occurs after any mutation of the collection occurs.
/// </summary>
IObservable<Unit> CollectionChanged { get; }

/// <summary>
/// Resets the items within the collection to the given set of items. I.E. clears and then re-populates the collection, as a single operation.
/// </summary>
/// <param name="items">The set of items with which to populate the collection.</param>
/// <exception cref="ArgumentNullException">Throws for <paramref name="items"/>.</exception>
void Reset(IEnumerable<T> items);

/// <summary>
/// Temporarily suspends the publication of notifications by the collection, until the returned object is disposed, at which point all mutations made during the suspension will (if any) will be published as one notification.
/// </summary>
Expand Down
Loading