Skip to content

Commit

Permalink
New Virtualization operator (#888)
Browse files Browse the repository at this point in the history
SortAndVirtual + SortAndBind - to replace the old Sort followed by virtualize
  • Loading branch information
RolandPheasant authored Jun 3, 2024
1 parent 00a702e commit 275cc2c
Show file tree
Hide file tree
Showing 22 changed files with 1,873 additions and 173 deletions.
16 changes: 8 additions & 8 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,13 @@ dotnet_naming_symbols.constant_fields.required_modifiers = const
dotnet_naming_style.pascal_case_style.capitalization = pascal_case

# static fields should have s_ prefix
dotnet_naming_rule.static_fields_should_have_prefix.severity = suggestion
dotnet_naming_rule.static_fields_should_have_prefix.severity = none
dotnet_naming_rule.static_fields_should_have_prefix.symbols = static_fields
dotnet_naming_rule.static_fields_should_have_prefix.style = static_prefix_style
dotnet_naming_symbols.static_fields.applicable_kinds = field
dotnet_naming_symbols.static_fields.required_modifiers = static
dotnet_naming_symbols.static_fields.applicable_accessibilities = private, internal, private_protected
dotnet_naming_style.static_prefix_style.required_prefix = s_
dotnet_naming_style.static_prefix_style.required_prefix = _
dotnet_naming_style.static_prefix_style.capitalization = camel_case

# internal and private fields should be _camelCase
Expand Down Expand Up @@ -305,14 +305,14 @@ dotnet_diagnostic.RCS1507.severity = error

dotnet_diagnostic.SA1000.severity = error
dotnet_diagnostic.SA1001.severity = error
dotnet_diagnostic.SA1002.severity = error
dotnet_diagnostic.SA1002.severity = none
dotnet_diagnostic.SA1003.severity = error
dotnet_diagnostic.SA1004.severity = error
dotnet_diagnostic.SA1005.severity = error
dotnet_diagnostic.SA1006.severity = error
dotnet_diagnostic.SA1007.severity = error
dotnet_diagnostic.SA1008.severity = error
dotnet_diagnostic.SA1009.severity = error
dotnet_diagnostic.SA1009.severity = none
dotnet_diagnostic.SA1010.severity = none
dotnet_diagnostic.SA1011.severity = error
dotnet_diagnostic.SA1012.severity = error
Expand Down Expand Up @@ -371,9 +371,9 @@ dotnet_diagnostic.SA1137.severity = error
dotnet_diagnostic.SA1139.severity = error
dotnet_diagnostic.SA1200.severity = none
dotnet_diagnostic.SA1201.severity = none
dotnet_diagnostic.SA1202.severity = error
dotnet_diagnostic.SA1203.severity = error
dotnet_diagnostic.SA1204.severity = error
dotnet_diagnostic.SA1202.severity = none
dotnet_diagnostic.SA1203.severity = none
dotnet_diagnostic.SA1204.severity = none
dotnet_diagnostic.SA1205.severity = error
dotnet_diagnostic.SA1206.severity = error
dotnet_diagnostic.SA1207.severity = error
Expand Down Expand Up @@ -402,7 +402,7 @@ dotnet_diagnostic.SA1314.severity = error
dotnet_diagnostic.SA1316.severity = none
dotnet_diagnostic.SA1400.severity = error
dotnet_diagnostic.SA1401.severity = error
dotnet_diagnostic.SA1402.severity = error
dotnet_diagnostic.SA1402.severity = none
dotnet_diagnostic.SA1403.severity = error
dotnet_diagnostic.SA1404.severity = error
dotnet_diagnostic.SA1405.severity = error
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -662,6 +662,15 @@ namespace DynamicData
public int Updates { get; }
public override string ToString() { }
}
public sealed class ChangeSet<TObject, TKey, TContext> : DynamicData.ChangeSet<TObject, TKey>, DynamicData.IChangeSet, DynamicData.IChangeSet<TObject, TKey>, DynamicData.IChangeSet<TObject, TKey, TContext>, System.Collections.Generic.IEnumerable<DynamicData.Change<TObject, TKey>>, System.Collections.IEnumerable
where TObject : notnull
where TKey : notnull
{
public ChangeSet(TContext context) { }
public ChangeSet(System.Collections.Generic.IEnumerable<DynamicData.Change<TObject, TKey>> collection, TContext context) { }
public ChangeSet(int capacity, TContext context) { }
public TContext Context { get; }
}
public enum ChangeType
{
Item = 0,
Expand Down Expand Up @@ -792,6 +801,12 @@ namespace DynamicData
{
int Updates { get; }
}
public interface IChangeSet<TObject, TKey, out TContext> : DynamicData.IChangeSet, DynamicData.IChangeSet<TObject, TKey>, System.Collections.Generic.IEnumerable<DynamicData.Change<TObject, TKey>>, System.Collections.IEnumerable
where TObject : notnull
where TKey : notnull
{
TContext Context { get; }
}
public interface IConnectableCache<TObject, TKey>
where TObject : notnull
where TKey : notnull
Expand Down Expand Up @@ -1766,6 +1781,12 @@ namespace DynamicData
public static System.IObservable<DynamicData.IChangeSet<TObject, TKey>> SortAndBind<TObject, TKey>(this System.IObservable<DynamicData.IChangeSet<TObject, TKey>> source, out System.Collections.ObjectModel.ReadOnlyObservableCollection<TObject> readOnlyObservableCollection)
where TObject : notnull, System.IComparable<TObject>
where TKey : notnull { }
public static System.IObservable<DynamicData.IChangeSet<TObject, TKey>> SortAndBind<TObject, TKey>(this System.IObservable<DynamicData.IChangeSet<TObject, TKey, DynamicData.VirtualContext<TObject>>> source, System.Collections.Generic.IList<TObject> targetList)
where TObject : notnull
where TKey : notnull { }
public static System.IObservable<DynamicData.IChangeSet<TObject, TKey>> SortAndBind<TObject, TKey>(this System.IObservable<DynamicData.IChangeSet<TObject, TKey, DynamicData.VirtualContext<TObject>>> source, out System.Collections.ObjectModel.ReadOnlyObservableCollection<TObject> readOnlyObservableCollection)
where TObject : notnull
where TKey : notnull { }
public static System.IObservable<DynamicData.IChangeSet<TObject, TKey>> SortAndBind<TObject, TKey>(this System.IObservable<DynamicData.IChangeSet<TObject, TKey>> source, System.Collections.Generic.IList<TObject> targetList, DynamicData.Binding.SortAndBindOptions options)
where TObject : notnull, System.IComparable<TObject>
where TKey : notnull { }
Expand All @@ -1784,6 +1805,12 @@ namespace DynamicData
public static System.IObservable<DynamicData.IChangeSet<TObject, TKey>> SortAndBind<TObject, TKey>(this System.IObservable<DynamicData.IChangeSet<TObject, TKey>> source, out System.Collections.ObjectModel.ReadOnlyObservableCollection<TObject> readOnlyObservableCollection, System.IObservable<System.Collections.Generic.IComparer<TObject>> comparerChanged)
where TObject : notnull
where TKey : notnull { }
public static System.IObservable<DynamicData.IChangeSet<TObject, TKey>> SortAndBind<TObject, TKey>(this System.IObservable<DynamicData.IChangeSet<TObject, TKey, DynamicData.VirtualContext<TObject>>> source, System.Collections.Generic.IList<TObject> targetList, DynamicData.Binding.SortAndBindOptions options)
where TObject : notnull
where TKey : notnull { }
public static System.IObservable<DynamicData.IChangeSet<TObject, TKey>> SortAndBind<TObject, TKey>(this System.IObservable<DynamicData.IChangeSet<TObject, TKey, DynamicData.VirtualContext<TObject>>> source, out System.Collections.ObjectModel.ReadOnlyObservableCollection<TObject> readOnlyObservableCollection, DynamicData.Binding.SortAndBindOptions options)
where TObject : notnull
where TKey : notnull { }
public static System.IObservable<DynamicData.IChangeSet<TObject, TKey>> SortAndBind<TObject, TKey>(this System.IObservable<DynamicData.IChangeSet<TObject, TKey>> source, System.Collections.Generic.IList<TObject> targetList, System.Collections.Generic.IComparer<TObject> comparer, DynamicData.Binding.SortAndBindOptions options)
where TObject : notnull
where TKey : notnull { }
Expand All @@ -1796,6 +1823,18 @@ namespace DynamicData
public static System.IObservable<DynamicData.IChangeSet<TObject, TKey>> SortAndBind<TObject, TKey>(this System.IObservable<DynamicData.IChangeSet<TObject, TKey>> source, out System.Collections.ObjectModel.ReadOnlyObservableCollection<TObject> readOnlyObservableCollection, System.IObservable<System.Collections.Generic.IComparer<TObject>> comparerChanged, DynamicData.Binding.SortAndBindOptions options)
where TObject : notnull
where TKey : notnull { }
public static System.IObservable<DynamicData.IChangeSet<TObject, TKey, DynamicData.VirtualContext<TObject>>> SortAndVirtualize<TObject, TKey>(this System.IObservable<DynamicData.IChangeSet<TObject, TKey>> source, System.Collections.Generic.IComparer<TObject> comparer, System.IObservable<DynamicData.IVirtualRequest> virtualRequests)
where TObject : notnull
where TKey : notnull { }
public static System.IObservable<DynamicData.IChangeSet<TObject, TKey, DynamicData.VirtualContext<TObject>>> SortAndVirtualize<TObject, TKey>(this System.IObservable<DynamicData.IChangeSet<TObject, TKey>> source, System.IObservable<System.Collections.Generic.IComparer<TObject>> comparerChanged, System.IObservable<DynamicData.IVirtualRequest> virtualRequests)
where TObject : notnull
where TKey : notnull { }
public static System.IObservable<DynamicData.IChangeSet<TObject, TKey, DynamicData.VirtualContext<TObject>>> SortAndVirtualize<TObject, TKey>(this System.IObservable<DynamicData.IChangeSet<TObject, TKey>> source, System.Collections.Generic.IComparer<TObject> comparer, System.IObservable<DynamicData.IVirtualRequest> virtualRequests, DynamicData.SortAndVirtualizeOptions options)
where TObject : notnull
where TKey : notnull { }
public static System.IObservable<DynamicData.IChangeSet<TObject, TKey, DynamicData.VirtualContext<TObject>>> SortAndVirtualize<TObject, TKey>(this System.IObservable<DynamicData.IChangeSet<TObject, TKey>> source, System.IObservable<System.Collections.Generic.IComparer<TObject>> comparerChanged, System.IObservable<DynamicData.IVirtualRequest> virtualRequests, DynamicData.SortAndVirtualizeOptions options)
where TObject : notnull
where TKey : notnull { }
public static System.IObservable<DynamicData.ISortedChangeSet<TObject, TKey>> SortBy<TObject, TKey>(this System.IObservable<DynamicData.IChangeSet<TObject, TKey>> source, System.Func<TObject, System.IComparable> expression, DynamicData.Binding.SortDirection sortOrder = 0, DynamicData.SortOptimisations sortOptimisations = 0, int resetThreshold = 100)
where TObject : notnull
where TKey : notnull { }
Expand Down Expand Up @@ -2507,6 +2546,13 @@ namespace DynamicData
public void SetStartingIndex(int index) { }
public override string ToString() { }
}
public struct SortAndVirtualizeOptions : System.IEquatable<DynamicData.SortAndVirtualizeOptions>
{
public SortAndVirtualizeOptions() { }
public int InitialCapacity { get; init; }
public int ResetThreshold { get; init; }
public bool UseBinarySearch { get; init; }
}
[System.Serializable]
public class SortException : System.Exception
{
Expand Down Expand Up @@ -2626,6 +2672,13 @@ namespace DynamicData
public UnspecifiedIndexException(string message) { }
public UnspecifiedIndexException(string message, System.Exception innerException) { }
}
public class VirtualContext<TObject> : System.IEquatable<DynamicData.VirtualContext<TObject>>
{
public VirtualContext(DynamicData.IVirtualResponse Response, System.Collections.Generic.IComparer<TObject> Comparer, DynamicData.SortAndVirtualizeOptions Options) { }
public System.Collections.Generic.IComparer<TObject> Comparer { get; init; }
public DynamicData.SortAndVirtualizeOptions Options { get; init; }
public DynamicData.IVirtualResponse Response { get; init; }
}
public class VirtualRequest : DynamicData.IVirtualRequest, System.IEquatable<DynamicData.IVirtualRequest>
{
public static readonly DynamicData.VirtualRequest Default;
Expand Down Expand Up @@ -2922,7 +2975,7 @@ namespace DynamicData.Tests
public void Dispose() { }
protected virtual void Dispose(bool isDisposing) { }
}
public class ChangeSetAggregator<TObject, TKey> : System.IDisposable
public sealed class ChangeSetAggregator<TObject, TKey> : System.IDisposable
where TObject : notnull
where TKey : notnull
{
Expand All @@ -2933,7 +2986,18 @@ namespace DynamicData.Tests
public System.Collections.Generic.IList<DynamicData.IChangeSet<TObject, TKey>> Messages { get; }
public DynamicData.Diagnostics.ChangeSummary Summary { get; }
public void Dispose() { }
protected virtual void Dispose(bool isDisposing) { }
}
public sealed class ChangeSetAggregator<TObject, TKey, TContext> : System.IDisposable
where TObject : notnull
where TKey : notnull
{
public ChangeSetAggregator(System.IObservable<DynamicData.IChangeSet<TObject, TKey, TContext>> source) { }
public DynamicData.IObservableCache<TObject, TKey> Data { get; }
public System.Exception? Error { get; }
public bool IsCompleted { get; }
public System.Collections.Generic.IList<DynamicData.IChangeSet<TObject, TKey, TContext>> Messages { get; }
public DynamicData.Diagnostics.ChangeSummary Summary { get; }
public void Dispose() { }
}
public class DistinctChangeSetAggregator<TValue> : System.IDisposable
where TValue : notnull
Expand Down Expand Up @@ -3006,6 +3070,9 @@ namespace DynamicData.Tests
public static DynamicData.Tests.VirtualChangeSetAggregator<TObject, TKey> AsAggregator<TObject, TKey>(this System.IObservable<DynamicData.IVirtualChangeSet<TObject, TKey>> source)
where TObject : notnull
where TKey : notnull { }
public static DynamicData.Tests.ChangeSetAggregator<TObject, TKey, TContext> AsAggregator<TObject, TKey, TContext>(this System.IObservable<DynamicData.IChangeSet<TObject, TKey, TContext>> source)
where TObject : notnull
where TKey : notnull { }
public static DynamicData.Tests.GroupChangeSetAggregator<TValue, TKey, TGroupKey> AsAggregator<TValue, TKey, TGroupKey>(this System.IObservable<DynamicData.IGroupChangeSet<TValue, TKey, TGroupKey>> source)
where TValue : notnull
where TKey : notnull
Expand Down
74 changes: 74 additions & 0 deletions src/DynamicData.Tests/Cache/EnsureUniqueKeysFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Linq;
using DynamicData.Tests.Domain;
using FluentAssertions;
using Mono.Cecil;
using Xunit;

