You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Zero/ZeroLevel/Services/MemoryPools/Collections/Linq/Distinct.cs

39 lines
1.9 KiB

using System;
using System.Collections.Generic;
namespace MemoryPools.Collections.Linq
{
public static partial class PoolingEnumerable
{
/// <summary>
/// Returns distinct elements from a sequence by using the default equality comparer to compare values. Complexity - O(N)
/// </summary>
public static IPoolingEnumerable<T> Distinct<T>(this IPoolingEnumerable<T> source) =>
Pool<DistinctExprEnumerable<T, T>>.Get().Init(source.GetEnumerator(), x => x);
/// <summary>
/// Returns distinct elements from a sequence by using the default equality comparer to compare values and selector to select key to compare by. Complexity - O(N)
/// </summary>
public static IPoolingEnumerable<T> DistinctBy<T, TItem>(
this IPoolingEnumerable<T> source,
Func<T, TItem> selector) =>
Pool<DistinctExprEnumerable<T, TItem>>.Get().Init(source.GetEnumerator(), selector);
/// <summary>
/// Returns distinct elements from a sequence by using a specified <paramref name="comparer"/> to compare values. Complexity - O(N)
/// </summary>
public static IPoolingEnumerable<T> Distinct<T>(
this IPoolingEnumerable<T> source,
IEqualityComparer<T> comparer) =>
Pool<DistinctExprEnumerable<T, T>>.Get().Init(source.GetEnumerator(), x => x,comparer);
/// <summary>
/// Returns distinct elements from a sequence by using a specified <paramref name="comparer"/> to compare values and selector to select key to compare by. Complexity - O(N)
/// </summary>
public static IPoolingEnumerable<T> DistinctBy<T, TItem>(
this IPoolingEnumerable<T> source,
Func<T, TItem> selector,
IEqualityComparer<TItem> comparer) =>
Pool<DistinctExprEnumerable<T, TItem>>.Get().Init(source.GetEnumerator(), selector, comparer);
}
}

Powered by TurnKey Linux.