module Data.Tensort.Utils.Check (isSorted) where
import Data.Tensort.Utils.ComparisonFunctions (lessThanOrEqualBit, lessThanOrEqualRecord)
import Data.Tensort.Utils.Types (Sortable (..))
isSorted :: Sortable -> Bool
isSorted :: Sortable -> Bool
isSorted (SortBit []) = Bool
True
isSorted (SortBit [Bit
_]) = Bool
True
isSorted (SortBit (Bit
x : Bit
y : [Bit]
remainingElements)) = Bit -> Bit -> Bool
lessThanOrEqualBit Bit
x Bit
y Bool -> Bool -> Bool
&& Sortable -> Bool
isSorted ([Bit] -> Sortable
SortBit (Bit
y Bit -> [Bit] -> [Bit]
forall a. a -> [a] -> [a]
: [Bit]
remainingElements))
isSorted (SortRec []) = Bool
True
isSorted (SortRec [Record
_]) = Bool
True
isSorted (SortRec (Record
x : Record
y : [Record]
remainingElements)) = Record -> Record -> Bool
lessThanOrEqualRecord Record
x Record
y Bool -> Bool -> Bool
&& Sortable -> Bool
isSorted ([Record] -> Sortable
SortRec (Record
y Record -> [Record] -> [Record]
forall a. a -> [a] -> [a]
: [Record]
remainingElements))