Skip to content

Support sorting arrays of bitsets #720

Closed
@degawa

Description

@degawa

Motivation

Currently, stdlib does not support the sorting of bitset arrays. Support for sorting arrays of bitsets may allow stdlib to apply to modern numerical simulations.

In recent years, adaptive mesh refinement (AMR) has attracted much attention in fluid simulations. In some research aimed at the efficient implementation of AMR, a bit sequence like 11010010 representing the grid position and refinement level is used as an ID for a grid, and the bitset is used to store IDs.
The IDs represented by bitsets are sorted for load balancing in parallel computations. stdlib has bitsets but cannot perform sorting. This prevents the implementation of AMR using stdlib.
Thus, it is worth supporting sorting arrays of bitsets.

Prior Art

Additional Information

stdlib already implements the assignment operator (=) and comparison operators (>, >=, <, <=) for bitsets. So it is easy to support sorting arrays of bitsets by adding a few lines to stdlib_sorting.fypp and related files:

+#! Derived type bitsets
+#:set BITSET_KINDS = ["bitset_64", "bitset_large"]
+
+#! Bitset types to be considered during templating
+#:set BITSET_TYPES = ["type({})".format(k) for k in BITSET_KINDS]
+#:set BITSET_TYPES_ALT_NAME = list(zip(BITSET_TYPES, BITSET_TYPES, BITSET_KINDS))

#! For better code reuse in fypp, make lists that contain the input types,
#! with each having output types and a separate name prefix for subroutines
#! This approach allows us to have the same code for all input types.
-#:set IRSC_TYPES_ALT_NAME = INT_TYPES_ALT_NAME + REAL_TYPES_ALT_NAME + STRING_TYPES_ALT_NAME + CHAR_TYPES_ALT_NAME
+#:set IRSC_TYPES_ALT_NAME = INT_TYPES_ALT_NAME + REAL_TYPES_ALT_NAME + STRING_TYPES_ALT_NAME + CHAR_TYPES_ALT_NAME + BITSET_TYPES_ALT_NAME

Metadata

Metadata

Assignees

No one assigned

    Labels

    ideaProposition of an idea and opening an issue to discuss it

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions