Class GeneralComparer
General comparer which supports multiple directions and comparison of absolute values.
Inheritance
Implements
Namespace: ISynergy.Framework.Mathematics.Comparers
Assembly: ISynergy.Framework.Mathematics.dll
Syntax
public class GeneralComparer : IComparer<double>
Examples
// Assume we have values to sort
double[] values = { 0, -5, 3, 1, 8 };
// We can create an ad-hoc sorting rule considering only absolute values
Array.Sort(values, new GeneralComparer(ComparerDirection.Ascending, Math.Abs));
// Result will be { 0, 1, 3, 5, 8 }.
Constructors
View SourceGeneralComparer(ComparerDirection)
Constructs a new General Comparer.
Declaration
public GeneralComparer(ComparerDirection direction)
Parameters
Type | Name | Description |
---|---|---|
ComparerDirection | direction | The direction to compare. |
GeneralComparer(ComparerDirection, Func<Double, Double>)
Constructs a new General Comparer.
Declaration
public GeneralComparer(ComparerDirection direction, Func<double, double> map)
Parameters
Type | Name | Description |
---|---|---|
ComparerDirection | direction | The direction to compare. |
Func<System.Double, System.Double> | map | The mapping function which will be applied to each vector element prior to any comparisons. |
GeneralComparer(ComparerDirection, Boolean)
Constructs a new General Comparer.
Declaration
public GeneralComparer(ComparerDirection direction, bool useAbsoluteValues)
Parameters
Type | Name | Description |
---|---|---|
ComparerDirection | direction | The direction to compare. |
System.Boolean | useAbsoluteValues | True to compare absolute values, false otherwise. Default is false. |
Properties
View SourceDirection
Gets or sets the sorting direction used by this comparer.
Declaration
public ComparerDirection Direction { get; set; }
Property Value
Type | Description |
---|---|
ComparerDirection |
Methods
View SourceCompare(Double, Double)
Compares two objects and returns a value indicating whether one is less than, equal to, or greater than the other.
Declaration
public int Compare(double x, double y)
Parameters
Type | Name | Description |
---|---|---|
System.Double | x | The first object to compare. |
System.Double | y | The second object to compare. |
Returns
Type | Description |
---|---|
System.Int32 |
Compare(Int32, Int32)
Compares two objects and returns a value indicating whether one is less than, equal to, or greater than the other.
Declaration
public int Compare(int x, int y)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | x | The first object to compare. |
System.Int32 | y | The second object to compare. |
Returns
Type | Description |
---|---|
System.Int32 |