Skip to content

Commit b86d4c7

Browse files
committed
7.0.0
-Refactor code structure for improved readability and maintainability
1 parent 2b32787 commit b86d4c7

56 files changed

Lines changed: 8963 additions & 2250 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Directory.Build.props

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,13 @@
1111
<RepositoryType>git</RepositoryType>
1212
<NeutralLanguage>en</NeutralLanguage>
1313
<PackageLicenseExpression>MIT</PackageLicenseExpression>
14+
<PackageRequireLicenseAcceptance>True</PackageRequireLicenseAcceptance>
1415
<PackageProjectUrl>https://github.com/DevAM-Tools/LargeCollections</PackageProjectUrl>
1516
<RepositoryUrl>https://github.com/DevAM-Tools/LargeCollections</RepositoryUrl>
1617
<PackageReadmeFile>README.md</PackageReadmeFile>
17-
<Version>6.0.0</Version>
18-
<AssemblyVersion>6.0.0</AssemblyVersion>
19-
<FileVersion>6.0.0</FileVersion>
18+
<Version>7.0.0</Version>
19+
<AssemblyVersion>7.0.0</AssemblyVersion>
20+
<FileVersion>7.0.0</FileVersion>
2021
<SignAssembly>False</SignAssembly>
2122
</PropertyGroup>
2223
<PropertyGroup Condition="'$(Configuration)' == 'Release'">

