Show / Hide Table of Contents

Class CollectionExtensions

Inheritance
System.Object
CollectionExtensions
Namespace: Edgar.Legacy.GeneralAlgorithms.Algorithms.Common
Assembly: Edgar.dll
Syntax
public static class CollectionExtensions : Object

Methods

GetWeightedRandom<T>(IList<T>, Func<T, Double>, Random)

Returns a random number based on a given weight function.

Declaration
public static T GetWeightedRandom<T>(this IList<T> elements, Func<T, double> weightSelector, Random random)
Parameters
Type Name Description
System.Collections.Generic.IList<T> elements

Collection of elements.

System.Func<T, System.Double> weightSelector

A function that assigns weight to individual elements.

System.Random random

Random number generator to be used.

Returns
Type Description
T
Type Parameters
Name Description
T

MaxBy<TElement, TResult>(IEnumerable<TElement>, Func<TElement, TResult>)

Computes an index of the first maximum element with respect to a given function.

Declaration
public static int MaxBy<TElement, TResult>(this IEnumerable<TElement> collection, Func<TElement, TResult> func)
    where TResult : IComparable<TResult>
Parameters
Type Name Description
System.Collections.Generic.IEnumerable<TElement> collection
System.Func<TElement, TResult> func
Returns
Type Description
System.Int32
Type Parameters
Name Description
TElement
TResult

MinBy<TElement, TResult>(IEnumerable<TElement>, Func<TElement, TResult>)

Computes an index of the first minimum element with respect to a given function.

Declaration
public static int MinBy<TElement, TResult>(this IEnumerable<TElement> collection, Func<TElement, TResult> func)
    where TResult : IComparable<TResult>
Parameters
Type Name Description
System.Collections.Generic.IEnumerable<TElement> collection
System.Func<TElement, TResult> func
Returns
Type Description
System.Int32
Type Parameters
Name Description
TElement
TResult

SequenceEqualWithoutOrder<T>(IEnumerable<T>, IEnumerable<T>)

Check if two collections are equal. The order does not matter.

Declaration
public static bool SequenceEqualWithoutOrder<T>(this IEnumerable<T> firstEnumerable, IEnumerable<T> secondEnumerable)
Parameters
Type Name Description
System.Collections.Generic.IEnumerable<T> firstEnumerable
System.Collections.Generic.IEnumerable<T> secondEnumerable
Returns
Type Description
System.Boolean
Type Parameters
Name Description
T
Remarks

Both collection must have only unique elements. The method is quite slow - it runs in O(n^2) where n is the number of elements.

Back to top Generated by DocFX