mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
Fully move ExecuteFilters, add TODO
This commit is contained in:
@@ -8,6 +8,12 @@ namespace SabreTools.DatFiles.Test
|
|||||||
{
|
{
|
||||||
public partial class DatFileTests
|
public partial class DatFileTests
|
||||||
{
|
{
|
||||||
|
#region ExecuteFilters
|
||||||
|
|
||||||
|
// TODO: Add ExecuteFilters tests
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
#region MachineDescriptionToName
|
#region MachineDescriptionToName
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
|||||||
@@ -34,8 +34,8 @@ namespace SabreTools.DatFiles
|
|||||||
/// <param name="filterRunner">Preconfigured filter runner to use</param>
|
/// <param name="filterRunner">Preconfigured filter runner to use</param>
|
||||||
public void ExecuteFilters(FilterRunner filterRunner)
|
public void ExecuteFilters(FilterRunner filterRunner)
|
||||||
{
|
{
|
||||||
Items.ExecuteFilters(filterRunner);
|
ExecuteFiltersImpl(filterRunner);
|
||||||
ItemsDB.ExecuteFilters(filterRunner);
|
ExecuteFiltersImplDB(filterRunner);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -184,6 +184,99 @@ namespace SabreTools.DatFiles
|
|||||||
return mapping;
|
return mapping;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Execute all filters in a filter runner on the items in the dictionary
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="filterRunner">Preconfigured filter runner to use</param>
|
||||||
|
private void ExecuteFiltersImpl(FilterRunner filterRunner)
|
||||||
|
{
|
||||||
|
List<string> keys = [.. Items.Keys];
|
||||||
|
#if NET452_OR_GREATER || NETCOREAPP
|
||||||
|
Parallel.ForEach(keys, Core.Globals.ParallelOptions, key =>
|
||||||
|
#elif NET40_OR_GREATER
|
||||||
|
Parallel.ForEach(keys, key =>
|
||||||
|
#else
|
||||||
|
foreach (var key in keys)
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
ExecuteFilterOnBucket(filterRunner, key);
|
||||||
|
#if NET40_OR_GREATER || NETCOREAPP
|
||||||
|
});
|
||||||
|
#else
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Execute all filters in a filter runner on the items in the dictionary
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="filterRunner">Preconfigured filter runner to use</param>
|
||||||
|
private void ExecuteFiltersImplDB(FilterRunner filterRunner)
|
||||||
|
{
|
||||||
|
List<string> keys = [.. ItemsDB.SortedKeys];
|
||||||
|
#if NET452_OR_GREATER || NETCOREAPP
|
||||||
|
Parallel.ForEach(keys, Globals.ParallelOptions, key =>
|
||||||
|
#elif NET40_OR_GREATER
|
||||||
|
Parallel.ForEach(keys, key =>
|
||||||
|
#else
|
||||||
|
foreach (var key in keys)
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
ExecuteFilterOnBucketDB(filterRunner, key);
|
||||||
|
#if NET40_OR_GREATER || NETCOREAPP
|
||||||
|
});
|
||||||
|
#else
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Execute all filters in a filter runner on a single bucket
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="filterRunner">Preconfigured filter runner to use</param>
|
||||||
|
/// <param name="bucketName">Name of the bucket to filter on</param>
|
||||||
|
private void ExecuteFilterOnBucket(FilterRunner filterRunner, string bucketName)
|
||||||
|
{
|
||||||
|
List<DatItem>? items = GetItemsForBucket(bucketName);
|
||||||
|
if (items == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
// Filter all items in the current key
|
||||||
|
List<DatItem> newItems = [];
|
||||||
|
foreach (var item in items)
|
||||||
|
{
|
||||||
|
if (item.PassesFilter(filterRunner))
|
||||||
|
newItems.Add(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set the value in the key to the new set
|
||||||
|
Remove(bucketName);
|
||||||
|
Add(bucketName, newItems);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Execute all filters in a filter runner on a single bucket
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="filterRunner">Preconfigured filter runner to use</param>
|
||||||
|
/// <param name="bucketName">Name of the bucket to filter on</param>
|
||||||
|
private void ExecuteFilterOnBucketDB(FilterRunner filterRunner, string bucketName)
|
||||||
|
{
|
||||||
|
var items = GetItemsForBucketDB(bucketName);
|
||||||
|
if (items == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
// Filter all items in the current key
|
||||||
|
List<long> newItems = [];
|
||||||
|
foreach (var item in items)
|
||||||
|
{
|
||||||
|
if (item.Value.PassesFilterDB(filterRunner))
|
||||||
|
newItems.Add(item.Key);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set the value in the key to the new set
|
||||||
|
ItemsDB._buckets[bucketName] = newItems;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Use game descriptions as names, updating cloneof/romof/sampleof
|
/// Use game descriptions as names, updating cloneof/romof/sampleof
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ using System.Threading.Tasks;
|
|||||||
#endif
|
#endif
|
||||||
using System.Xml.Serialization;
|
using System.Xml.Serialization;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using SabreTools.Core.Filter;
|
|
||||||
using SabreTools.Core.Tools;
|
using SabreTools.Core.Tools;
|
||||||
using SabreTools.DatItems;
|
using SabreTools.DatItems;
|
||||||
using SabreTools.DatItems.Formats;
|
using SabreTools.DatItems.Formats;
|
||||||
@@ -827,58 +826,6 @@ namespace SabreTools.DatFiles
|
|||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
// TODO: All internal, can this be put into a better location?
|
|
||||||
#region Filtering
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Execute all filters in a filter runner on the items in the dictionary
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="filterRunner">Preconfigured filter runner to use</param>
|
|
||||||
internal void ExecuteFilters(FilterRunner filterRunner)
|
|
||||||
{
|
|
||||||
List<string> keys = [.. Keys];
|
|
||||||
#if NET452_OR_GREATER || NETCOREAPP
|
|
||||||
Parallel.ForEach(keys, Core.Globals.ParallelOptions, key =>
|
|
||||||
#elif NET40_OR_GREATER
|
|
||||||
Parallel.ForEach(keys, key =>
|
|
||||||
#else
|
|
||||||
foreach (var key in keys)
|
|
||||||
#endif
|
|
||||||
{
|
|
||||||
ExecuteFilterOnBucket(filterRunner, key);
|
|
||||||
#if NET40_OR_GREATER || NETCOREAPP
|
|
||||||
});
|
|
||||||
#else
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Execute all filters in a filter runner on a single bucket
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="filterRunner">Preconfigured filter runner to use</param>
|
|
||||||
/// <param name="bucketName">Name of the bucket to filter on</param>
|
|
||||||
private void ExecuteFilterOnBucket(FilterRunner filterRunner, string bucketName)
|
|
||||||
{
|
|
||||||
List<DatItem>? items = GetItemsForBucket(bucketName);
|
|
||||||
if (items == null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
// Filter all items in the current key
|
|
||||||
List<DatItem> newItems = [];
|
|
||||||
foreach (var item in items)
|
|
||||||
{
|
|
||||||
if (item.PassesFilter(filterRunner))
|
|
||||||
newItems.Add(item);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set the value in the key to the new set
|
|
||||||
Remove(bucketName);
|
|
||||||
Add(bucketName, newItems);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Statistics
|
#region Statistics
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ using System.Threading.Tasks;
|
|||||||
#endif
|
#endif
|
||||||
using System.Xml.Serialization;
|
using System.Xml.Serialization;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using SabreTools.Core.Filter;
|
|
||||||
using SabreTools.Core.Tools;
|
using SabreTools.Core.Tools;
|
||||||
using SabreTools.DatItems;
|
using SabreTools.DatItems;
|
||||||
using SabreTools.DatItems.Formats;
|
using SabreTools.DatItems.Formats;
|
||||||
@@ -1206,57 +1205,6 @@ namespace SabreTools.DatFiles
|
|||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
// TODO: All internal, can this be put into a better location?
|
|
||||||
#region Filtering
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Execute all filters in a filter runner on the items in the dictionary
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="filterRunner">Preconfigured filter runner to use</param>
|
|
||||||
internal void ExecuteFilters(FilterRunner filterRunner)
|
|
||||||
{
|
|
||||||
List<string> keys = [.. SortedKeys];
|
|
||||||
#if NET452_OR_GREATER || NETCOREAPP
|
|
||||||
Parallel.ForEach(keys, Core.Globals.ParallelOptions, key =>
|
|
||||||
#elif NET40_OR_GREATER
|
|
||||||
Parallel.ForEach(keys, key =>
|
|
||||||
#else
|
|
||||||
foreach (var key in keys)
|
|
||||||
#endif
|
|
||||||
{
|
|
||||||
ExecuteFilterOnBucket(filterRunner, key);
|
|
||||||
#if NET40_OR_GREATER || NETCOREAPP
|
|
||||||
});
|
|
||||||
#else
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Execute all filters in a filter runner on a single bucket
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="filterRunner">Preconfigured filter runner to use</param>
|
|
||||||
/// <param name="bucketName">Name of the bucket to filter on</param>
|
|
||||||
private void ExecuteFilterOnBucket(FilterRunner filterRunner, string bucketName)
|
|
||||||
{
|
|
||||||
var items = GetItemsForBucket(bucketName);
|
|
||||||
if (items == null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
// Filter all items in the current key
|
|
||||||
List<long> newItems = [];
|
|
||||||
foreach (var item in items)
|
|
||||||
{
|
|
||||||
if (item.Value.PassesFilterDB(filterRunner))
|
|
||||||
newItems.Add(item.Key);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set the value in the key to the new set
|
|
||||||
_buckets[bucketName] = newItems;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Statistics
|
#region Statistics
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
Reference in New Issue
Block a user