LargeCollections.DiskCache/BoundingBox.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*
1+
/*
22
MIT License
33
SPDX-License-Identifier: MIT
44

LargeCollections.DiskCache/DiskCache.cs

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*
1+
/*
22
MIT License
33
SPDX-License-Identifier: MIT
44
@@ -1211,6 +1211,14 @@ protected static int GetParallelIndex(byte[] bytesId, byte degreeOfParallelism)
12111211
return index;
12121212
}
12131213

1214+
#region DoForEach Methods
1215+
1216+
/// <summary>
1217+
/// Performs the <paramref name="action"/> with key-value pairs of the cache.
1218+
/// Note: offset and count parameters are not supported for hash-based caches
1219+
/// since elements have no defined order.
1220+
/// </summary>
1221+
/// <param name="action">The function that will be called for each key-value pair.</param>
12141222
[MethodImpl(MethodImplOptions.AggressiveInlining)]
12151223
public void DoForEach(Action<KeyValuePair<TKey, TValue>> action)
12161224
{
@@ -1225,17 +1233,21 @@ public void DoForEach(Action<KeyValuePair<TKey, TValue>> action)
12251233
}
12261234
}
12271235

1236+
/// <summary>
1237+
/// Performs the action on key-value pairs using an action for optimal performance.
1238+
/// Note: offset and count parameters are not supported for hash-based caches
1239+
/// since elements have no defined order.
1240+
/// </summary>
1241+
/// <typeparam name="TAction">A type implementing <see cref="ILargeAction{KeyValuePair{TKey, TValue}}"/>.</typeparam>
1242+
/// <param name="action">The action instance passed by reference.</param>
12281243
[MethodImpl(MethodImplOptions.AggressiveInlining)]
1229-
public void DoForEach<TUserData>(ActionWithUserData<KeyValuePair<TKey, TValue>, TUserData> action, ref TUserData userData)
1244+
public void DoForEach<TAction>(ref TAction action) where TAction : ILargeAction<KeyValuePair<TKey, TValue>>
12301245
{
1231-
if (action is null)
1232-
{
1233-
throw new ArgumentNullException(nameof(action));
1234-
}
1235-
12361246
foreach (KeyValuePair<TKey, TValue> item in GetAll())
12371247
{
1238-
action.Invoke(item, ref userData);
1248+
action.Invoke(item);
12391249
}
12401250
}
1251+
1252+
#endregion
12411253
}

LargeCollections.DiskCache/DiskCacheConstants.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*
1+
/*
22
MIT License
33
SPDX-License-Identifier: MIT
44

LargeCollections.DiskCache/Interfaces/DiskCacheInterfaces.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*
1+
/*
22
MIT License
33
SPDX-License-Identifier: MIT
44

LargeCollections.DiskCache/LargeCollections.DiskCache.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFrameworks>netstandard2.0;netstandard2.1;net6.0</TargetFrameworks>
4+
<TargetFrameworks>netstandard2.0;netstandard2.1;net6.0;net8.0;net10.0</TargetFrameworks>
55
<PackageTags>LargeCollection;LargeCollections;Large;Collection;Collections;Dictionary;DiskCache;Cache;Disk;Sqlite;Spatial;Query</PackageTags>
66
<Description>Dictionary-like collections that allow to limit the amount of memory (RAM) in MB that will be used. Any memory requirement that exceeds this amount is automatically swapped out to disk. Additionally it offers multi-threaded operations for performance improvements.</Description>
77
<Title>LargeCollections.DiskCache</Title>

LargeCollections.DiskCache/ParallelEnumerableExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*
1+
/*
22
MIT License
33
SPDX-License-Identifier: MIT
44

LargeCollections.DiskCache/SpatialDiskCache.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*
1+
/*
22
MIT License
33
SPDX-License-Identifier: MIT
44

LargeCollections.Observable/IReadOnlyLargeObservableCollection.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,15 @@ public interface IReadOnlyLargeObservableCollection<T> :
3939
/// </summary>
4040
/// <returns>A disposable that resumes notifications when disposed</returns>
4141
IDisposable SuspendNotifications();
42+
43+
/// <summary>
44+
/// High-performance event raised for any collection change.
45+
/// Uses struct-based event args passed by reference to avoid allocations.
46+
/// The event args contain all information about the change including:
47+
/// - Action: The type of change (Add, Remove, Replace, Clear, Reset, RangeAdd)
48+
/// - Index: The index at which the change occurred
49+
/// - NewItem/OldItem: The items involved in the change
50+
/// - Count/NewCount: Count information for the change
51+
/// </summary>
52+
event LargeCollectionChangedEventHandler<T> Changed;
4253
}
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
/*
2+
MIT License
3+
SPDX-License-Identifier: MIT
4+
5+
Copyright (c) 2025 DevAM
6+
7+
Permission is hereby granted, free of charge, to any person obtaining a copy
8+
of this software and associated documentation files (the "Software"), to deal
9+
in the Software without restriction, including without limitation the rights
10+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
copies of the Software, and to permit persons to whom the Software is
12+
furnished to do so, subject to the following conditions:
13+
14+
The above copyright notice and this permission notice shall be included in all
15+
copies or substantial portions of the Software.
16+
17+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23+
SOFTWARE.
24+
*/
25+
26+
using System;
27+
using System.Collections.Generic;
28+
using System.Runtime.CompilerServices;
29+
30+
namespace LargeCollections.Observable;
31+
32+
/// <summary>
33+
/// High-performance predicate interface for filtering operations.
34+
/// Using struct implementations enables JIT devirtualization and inlining for optimal performance.
35+
/// </summary>
36+
/// <typeparam name="T">The type of items to filter.</typeparam>
37+
/// <example>
38+
/// <code>
39+
/// struct PositiveFilter : ILargePredicate&lt;int&gt;
40+
/// {
41+
/// public bool Invoke(int item) =&gt; item &gt; 0;
42+
/// }
43+
///
44+
/// var filtered = collection.CreateFilteredView(new PositiveFilter());
45+
/// </code>
46+
/// </example>
47+
public interface ILargePredicate<T>
48+
{
49+
/// <summary>
50+
/// Evaluates the predicate for the specified item.
51+
/// </summary>
52+
/// <param name="item">The item to evaluate.</param>
53+
/// <returns>true if the item satisfies the predicate; otherwise, false.</returns>
54+
bool Invoke(T item);
55+
}
56+
57+
/// <summary>
58+
/// Wrapper that adapts a <see cref="Func{T, TResult}"/> delegate to the <see cref="ILargePredicate{T}"/> interface.
59+
/// Use this when you have an existing delegate but want to use the generic predicate overloads.
60+
/// Note: This wrapper has the same performance as direct delegate usage.
61+
/// </summary>
62+
/// <typeparam name="T">The type to filter.</typeparam>
63+
public readonly struct DelegatePredicate<T> : ILargePredicate<T>
64+
{
65+
private readonly Func<T, bool> _predicate;
66+
67+
/// <summary>
68+
/// Creates a new delegate wrapper predicate.
69+
/// </summary>
70+
/// <param name="predicate">The predicate delegate to wrap.</param>
71+
public DelegatePredicate(Func<T, bool> predicate)
72+
{
73+
_predicate = predicate ?? throw new ArgumentNullException(nameof(predicate));
74+
}
75+
76+
/// <inheritdoc/>
77+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
78+
public bool Invoke(T item) => _predicate(item);
79+
}
80+
81+
/// <summary>
82+
/// A pass-through predicate that always returns true (no filtering).
83+
/// The JIT compiler can completely eliminate the predicate check when this struct is used,
84+
/// resulting in zero overhead compared to not having a predicate at all.
85+
/// </summary>
86+
/// <typeparam name="T">The type of items.</typeparam>
87+
public readonly struct NoFilter<T> : ILargePredicate<T>
88+
{
89+
/// <inheritdoc/>
90+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
91+
public bool Invoke(T item) => true;
92+
}
93+
94+
/// <summary>
95+
/// A pass-through comparer that preserves the original order (no sorting).
96+
/// The JIT compiler can completely eliminate the sort operation when this struct is used,
97+
/// resulting in zero overhead compared to not having a comparer at all.
98+
/// </summary>
99+
/// <typeparam name="T">The type of items.</typeparam>
100+
public readonly struct NoSort<T> : IComparer<T>
101+
{
102+
/// <inheritdoc/>
103+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
104+
public int Compare(T x, T y) => 0;
105+
}
106+

0 commit comments

Comments
 (0)