mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-03-12 04:35:27 -07:00
* chore: updated tfm to net6 * chore: updated main packages * chore: fixed some warnings * core: Added workflow_dispatch to some of the CI pipelines [skip ci] (#4392) * chore: bump the net version * ci: use the dotnet ver task everywhere
42 lines
1.2 KiB
C#
42 lines
1.2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
|
|
namespace Ombi.Helpers
|
|
{
|
|
public static class LinqHelpers
|
|
{
|
|
public static HashSet<T> ToHashSet<T>(
|
|
this IEnumerable<T> source,
|
|
IEqualityComparer<T> comparer = null)
|
|
{
|
|
return new HashSet<T>(source, comparer);
|
|
}
|
|
|
|
public static IEnumerable<T> Shuffle<T>(this IEnumerable<T> source)
|
|
{
|
|
return source.Shuffle(new Random());
|
|
}
|
|
|
|
public static IEnumerable<T> Shuffle<T>(this IEnumerable<T> source, Random rng)
|
|
{
|
|
if (source == null) throw new ArgumentNullException(nameof(source));
|
|
if (rng == null) throw new ArgumentNullException(nameof(rng));
|
|
|
|
return source.ShuffleIterator(rng);
|
|
}
|
|
|
|
private static IEnumerable<T> ShuffleIterator<T>(
|
|
this IEnumerable<T> source, Random rng)
|
|
{
|
|
var buffer = source.ToList();
|
|
for (int i = 0; i < buffer.Count; i++)
|
|
{
|
|
int j = rng.Next(i, buffer.Count);
|
|
yield return buffer[j];
|
|
|
|
buffer[j] = buffer[i];
|
|
}
|
|
}
|
|
}
|
|
} |