Skip to content

Add generic is_sorted utility function to stdlib_sorting #1166

@srinjoy933

Description

@srinjoy933

Currently, the stdlib_sorting module provides robust O(N log N) and O(N) sorting algorithms but lacks a fundamental O(N) utility to verify array monotonicity prior to invoking computationally expensive sorting routines. This issue proposes the implementation of a pure, generic is_sorted(array, reverse) function to unblock conditional sorting workflows and data validation. The implementation will utilize fypp templating to generate highly optimized, early-exit validation loops for all module-supported intrinsic types (int8 through int64, sp/dp/qp reals, characters) and derived types (string_type, bitset). The function will return a standard logical scalar indicating whether the array satisfies a non-decreasing order, or a non-increasing order if the optional intent(in) :: reverse logical flag is asserted as .true.. Adding this feature aligns Fortran's stdlib with standard library capabilities found in C++ (std::is_sorted) and Rust, providing an essential primitive for algorithmic optimization.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions