Class GeneralComparer
General comparer which supports multiple
directions and comparison of absolute values.
Inheritance
System.Object
GeneralComparer
Implements
System.Collections.Generic.IComparer<System.Double>
System.Collections.Generic.IComparer<System.Int32>
Inherited Members
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.ToString()
Namespace: Mars.Numerics.Comparers
Assembly: Mars.Numerics.dll
Syntax
public class GeneralComparer : IComparer<double>, IComparer<int>
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
| Improve this Doc View SourceGeneralComparer(ComparerDirection, Boolean)
Constructs a new General Comparer.
Declaration
public GeneralComparer(ComparerDirection direction, bool useAbsoluteValues = false)
Parameters
Type | Name | Description |
---|---|---|
ComparerDirection | direction | The direction to compare. |
System.Boolean | useAbsoluteValues | True to compare absolute values, false otherwise. Default is false. |
See Also
| Improve this Doc View SourceGeneralComparer(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. |
System.Func<System.Double, System.Double> | map | The mapping function which will be applied to each vector element prior to any comparisons. |
See Also
Methods
| Improve this Doc 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 |
See Also
| Improve this Doc View SourceCompare(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 |
See Also
Implements
System.Collections.Generic.IComparer<T>
System.Collections.Generic.IComparer<T>