• Documentation
  • Core API
  • SmartOpenHamburg API
  • Model Components API
  • Common API

    Show / Hide Table of Contents
    • Mars.Common
      • GeoHash
      • GeoHashDecoder
      • GeohashDecodeResult
      • GeoHashEncoder
      • GeoHashPrecision
      • Hyperrectangle
      • InputHashHelper
      • PositionHelper
    • Mars.Common.Collections
      • BinaryArrayHeap<T>
      • DoubleBits
      • FibonacciHeap<T, TKey>
      • FibonacciHeapDoubleKey<T>
      • FibonacciHeapNode<T, TKey>
      • FibonacciHeapNodeDoubleKey<T>
      • HeapNode
      • IntervalSize
      • K2DTree<T>
      • K2dTreeNode<T>
      • KdTree
      • KdTree<T>
      • KdTreeBase<TNode>
      • KdTreeNode
      • KdTreeNode<T>
      • KdTreeNodeBase<TNode>
      • KdTreeNodeCollection<TNode>
      • KdTreeNodeList<T>
      • Key
      • Node<T>
      • NodeBase<T>
      • NodeDataContainer<T>
      • NodeDistance<TNode>
      • QuadTree<T>
      • Root<T>
      • TreeDataContainer<T>
    • Mars.Common.Collections.CritBit
      • ICritBitTree<TValue>
    • Mars.Common.Collections.Graph
      • EdgeData
      • GraphData
      • GraphSerializer
      • ISpatialGraph
      • KeyContainer
      • NodeData
      • SpatialGraph
      • SpatialGraphHelper
    • Mars.Common.Collections.Graph.Algorithms
      • AStar
      • CompressedPathDatabase
      • ContractionSearch
      • DepthLimitedTraversal
    • Mars.Common.Collections.Graph.Helper
      • INodeFinder
      • KdTreeNodeFinder
      • RunLengthEncoder
    • Mars.Common.Collections.KNNGraph
      • DefaultRandomGenerator
      • DistanceUtils
      • EventSources
      • EventSources.GraphBuildEventSource
      • EventSources.GraphSearchEventSource
      • IProgressReporter
      • IProvideRandomValues
      • KnnGraph<TItem, TDistance>
      • KnnGraph<TItem, TDistance>.KnnSearchResult
      • KnnGraph<TItem, TDistance>.Parameters
      • Node
      • ReverseComparer<T>
      • ReverseComparerExtensions
      • SelectionKind
      • TravelingCosts<TItem, TDistance>
    • Mars.Common.Compat
      • FormatDecoderAttribute
      • FormatEncoderAttribute
      • FormatHandlerAttribute
      • IntegerAttribute
      • NegativeIntegerAttribute
      • NonnegativeIntegerAttribute
      • NonpositiveIntegerAttribute
      • PositiveIntegerAttribute
    • Mars.Common.Data
      • DomainDataImporter
    • Mars.Common.Data.Providers
      • AscDataProvider
      • GeoJsonFeatureCollectionConverter
      • GeoJsonFeatureConverter
      • GeometryDataProvider
      • GraphMlProvider
      • HttpDataProvider
      • IDataProvider<TInput>
      • JsonFileDataProvider
      • JsonTextDataProvider
      • XmlFileDataProvider
      • XmlTextDataProvider
    • Mars.Common.Exceptions
      • DimensionMismatchException
      • ParseException
    • Mars.Common.IO
      • ExtensionMethods
      • FileClientUtils
      • FileKeys
      • HttpClientUtils
      • ObjectSerialize
      • Serializer
      • SerializerCompression
      • SparseFormat
      • SparseReader
      • SparseWriter
    • Mars.Common.IO.Attributes
      • SerializationBinderAttribute
      • SurrogateSelectorAttribute
    • Mars.Common.IO.Console
      • ChildProgressBar
      • IProgressBar
      • ProgressBar
      • ProgressBarBase
      • ProgressBarHeight
      • ProgressBarOptions
      • ProgressBarSimple
    • Mars.Common.IO.Csv
      • CsvAnalyzer
      • CsvReader
      • CsvReader.RecordEnumerator
      • CsvWriter
      • MissingFieldAction
      • ParseErrorAction
      • ValueTrimmingOptions
    • Mars.Common.IO.Events
      • ParseErrorEventArgs
    • Mars.Common.IO.Exceptions
      • MalformedCsvException
      • MissingFieldCsvException
    • Mars.Common.IO.Mapped
      • Context
      • DefaultArrayFactory
      • Extensions
      • IArrayFactory
      • ISerializableToStream
      • MappedAccessor<T>
      • MemoryMap
      • MemoryMap.CreateAccessorFunc<T>
      • MemoryMap.ReadFromDelegate<T>
      • MemoryMap.WriteToDelegate<T>
      • MemoryMapDelegates
      • MemoryMapDelegates.CreateAccessorFunc<T>
      • MemoryMapStream
    • Mars.Common.IO.Mapped.Accessors
      • MappedAccessorByte
      • MappedAccessorDouble
      • MappedAccessorInt16
      • MappedAccessorInt32
      • MappedAccessorInt64
      • MappedAccessorSingle
      • MappedAccessorUInt16
      • MappedAccessorUInt32
      • MappedAccessorUInt64
      • MappedAccessorVariable<T>
    • Mars.Common.IO.Mapped.Arrays
      • Array<T>
      • ArrayBase<T>
      • ArrayProfile
      • MappedArray<TMapped, T>
      • MappedArray<TMapped, T>.MapFrom
      • MappedArray<TMapped, T>.MapTo
      • MemoryArray<T>
      • VariableArray<T>
    • Mars.Common.IO.Mapped.Collections
      • MemoryBackedDictionary<TKey, TValue>
      • MemoryBackedList<T>
    • Mars.Common.IO.Mapped.Indexes
      • Index<T>
    • Mars.Common.IO.Mapped.Streams
      • CappedStream
    • Mars.Common.Socket
      • ByteOrder
      • CloseEventArgs
      • CloseStatusCode
      • CompressionMethod
      • ErrorEventArgs
      • Ext
      • MessageEventArgs
      • WebSocket
      • WebSocketException
      • WebSocketState
    • Mars.Common.Socket.Server
      • IWebSocketSession
      • WebHeaderCollection
      • WebSocketBehavior
      • WebSocketContext
      • WebSocketServer
      • WebSocketServiceHost
      • WebSocketServiceManager
      • WebSocketSessionManager
    • Mars.Numerics
      • Classes
      • Combinatorics
      • Constants
      • Distance
      • Elementwise
      • Jagged
      • MathematicsException
      • MathHelper
      • Matrix
      • MatrixOrder
      • MatrixType
      • Norm
      • Sort
      • Sorting
      • Sparse
      • Sparse<T>
      • Tools
      • Vector
      • VectorHelper
      • VectorType
    • Mars.Numerics.Comparers
      • ArrayComparer<T>
      • ComparerDirection
      • CustomComparer<T>
      • ElementComparer
      • ElementComparer<T>
      • GeneralComparer
      • StableComparer<T>
    • Mars.Numerics.Distances
      • Angular
      • Chebyshev
      • Cosine
      • Dirac<T>
      • Euclidean
      • Hamming
      • Hamming<T>
      • Haversine
      • Jaccard
      • Jaccard<T>
      • Kulczynski
      • Levenshtein
      • Levenshtein<T>
      • Manhattan
      • Matching
      • Minkowski
      • SquareEuclidean
      • Vincenty
      • Vincenty.Ellipsoid
    • Mars.Numerics.Distances.Base
      • IDistance<T>
      • IDistance<TFirst, TSecond>
      • IMetric<T>
      • ISimilarity<T, TU>
      • ISimilarity<T>
    • Mars.Numerics.Exceptions
      • DimensionMismatchException
      • NonPositiveDefiniteMatrixException
      • SingularMatrixException
    • Mars.Numerics.Formats
      • DefaultMatrixFormatProvider
      • IMatrixFormatProvider
      • MatrixFormatProviderBase
      • MatrixFormatter
      • OctaveMatrixFormatProvider
    • Mars.Numerics.Ranges
      • ByteRange
      • DoubleRange
      • FloatRange
      • IntRange
      • IRange<T>
    • Mars.Numerics.Statistics
      • ConstValueDistribution<T>
      • Distribution<T>
      • FastGaussianDistributionD
      • FastGaussianDistributionF
      • IDistribution
      • UniformDiscreteDistribution
      • UniformDistributionD
      • UniformDistributionF
    • Mars.Numerics.Statistics.Base
      • BinarySearch
      • DistributionBase
      • ISampleableDistribution<TObservations>
      • IUnivariateDistribution
      • IUnivariateDistribution<TObservation>
      • UnivariateDiscreteDistribution

    Class Sort

    Extension methods for sorting operations.
    Inheritance
    System.Object
    Sort
    Namespace: Mars.Numerics
    Assembly: Mars.Numerics.dll
    Syntax
    public static class Sort : object

    Methods

    Insertion<T>(T[], Func<T, T, Int32>, Boolean)

    Insertion sort.
    Declaration
    public static int Insertion<T>(T[] keys, Func<T, T, int> comparer, bool asc = true)
    Parameters
    Type Name Description
    T[] keys
    Func<T, T, System.Int32> comparer
    System.Boolean asc
    Returns
    Type Description
    System.Int32
    Type Parameters
    Name Description
    T

    Insertion<T>(T[], Boolean)

    Insertion sort.
    Declaration
    public static int Insertion<T>(T[] keys, bool asc = true)
        where T : IComparable<T>
    Parameters
    Type Name Description
    T[] keys
    System.Boolean asc
    Returns
    Type Description
    System.Int32
    Type Parameters
    Name Description
    T

    Insertion<T>(T[], Int32, Int32, Func<T, T, Int32>, Boolean)

    Insertion sort.
    Declaration
    public static int Insertion<T>(T[] keys, int first, int last, Func<T, T, int> comparer, bool asc = true)
    Parameters
    Type Name Description
    T[] keys
    System.Int32 first
    System.Int32 last
    Func<T, T, System.Int32> comparer
    System.Boolean asc
    Returns
    Type Description
    System.Int32
    Type Parameters
    Name Description
    T

    Insertion<T>(T[], Int32, Int32, Boolean)

    Insertion sort.
    Declaration
    public static int Insertion<T>(T[] keys, int first, int last, bool asc = true)
        where T : IComparable<T>
    Parameters
    Type Name Description
    T[] keys
    System.Int32 first
    System.Int32 last
    System.Boolean asc
    Returns
    Type Description
    System.Int32
    Type Parameters
    Name Description
    T

    Insertion<TKey, TValue>(TKey[], TValue[], Func<TKey, TKey, Int32>, Boolean)

    Insertion sort.
    Declaration
    public static int Insertion<TKey, TValue>(TKey[] keys, TValue[] items, Func<TKey, TKey, int> comparer, bool asc = true)
    Parameters
    Type Name Description
    TKey[] keys
    TValue[] items
    Func<TKey, TKey, System.Int32> comparer
    System.Boolean asc
    Returns
    Type Description
    System.Int32
    Type Parameters
    Name Description
    TKey
    TValue

    Insertion<T, TU>(T[], TU[], Boolean)

    Insertion sort.
    Declaration
    public static int Insertion<T, TU>(T[] keys, TU[] items, bool asc = true)
        where T : IComparable<T>
    Parameters
    Type Name Description
    T[] keys
    TU[] items
    System.Boolean asc
    Returns
    Type Description
    System.Int32
    Type Parameters
    Name Description
    T
    TU

    Insertion<TKeys, TValue>(TKeys[], TValue[], Int32, Int32, Func<TKeys, TKeys, Int32>, Boolean)

    Insertion sort.
    Declaration
    public static int Insertion<TKeys, TValue>(TKeys[] keys, TValue[] items, int first, int last, Func<TKeys, TKeys, int> comparer, bool asc = true)
    Parameters
    Type Name Description
    TKeys[] keys
    TValue[] items
    System.Int32 first
    System.Int32 last
    Func<TKeys, TKeys, System.Int32> comparer
    System.Boolean asc
    Returns
    Type Description
    System.Int32
    Type Parameters
    Name Description
    TKeys
    TValue

    Insertion<TKey, TValue>(TKey[], TValue[], Int32, Int32, Boolean)

    Insertion sort.
    Declaration
    public static int Insertion<TKey, TValue>(TKey[] keys, TValue[] items, int first, int last, bool asc = true)
        where TKey : IComparable<TKey>
    Parameters
    Type Name Description
    TKey[] keys
    TValue[] items
    System.Int32 first
    System.Int32 last
    System.Boolean asc
    Returns
    Type Description
    System.Int32
    Type Parameters
    Name Description
    TKey
    TValue

    NthElement<T>(T[], Int32, Boolean)

    Retrieves the n-th smallest element in an array. See remarks for more info.
    Declaration
    public static T NthElement<T>(this T[] items, int n, bool asc = true)
        where T : IComparable<T>
    Parameters
    Type Name Description
    T[] items The array of elements from which the n-th element should be extracted.
    System.Int32 n The position to look for (0 returns the smallest element, 1 the second smallest, and so on).
    System.Boolean asc Whether to take the smallest or the largest element. If set to false, instead of returning the smallest, the method will return the largest elements.
    Returns
    Type Description
    T If asc is true, returns the n-th smallest element in the array. Otherwise, returns the n-th largest.
    Type Parameters
    Name Description
    T The type for the items in the array.
    Remarks
    As a side-effect, partially orders the collection, making sure every element smaller than the n-th smaller element are in the beginning of the array (but not necessarily in order). If you need the values that come before the n-th element to also be in order, please use the Partial<T>(T[], Int32, Boolean) method instead.

    NthElement<T>(T[], Int32, Int32, Int32, Func<T, T, Int32>, Boolean)

    Retrieves the n-th smallest element in an array. See remarks for more info.
    Declaration
    public static T NthElement<T>(this T[] items, int first, int last, int n, Func<T, T, int> compare, bool asc = true)
    Parameters
    Type Name Description
    T[] items The array of elements from which the n-th element should be extracted.
    System.Int32 first The beginning of the search interval.
    System.Int32 last The end of the search interval.
    System.Int32 n The position to look for (0 returns the smallest element, 1 the second smallest, and so on).
    Func<T, T, System.Int32> compare The comparison function to be used to sort elements.
    System.Boolean asc Whether to take the smallest or the largest element. If set to false, instead of returning the smallest, the method will return the largest elements.
    Returns
    Type Description
    T If asc is true, returns the n-th smallest element in the array. Otherwise, returns the n-th largest.
    Type Parameters
    Name Description
    T The type for the items in the array.
    Remarks
    As a side-effect, partially orders the collection, making sure every element smaller than the n-th smaller element are in the beginning of the array (but not necessarily in order). If you need the values that come before the n-th element to also be in order, please use the Partial<T>(T[], Int32, Boolean) method instead.

    NthElement<T>(T[], Int32, Int32, Int32, Boolean)

    Retrieves the n-th smallest element in an array. See remarks for more info.
    Declaration
    public static T NthElement<T>(this T[] items, int first, int last, int n, bool asc = true)
        where T : IComparable<T>
    Parameters
    Type Name Description
    T[] items The array of elements from which the n-th element should be extracted.
    System.Int32 first The beginning of the search interval.
    System.Int32 last The end of the search interval.
    System.Int32 n The position to look for (0 returns the smallest element, 1 the second smallest, and so on).
    System.Boolean asc Whether to take the smallest or the largest element. If set to false, instead of returning the smallest, the method will return the largest elements.
    Returns
    Type Description
    T If asc is true, returns the n-th smallest element in the array. Otherwise, returns the n-th largest.
    Type Parameters
    Name Description
    T The type for the items in the array.
    Remarks
    As a side-effect, partially orders the collection, making sure every element smaller than the n-th smaller element are in the beginning of the array (but not necessarily in order). If you need the values that come before the n-th element to also be in order, please use the Partial<T>(T[], Int32, Boolean) method instead.

    NthElement<TKey, TValue>(TKey[], TValue[], Int32, Boolean)

    Retrieves the n-th smallest element in an array. See remarks for more info.
    Declaration
    public static TKey NthElement<TKey, TValue>(this TKey[] keys, TValue[] items, int n, bool asc = true)
        where TKey : IComparable<TKey>
    Parameters
    Type Name Description
    TKey[] keys The keys that will be used to determine the order of elements in items.
    TValue[] items The array of elements from which the n-th element should be extracted.
    System.Int32 n The position to look for (0 returns the smallest element, 1 the second smallest, and so on).
    System.Boolean asc Whether to take the smallest or the largest element. If set to false, instead of returning the smallest, the method will return the largest elements.
    Returns
    Type Description
    TKey If asc is true, returns the n-th smallest element in the array. Otherwise, returns the n-th largest.
    Type Parameters
    Name Description
    TKey The type for the keys associated with each value in the items array.
    TValue The type for the items in the array.
    Remarks
    As a side-effect, partially orders the collection, making sure every element smaller than the n-th smaller element are in the beginning of the array (but not necessarily in order). If you need the values that come before the n-th element to also be in order, please use the Partial<T>(T[], Int32, Boolean) method instead.

    NthElement<TKey, TValue>(TKey[], TValue[], Int32, Int32, Int32, Func<TKey, TKey, Int32>, Boolean)

    Retrieves the n-th smallest element in an array. See remarks for more info.
    Declaration
    public static TKey NthElement<TKey, TValue>(this TKey[] keys, TValue[] items, int first, int last, int n, Func<TKey, TKey, int> compare, bool asc = true)
    Parameters
    Type Name Description
    TKey[] keys The keys that will be used to determine the order of elements in items.
    TValue[] items The array of elements from which the n-th element should be extracted.
    System.Int32 first The beginning of the search interval.
    System.Int32 last The end of the search interval.
    System.Int32 n The position to look for (0 returns the smallest element, 1 the second smallest, and so on).
    Func<TKey, TKey, System.Int32> compare The comparison function to be used to sort elements.
    System.Boolean asc Whether to take the smallest or the largest element. If set to false, instead of returning the smallest, the method will return the largest elements.
    Returns
    Type Description
    TKey If asc is true, returns the n-th smallest element in the array. Otherwise, returns the n-th largest.
    Type Parameters
    Name Description
    TKey The type for the keys associated with each value in the items array.
    TValue The type for the items in the array.
    Remarks
    As a side-effect, partially orders the collection, making sure every element smaller than the n-th smaller element are in the beginning of the array (but not necessarily in order). If you need the values that come before the n-th element to also be in order, please use the Partial<T>(T[], Int32, Boolean) method instead.

    NthElement<TKey, TValue>(TKey[], TValue[], Int32, Int32, Int32, Boolean)

    Retrieves the n-th smallest element in an array. See remarks for more info.
    Declaration
    public static TKey NthElement<TKey, TValue>(this TKey[] keys, TValue[] items, int first, int last, int n, bool asc = true)
        where TKey : IComparable<TKey>
    Parameters
    Type Name Description
    TKey[] keys The keys that will be used to determine the order of elements in items.
    TValue[] items The array of elements from which the n-th element should be extracted.
    System.Int32 first The beginning of the search interval.
    System.Int32 last The end of the search interval.
    System.Int32 n The position to look for (0 returns the smallest element, 1 the second smallest, and so on).
    System.Boolean asc Whether to take the smallest or the largest element. If set to false, instead of returning the smallest, the method will return the largest elements.
    Returns
    Type Description
    TKey If asc is true, returns the n-th smallest element in the array. Otherwise, returns the n-th largest.
    Type Parameters
    Name Description
    TKey The type for the keys associated with each value in the items array.
    TValue The type for the items in the array.
    Remarks
    As a side-effect, partially orders the collection, making sure every element smaller than the n-th smaller element are in the beginning of the array (but not necessarily in order). If you need the values that come before the n-th element to also be in order, please use the Partial<T>(T[], Int32, Boolean) method instead.

    Partial<T>(T[], Int32, Boolean)

    Partially orders a collection, making sure every element smaller than the n-th smaller element are in the beginning of the array.
    Declaration
    public static void Partial<T>(T[] items, int n, bool asc = true)
        where T : IComparable<T>
    Parameters
    Type Name Description
    T[] items The array of elements from which the n-th element should be extracted.
    System.Int32 n The position to look for (0 returns the smallest element, 1 the second smallest, and so on).
    System.Boolean asc Whether to take the smallest or the largest element. If set to false, instead of returning the smallest, the method will return the largest elements in the beginning of the array.
    Type Parameters
    Name Description
    T The type for the items in the array.

    Partial<TKey, TValue>(TKey[], TValue[], Int32, Boolean)

    Partially orders a collection, making sure every element smaller than the n-th smaller element are in the beginning of the array.
    Declaration
    public static void Partial<TKey, TValue>(TKey[] keys, TValue[] items, int n, bool asc = true)
        where TKey : IComparable<TKey>
    Parameters
    Type Name Description
    TKey[] keys The keys that will be used to determine the order of elements in items.
    TValue[] items The array of elements from which the n-th element should be extracted.
    System.Int32 n The position to look for (0 returns the smallest element, 1 the second smallest, and so on).
    System.Boolean asc Whether to take the smallest or the largest element. If set to false, instead of returning the smallest, the method will return the largest elements in the beginning of the array.
    Type Parameters
    Name Description
    TKey The type for the keys associated with each value in the items array.
    TValue The type for the items in the array.

    Partition<T>(T[], Int32, Int32, Func<T, T, Int32>, Boolean)

    Reorders the elements in the range [left, right) in such a way that all elements for which the function compare returns true precede the elements for which compare returns false. Relative order of the elements is not preserved. This function should be equivalent to C++'s std::partition.
    Declaration
    public static int Partition<T>(this T[] items, int first, int last, Func<T, T, int> compare, bool asc = true)
    Parameters
    Type Name Description
    T[] items The list to be reordered.
    System.Int32 first The beginning of the range to be reordered.
    System.Int32 last The end of the range to be reordered.
    Func<T, T, System.Int32> compare Function to use in the comparison.
    System.Boolean asc Whether to sort in ascending or descending order.
    Returns
    Type Description
    System.Int32 The index of the new pivot.
    Type Parameters
    Name Description
    T

    Partition<T>(T[], Int32, Int32, Boolean)

    Reorders the elements in the range [left, right) in such a way that all elements that are smaller than the pivot precede those that are greater than the pivot. Relative order of the elements is not preserved. This function should be equivalent to C++'s std::partition.
    Declaration
    public static int Partition<T>(this T[] keys, int first, int last, bool asc = true)
        where T : IComparable<T>
    Parameters
    Type Name Description
    T[] keys The list to be reordered.
    System.Int32 first The beginning of the range to be reordered.
    System.Int32 last The end of the range to be reordered.
    System.Boolean asc Whether to sort in ascending or descending order.
    Returns
    Type Description
    System.Int32 The index of the new pivot.
    Type Parameters
    Name Description
    T

    Partition<TKey, TValue>(TKey[], TValue[], Int32, Int32, Func<TKey, TKey, Int32>, Boolean)

    Reorders the elements in the range [left, right) in such a way that all elements for which the function compare returns true precede the elements for which compare returns false. Relative order of the elements is not preserved. This function should be equivalent to C++'s std::partition.
    Declaration
    public static int Partition<TKey, TValue>(this TKey[] keys, TValue[] items, int first, int last, Func<TKey, TKey, int> compare, bool asc = true)
    Parameters
    Type Name Description
    TKey[] keys The list to be reordered.
    TValue[] items An array of keys associated with each element in the list.
    System.Int32 first The beginning of the range to be reordered.
    System.Int32 last The end of the range to be reordered.
    Func<TKey, TKey, System.Int32> compare Function to use in the comparison.
    System.Boolean asc Whether to sort in ascending or descending order.
    Returns
    Type Description
    System.Int32 The index of the new pivot.
    Type Parameters
    Name Description
    TKey
    TValue

    Partition<TKey, TValue>(TKey[], TValue[], Int32, Int32, Boolean)

    Reorders the elements in the range [left, right) in such a way that all elements that are smaller than the pivot precede those that are greater than the pivot. Relative order of the elements is not preserved. This function should be equivalent to C++'s std::partition.
    Declaration
    public static int Partition<TKey, TValue>(this TKey[] keys, TValue[] items, int first, int last, bool asc = true)
        where TKey : IComparable<TKey>
    Parameters
    Type Name Description
    TKey[] keys The list to be reordered.
    TValue[] items An array of keys associated with each element in the list.
    System.Int32 first The beginning of the range to be reordered.
    System.Int32 last The end of the range to be reordered.
    System.Boolean asc Whether to sort in ascending or descending order.
    Returns
    Type Description
    System.Int32 The index of the new pivot.
    Type Parameters
    Name Description
    TKey
    TValue
    Back to top Copyright © MARS GROUP.
    HAW Hamburg