namespace DynamicData.Tests.Cache;
Expand Down Expand Up @@ -49,6 +50,79 @@ public void AddAndRemove()

}

[Fact]
public void Refresh()
{
_source.AddOrUpdate(new Person("Me", 20));

_source.Edit(innerCache =>
{
innerCache.Refresh("Me");
});

var message1 = _results.Messages[1];
message1.Count.Should().Be(1);
message1.First().Current.Age.Should().Be(20);
message1.First().Reason.Should().Be(ChangeReason.Refresh);

}


[Fact]
public void CompoundRefresh1()
{
_source.Edit(innerCache =>
{
_source.AddOrUpdate(new Person("Me", 20));
innerCache.Refresh("Me");
});

var message1 = _results.Messages[0];
message1.Count.Should().Be(1);
message1.First().Current.Age.Should().Be(20);
message1.First().Reason.Should().Be(ChangeReason.Add);

}

[Fact]
public void CompoundRefresh2()
{
_source.Edit(innerCache =>
{
innerCache.AddOrUpdate(new Person("Me", 20));
innerCache.AddOrUpdate(new Person("Me", 21));
innerCache.Refresh("Me");
innerCache.Refresh("Me");
});

var message1 = _results.Messages[0];
message1.Count.Should().Be(1);
message1.First().Current.Age.Should().Be(21);
message1.First().Reason.Should().Be(ChangeReason.Add);

}

[Fact]
public void CompoundRefresh3()
{
_source.AddOrUpdate(new Person("Me", 20));

_source.Edit(innerCache =>
{
innerCache.Refresh("Me");
innerCache.Refresh("Me");
innerCache.Refresh("Me");
});

var message1 = _results.Messages[1];
message1.Count.Should().Be(1);
message1.First().Current.Age.Should().Be(20);
message1.First().Reason.Should().Be(ChangeReason.Refresh);

}


public void Dispose()
{
_source.Dispose();
Expand Down
Loading

0 comments on commit 275cc2c

Please sign in to comment.