packages feed

tensort 1.0.1.4 → 1.1.0.0

raw patch · 33 files changed

+1006/−1675 lines, 33 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

- Data.Tensort.Utils.Types: ByteMemR :: [ByteR] -> MemoryR
- Data.Tensort.Utils.Types: SBitBit :: Bit -> SBit
- Data.Tensort.Utils.Types: SBitRec :: Record -> SBit
- Data.Tensort.Utils.Types: SBytesBit :: [Byte] -> SBytes
- Data.Tensort.Utils.Types: SBytesRec :: [ByteR] -> SBytes
- Data.Tensort.Utils.Types: SMemoryBit :: Memory -> SMemory
- Data.Tensort.Utils.Types: SMemoryRec :: MemoryR -> SMemory
- Data.Tensort.Utils.Types: SRecordBit :: Record -> SRecord
- Data.Tensort.Utils.Types: SRecordRec :: RecordR -> SRecord
- Data.Tensort.Utils.Types: SRecordsBit :: [Record] -> SRecords
- Data.Tensort.Utils.Types: SRecordsRec :: [RecordR] -> SRecords
- Data.Tensort.Utils.Types: STensorBit :: Tensor -> STensor
- Data.Tensort.Utils.Types: STensorRec :: TensorR -> STensor
- Data.Tensort.Utils.Types: STensorsBit :: [Tensor] -> STensors
- Data.Tensort.Utils.Types: STensorsRec :: [TensorR] -> STensors
- Data.Tensort.Utils.Types: SortBit :: [Bit] -> Sortable
- Data.Tensort.Utils.Types: SortRec :: [Record] -> Sortable
- Data.Tensort.Utils.Types: TensorMemR :: [TensorR] -> MemoryR
- Data.Tensort.Utils.Types: data MemoryR
- Data.Tensort.Utils.Types: data SBit
- Data.Tensort.Utils.Types: data SBytes
- Data.Tensort.Utils.Types: data SMemory
- Data.Tensort.Utils.Types: data SRecord
- Data.Tensort.Utils.Types: data SRecords
- Data.Tensort.Utils.Types: data STensor
- Data.Tensort.Utils.Types: data STensors
- Data.Tensort.Utils.Types: data Sortable
- Data.Tensort.Utils.Types: fromSBitBit :: SBit -> Bit
- Data.Tensort.Utils.Types: fromSBitBits :: [SBit] -> Sortable
- Data.Tensort.Utils.Types: fromSBitRec :: SBit -> Record
- Data.Tensort.Utils.Types: fromSBitRecs :: [SBit] -> Sortable
- Data.Tensort.Utils.Types: fromSBytesBit :: SBytes -> [[Bit]]
- Data.Tensort.Utils.Types: fromSBytesRec :: SBytes -> [[Record]]
- Data.Tensort.Utils.Types: fromSMemoryBit :: SMemory -> Memory
- Data.Tensort.Utils.Types: fromSMemoryRec :: SMemory -> MemoryR
- Data.Tensort.Utils.Types: fromSRecordArrayBit :: [SRecord] -> [Record]
- Data.Tensort.Utils.Types: fromSRecordArrayRec :: [SRecord] -> [RecordR]
- Data.Tensort.Utils.Types: fromSRecordBit :: SRecord -> Record
- Data.Tensort.Utils.Types: fromSRecordRec :: SRecord -> RecordR
- Data.Tensort.Utils.Types: fromSRecordsBit :: SRecords -> [Record]
- Data.Tensort.Utils.Types: fromSRecordsRec :: SRecords -> [RecordR]
- Data.Tensort.Utils.Types: fromSTensorBit :: STensor -> Tensor
- Data.Tensort.Utils.Types: fromSTensorRec :: STensor -> TensorR
- Data.Tensort.Utils.Types: fromSTensorsBit :: STensors -> [Tensor]
- Data.Tensort.Utils.Types: fromSTensorsRec :: STensors -> [TensorR]
- Data.Tensort.Utils.Types: fromSortBit :: Sortable -> [Bit]
- Data.Tensort.Utils.Types: fromSortRec :: Sortable -> [Record]
- Data.Tensort.Utils.Types: instance GHC.Classes.Eq Data.Tensort.Utils.Types.Memory
- Data.Tensort.Utils.Types: instance GHC.Classes.Eq Data.Tensort.Utils.Types.MemoryR
- Data.Tensort.Utils.Types: instance GHC.Classes.Eq Data.Tensort.Utils.Types.SBit
- Data.Tensort.Utils.Types: instance GHC.Classes.Eq Data.Tensort.Utils.Types.SBytes
- Data.Tensort.Utils.Types: instance GHC.Classes.Eq Data.Tensort.Utils.Types.SMemory
- Data.Tensort.Utils.Types: instance GHC.Classes.Eq Data.Tensort.Utils.Types.SRecord
- Data.Tensort.Utils.Types: instance GHC.Classes.Eq Data.Tensort.Utils.Types.SRecords
- Data.Tensort.Utils.Types: instance GHC.Classes.Eq Data.Tensort.Utils.Types.STensor
- Data.Tensort.Utils.Types: instance GHC.Classes.Eq Data.Tensort.Utils.Types.STensors
- Data.Tensort.Utils.Types: instance GHC.Classes.Eq Data.Tensort.Utils.Types.Sortable
- Data.Tensort.Utils.Types: instance GHC.Classes.Ord Data.Tensort.Utils.Types.Memory
- Data.Tensort.Utils.Types: instance GHC.Classes.Ord Data.Tensort.Utils.Types.MemoryR
- Data.Tensort.Utils.Types: instance GHC.Classes.Ord Data.Tensort.Utils.Types.SBit
- Data.Tensort.Utils.Types: instance GHC.Classes.Ord Data.Tensort.Utils.Types.SBytes
- Data.Tensort.Utils.Types: instance GHC.Classes.Ord Data.Tensort.Utils.Types.SMemory
- Data.Tensort.Utils.Types: instance GHC.Classes.Ord Data.Tensort.Utils.Types.SRecord
- Data.Tensort.Utils.Types: instance GHC.Classes.Ord Data.Tensort.Utils.Types.SRecords
- Data.Tensort.Utils.Types: instance GHC.Classes.Ord Data.Tensort.Utils.Types.STensor
- Data.Tensort.Utils.Types: instance GHC.Classes.Ord Data.Tensort.Utils.Types.STensors
- Data.Tensort.Utils.Types: instance GHC.Classes.Ord Data.Tensort.Utils.Types.Sortable
- Data.Tensort.Utils.Types: instance GHC.Show.Show Data.Tensort.Utils.Types.Memory
- Data.Tensort.Utils.Types: instance GHC.Show.Show Data.Tensort.Utils.Types.MemoryR
- Data.Tensort.Utils.Types: instance GHC.Show.Show Data.Tensort.Utils.Types.SBit
- Data.Tensort.Utils.Types: instance GHC.Show.Show Data.Tensort.Utils.Types.SBytes
- Data.Tensort.Utils.Types: instance GHC.Show.Show Data.Tensort.Utils.Types.SMemory
- Data.Tensort.Utils.Types: instance GHC.Show.Show Data.Tensort.Utils.Types.SRecord
- Data.Tensort.Utils.Types: instance GHC.Show.Show Data.Tensort.Utils.Types.SRecords
- Data.Tensort.Utils.Types: instance GHC.Show.Show Data.Tensort.Utils.Types.STensor
- Data.Tensort.Utils.Types: instance GHC.Show.Show Data.Tensort.Utils.Types.STensors
- Data.Tensort.Utils.Types: instance GHC.Show.Show Data.Tensort.Utils.Types.Sortable
- Data.Tensort.Utils.Types: type BitR = Record
- Data.Tensort.Utils.Types: type ByteR = [Record]
- Data.Tensort.Utils.Types: type Record = (Address, TopBit)
- Data.Tensort.Utils.Types: type RecordR = (Address, TopBitR)
- Data.Tensort.Utils.Types: type RegisterR = [RecordR]
- Data.Tensort.Utils.Types: type STensorStack = STensor
- Data.Tensort.Utils.Types: type STensorStacks = STensors
- Data.Tensort.Utils.Types: type Tensor = (Register, Memory)
- Data.Tensort.Utils.Types: type TensorR = (RegisterR, MemoryR)
- Data.Tensort.Utils.Types: type TensorStackR = TensorR
- Data.Tensort.Utils.Types: type TopBitR = Record
- Data.Tensort.Utils.WrapSortAlg: wrapSortAlg :: SortAlg -> [Bit] -> [Bit]
+ Data.Tensort.Utils.SortRecs: sortRecs :: Ord a => SortAlg a -> [Record a] -> [Record a]
+ Data.Tensort.Utils.Types: Record :: (TopBit a, Address) -> Record a
+ Data.Tensort.Utils.Types: Tensor :: (Register a, Memory a) -> Tensor a
+ Data.Tensort.Utils.Types: fromRecord :: Record a -> (TopBit a, Address)
+ Data.Tensort.Utils.Types: fromTensor :: Tensor a -> (Register a, Memory a)
+ Data.Tensort.Utils.Types: instance GHC.Classes.Eq a => GHC.Classes.Eq (Data.Tensort.Utils.Types.Memory a)
+ Data.Tensort.Utils.Types: instance GHC.Classes.Eq a => GHC.Classes.Eq (Data.Tensort.Utils.Types.Record a)
+ Data.Tensort.Utils.Types: instance GHC.Classes.Eq a => GHC.Classes.Eq (Data.Tensort.Utils.Types.Tensor a)
+ Data.Tensort.Utils.Types: instance GHC.Classes.Ord a => GHC.Classes.Ord (Data.Tensort.Utils.Types.Memory a)
+ Data.Tensort.Utils.Types: instance GHC.Classes.Ord a => GHC.Classes.Ord (Data.Tensort.Utils.Types.Record a)
+ Data.Tensort.Utils.Types: instance GHC.Classes.Ord a => GHC.Classes.Ord (Data.Tensort.Utils.Types.Tensor a)
+ Data.Tensort.Utils.Types: instance GHC.Show.Show a => GHC.Show.Show (Data.Tensort.Utils.Types.Memory a)
+ Data.Tensort.Utils.Types: instance GHC.Show.Show a => GHC.Show.Show (Data.Tensort.Utils.Types.Record a)
+ Data.Tensort.Utils.Types: instance GHC.Show.Show a => GHC.Show.Show (Data.Tensort.Utils.Types.Tensor a)
+ Data.Tensort.Utils.Types: newtype Record a
+ Data.Tensort.Utils.Types: newtype Tensor a
- Data.Robustsort: robustsortB :: [Bit] -> [Bit]
+ Data.Robustsort: robustsortB :: Ord a => [a] -> [a]
- Data.Robustsort: robustsortM :: [Bit] -> [Bit]
+ Data.Robustsort: robustsortM :: Ord a => [a] -> [a]
- Data.Robustsort: robustsortP :: [Bit] -> [Bit]
+ Data.Robustsort: robustsortP :: Ord a => [a] -> [a]
- Data.Robustsort: robustsortRB :: [Bit] -> [Bit]
+ Data.Robustsort: robustsortRB :: Ord a => [a] -> [a]
- Data.Robustsort: robustsortRM :: [Bit] -> [Bit]
+ Data.Robustsort: robustsortRM :: Ord a => [a] -> [a]
- Data.Robustsort: robustsortRP :: [Bit] -> [Bit]
+ Data.Robustsort: robustsortRP :: Ord a => [a] -> [a]
- Data.Tensort: tensort :: [Bit] -> [Bit]
+ Data.Tensort: tensort :: Ord a => [a] -> [a]
- Data.Tensort.OtherSorts.Mergesort: mergesort :: Sortable -> Sortable
+ Data.Tensort.OtherSorts.Mergesort: mergesort :: Ord a => [a] -> [a]
- Data.Tensort.OtherSorts.Quicksort: quicksort :: Sortable -> Sortable
+ Data.Tensort.OtherSorts.Quicksort: quicksort :: Ord a => [a] -> [a]
- Data.Tensort.Robustsort: robustsortB :: Sortable -> Sortable
+ Data.Tensort.Robustsort: robustsortB :: Ord a => [Bit a] -> [Bit a]
- Data.Tensort.Robustsort: robustsortM :: Sortable -> Sortable
+ Data.Tensort.Robustsort: robustsortM :: Ord a => [Bit a] -> [Bit a]
- Data.Tensort.Robustsort: robustsortP :: Sortable -> Sortable
+ Data.Tensort.Robustsort: robustsortP :: Ord a => [Bit a] -> [Bit a]
- Data.Tensort.Robustsort: robustsortRB :: Sortable -> Sortable
+ Data.Tensort.Robustsort: robustsortRB :: Ord a => [Bit a] -> [Bit a]
- Data.Tensort.Robustsort: robustsortRCustom :: SortAlg -> Sortable -> Sortable
+ Data.Tensort.Robustsort: robustsortRCustom :: Ord a => SortAlg (Bit a) -> [Bit a] -> [Bit a]
- Data.Tensort.Robustsort: robustsortRM :: Sortable -> Sortable
+ Data.Tensort.Robustsort: robustsortRM :: Ord a => [Bit a] -> [Bit a]
- Data.Tensort.Robustsort: robustsortRP :: Sortable -> Sortable
+ Data.Tensort.Robustsort: robustsortRP :: Ord a => [Bit a] -> [Bit a]
- Data.Tensort.Subalgorithms.Bogosort: bogosort :: Sortable -> Sortable
+ Data.Tensort.Subalgorithms.Bogosort: bogosort :: Ord a => [a] -> [a]
- Data.Tensort.Subalgorithms.Bogosort: bogosortSeeded :: Int -> Sortable -> Sortable
+ Data.Tensort.Subalgorithms.Bogosort: bogosortSeeded :: Ord a => Int -> [a] -> [a]
- Data.Tensort.Subalgorithms.Bubblesort: bubblesort :: Sortable -> Sortable
+ Data.Tensort.Subalgorithms.Bubblesort: bubblesort :: Ord a => [a] -> [a]
- Data.Tensort.Subalgorithms.Exchangesort: exchangesort :: Sortable -> Sortable
+ Data.Tensort.Subalgorithms.Exchangesort: exchangesort :: Ord a => [a] -> [a]
- Data.Tensort.Subalgorithms.Magicsort: magicsort :: Sortable -> Sortable
+ Data.Tensort.Subalgorithms.Magicsort: magicsort :: Ord a => [a] -> [a]
- Data.Tensort.Subalgorithms.Permutationsort: permutationsort :: Sortable -> Sortable
+ Data.Tensort.Subalgorithms.Permutationsort: permutationsort :: Ord a => [a] -> [a]
- Data.Tensort.Subalgorithms.Rotationsort: rotationsort :: Sortable -> Sortable
+ Data.Tensort.Subalgorithms.Rotationsort: rotationsort :: Ord a => [a] -> [a]
- Data.Tensort.Subalgorithms.Rotationsort: rotationsortAmbi :: Sortable -> Sortable
+ Data.Tensort.Subalgorithms.Rotationsort: rotationsortAmbi :: Ord a => [a] -> [a]
- Data.Tensort.Subalgorithms.Rotationsort: rotationsortReverse :: Sortable -> Sortable
+ Data.Tensort.Subalgorithms.Rotationsort: rotationsortReverse :: Ord a => [a] -> [a]
- Data.Tensort.Subalgorithms.Rotationsort: rotationsortReverseAmbi :: Sortable -> Sortable
+ Data.Tensort.Subalgorithms.Rotationsort: rotationsortReverseAmbi :: Ord a => [a] -> [a]
- Data.Tensort.Subalgorithms.Supersort: magicSuperStrat :: SupersortStrat
+ Data.Tensort.Subalgorithms.Supersort: magicSuperStrat :: Ord a => SupersortStrat a
- Data.Tensort.Subalgorithms.Supersort: mundaneSuperStrat :: SupersortStrat
+ Data.Tensort.Subalgorithms.Supersort: mundaneSuperStrat :: Ord a => SupersortStrat a
- Data.Tensort.Subalgorithms.Supersort: supersort :: (SortAlg, SortAlg, SortAlg, SupersortStrat) -> Sortable -> Sortable
+ Data.Tensort.Subalgorithms.Supersort: supersort :: Ord a => (SortAlg a, SortAlg a, SortAlg a, SupersortStrat a) -> [a] -> [a]
- Data.Tensort.Tensort: tensort :: TensortProps -> Sortable -> Sortable
+ Data.Tensort.Tensort: tensort :: Ord a => TensortProps a -> [Bit a] -> [Bit a]
- Data.Tensort.Tensort: tensortB4 :: Sortable -> Sortable
+ Data.Tensort.Tensort: tensortB4 :: Ord a => [Bit a] -> [Bit a]
- Data.Tensort.Tensort: tensortBL :: Sortable -> Sortable
+ Data.Tensort.Tensort: tensortBL :: Ord a => [Bit a] -> [Bit a]
- Data.Tensort.Tensort: tensortBN :: Int -> Sortable -> Sortable
+ Data.Tensort.Tensort: tensortBN :: Ord a => Int -> [Bit a] -> [Bit a]
- Data.Tensort.Utils.Check: isSorted :: Sortable -> Bool
+ Data.Tensort.Utils.Check: isSorted :: Ord a => [a] -> Bool
- Data.Tensort.Utils.LogNat: getLnBytesize :: Sortable -> Int
+ Data.Tensort.Utils.LogNat: getLnBytesize :: Ord a => [a] -> Int
- Data.Tensort.Utils.MkTsProps: mkTsProps :: Int -> SortAlg -> TensortProps
+ Data.Tensort.Utils.MkTsProps: mkTsProps :: Ord a => Int -> SortAlg a -> TensortProps a
- Data.Tensort.Utils.RandomizeList: randomizeList :: Int -> Sortable -> Sortable
+ Data.Tensort.Utils.RandomizeList: randomizeList :: Ord a => Int -> [a] -> [a]
- Data.Tensort.Utils.Types: ByteMem :: [Byte] -> Memory
+ Data.Tensort.Utils.Types: ByteMem :: [Byte a] -> Memory a
- Data.Tensort.Utils.Types: TensorMem :: [Tensor] -> Memory
+ Data.Tensort.Utils.Types: TensorMem :: [Tensor a] -> Memory a
- Data.Tensort.Utils.Types: TensortProps :: Int -> SortAlg -> TensortProps
+ Data.Tensort.Utils.Types: TensortProps :: Int -> SortAlg a -> TensortProps a
- Data.Tensort.Utils.Types: [bytesize] :: TensortProps -> Int
+ Data.Tensort.Utils.Types: [bytesize] :: TensortProps a -> Int
- Data.Tensort.Utils.Types: [subAlgorithm] :: TensortProps -> SortAlg
+ Data.Tensort.Utils.Types: [subAlgorithm] :: TensortProps a -> SortAlg a
- Data.Tensort.Utils.Types: data Memory
+ Data.Tensort.Utils.Types: data Memory a
- Data.Tensort.Utils.Types: data TensortProps
+ Data.Tensort.Utils.Types: data TensortProps a
- Data.Tensort.Utils.Types: type Bit = Int
+ Data.Tensort.Utils.Types: type Bit a = a
- Data.Tensort.Utils.Types: type Byte = [Bit]
+ Data.Tensort.Utils.Types: type Byte a = [Bit a]
- Data.Tensort.Utils.Types: type Register = [Record]
+ Data.Tensort.Utils.Types: type Register a = [Record a]
- Data.Tensort.Utils.Types: type SortAlg = Sortable -> Sortable
+ Data.Tensort.Utils.Types: type SortAlg a = [a] -> [a]
- Data.Tensort.Utils.Types: type SupersortProps = (SortAlg, SortAlg, SortAlg, SupersortStrat)
+ Data.Tensort.Utils.Types: type SupersortProps a = (SortAlg a, SortAlg a, SortAlg a, SupersortStrat a)
- Data.Tensort.Utils.Types: type SupersortStrat = (Sortable, Sortable, Sortable) -> Sortable
+ Data.Tensort.Utils.Types: type SupersortStrat a = ([a], [a], [a]) -> [a]
- Data.Tensort.Utils.Types: type TensorStack = Tensor
+ Data.Tensort.Utils.Types: type TensorStack a = Tensor a
- Data.Tensort.Utils.Types: type TopBit = Bit
+ Data.Tensort.Utils.Types: type TopBit a = Bit a

Files

CHANGELOG.md view
@@ -2,101 +2,111 @@  ## 0.1.0.0 -- 2024-05-30 -* First version. Released to an eager world!+- First version. Released to an eager world!  ## 0.2.0.0 -- 2024-05-31 -* Add Logarithmic Tensort+- Add Logarithmic Tensort -* Rename and update Exchangesort+- Rename and update Exchangesort -* Simplify code and structure+- Simplify code and structure -* Cleanup exports+- Cleanup exports -* Cleanup Types+- Cleanup Types -* Improve documentation+- Improve documentation -* Add to package file+- Add to package file -* Expand supported dependency versions+- Expand supported dependency versions -* Add tests+- Add tests  ## 0.2.0.1 -- 2024-06-12 -* Add guards for short lists in input+- Add guards for short lists in input -* Improve testing+- Improve testing -* Improve documentation+- Improve documentation -* Add very basic benchmarking+- Add very basic benchmarking  ## 0.2.0.2 -- 2024-06-13 -* Cleanup testing and CI+- Cleanup testing and CI  ## 0.2.0.3 -- 2024-06-16 -* Improve testing compatibility (fix QuickCheck breaking Stackage build)+- Improve testing compatibility (fix QuickCheck breaking Stackage build)  ## 1.0.0.0 -- 2024-08-21 -* Add Recursive Robustsort+- Add Recursive Robustsort -* Add Rotationsort+- Add Rotationsort -* Fix Bubblesort to more closely match Ackley's non-'optimized' version+- Fix Bubblesort to more closely match Ackley's non-'optimized' version -* Add Benchmarking+- Add Benchmarking -* Expand README+- Expand README -* Replace Exchangesort with Rotationsort in Robustsort+- Replace Exchangesort with Rotationsort in Robustsort -* Use Sortable type in Tensort and Robustsort so they can be used recursively+- Use Sortable type in Tensort and Robustsort so they can be used recursively -* Add top-level Tensort and Robustsort functions wrapped in a type converter so+- Add top-level Tensort and Robustsort functions wrapped in a type converter so   they can be easily used to sort Bits (Integers) -* Add more helper functions+- Add more helper functions -* Many more updates to the algorithms - see README for details+- Many more updates to the algorithms - see README for details  ## 1.0.1.0 -- 2024-08-22 -* Export more functions for building custom Tensort variants+- Export more functions for building custom Tensort variants -* Cleanup and improve documentation+- Cleanup and improve documentation -* Cleanup code a bit+- Cleanup code a bit  ## 1.0.1.1 -- 2024-08-22 -* Make all pictures in README viewable on Hackage+- Make all pictures in README viewable on Hackage  ## 1.0.1.2 -- 2024-08-22 -* Include benchmarking results and README images in package+- Include benchmarking results and README images in package -* Improve flow in README+- Improve flow in README -* Cleanup code and documentation a bit+- Cleanup code and documentation a bit  ## 1.0.1.3 -- 2024-09-16 -* Adjust README formatting+- Adjust README formatting -* Add Hype section to README+- Add Hype section to README -* Some code and documentation cleanup+- Some code and documentation cleanup  ## 1.0.1.4 -- 2025-01-07 -* Bump version constraints on base and random+- Bump version constraints on base and random -* Test with new versions of GHC+- Test with new versions of GHC -* Fix typos and make minor changes to README+- Fix typos and make minor changes to README++## 1.1.0.0 -- 2025-02-14++- Add support for sorting all Ord types++- Expand types used in testing++- Remove types and functions no longer used++- Immensely cleanup the code
README.md view
@@ -1102,7 +1102,7 @@ ## Library  This package provides implementations of the following algorithms wrapped for-integer sorting:+Ord sorting:    - Standard Logarithmic Tensort @@ -1118,8 +1118,8 @@    - Recursive Magic Robustsort -It also provides many more algorithms and helper functions wrapped for both Bit-and Record sorting so you can make your own Tensort variants!+It also provides many more algorithms and helper functions so you can make your+own Tensort variants!  Check the code in `src/` or the documentation on Hackage/Hoogle for more details.
src/Data/Robustsort.hs view
@@ -1,5 +1,5 @@--- | This module provides convenience functions that wraps common Robustsort---   functions to sort lists of Bits without dealing with type conversion+-- | This module provides common Robustsort functions defined without reference+--   to Bits module Data.Robustsort   ( robustsortP,     robustsortB,@@ -18,8 +18,6 @@     robustsortRM,     robustsortRP,   )-import Data.Tensort.Utils.Types (Bit)-import Data.Tensort.Utils.WrapSortAlg (wrapSortAlg)  -- | Takes a list of Bits and returns a sorted list of Bits using a Basic --   Mundane Robustsort algorithm with a Permutationsort adjudicator@@ -28,10 +26,10 @@ --   'Data.Tensort.Robustsort.robustsortP' function  -- | ==== __Examples__---   >>> robustsortP [16, 23, 4, 8, 15, 42]+--   >>> robustsortP ([16, 23, 4, 8, 15, 42] :: [Int]) --   [4,8,15,16,23,42]-robustsortP :: [Bit] -> [Bit]-robustsortP = wrapSortAlg Data.Tensort.Robustsort.robustsortP+robustsortP :: (Ord a) => [a] -> [a]+robustsortP = Data.Tensort.Robustsort.robustsortP  -- | Takes a list of Bits and returns a sorted list of Bits using a Basic --   Mundane Robustsort algorithm with a Bogosort adjudicator@@ -40,10 +38,10 @@ --   'Data.Tensort.Robustsort.robustsortB' function  -- | ==== __Examples__---  >>> robustsortB [16, 23, 4, 8, 15, 42]+--  >>> robustsortB ([16, 23, 4, 8, 15, 42] :: [Int]) --  [4,8,15,16,23,42]-robustsortB :: [Bit] -> [Bit]-robustsortB = wrapSortAlg Data.Tensort.Robustsort.robustsortB+robustsortB :: (Ord a) => [a] -> [a]+robustsortB = Data.Tensort.Robustsort.robustsortB  -- | Takes a list of Bits and returns a sorted list of Bits using a Basic --   Magic Robustsort algorithm@@ -52,10 +50,10 @@ --   'Data.Tensort.Robustsort.robustsortM' function  -- | ==== __Examples__---  >>> robustsortM [16, 23, 4, 8, 15, 42]+--  >>> robustsortM ([16, 23, 4, 8, 15, 42] :: [Int]) --  [4,8,15,16,23,42]-robustsortM :: [Bit] -> [Bit]-robustsortM = wrapSortAlg Data.Tensort.Robustsort.robustsortM+robustsortM :: (Ord a) => [a] -> [a]+robustsortM = Data.Tensort.Robustsort.robustsortM  -- | Takes a list of Bits and returns a sorted list of Bits using a Recursive --   Mundane Robustsort algorithm with a Permutationsort adjudicator@@ -64,10 +62,10 @@ --   'Data.Tensort.Robustsort.robustsortRP' function  -- | ==== __Examples__---  >>> robustsortRP [16, 23, 4, 8, 15, 42]+--  >>> robustsortRP ([16, 23, 4, 8, 15, 42] :: [Int]) --  [4,8,15,16,23,42]-robustsortRP :: [Bit] -> [Bit]-robustsortRP = wrapSortAlg Data.Tensort.Robustsort.robustsortRP+robustsortRP :: (Ord a) => [a] -> [a]+robustsortRP = Data.Tensort.Robustsort.robustsortRP  -- | Takes a list of Bits and returns a sorted list of Bits using a Recursive --  Mundane Robustsort algorithm with a Bogosort adjudicator@@ -76,10 +74,10 @@ --   'Data.Tensort.Robustsort.robustsortRB' function  --  | ==== __Examples__---  >>> robustsortRB [16, 23, 4, 8, 15, 42]+--  >>> robustsortRB ([16, 23, 4, 8, 15, 42] :: [Int]) --  [4,8,15,16,23,42]-robustsortRB :: [Bit] -> [Bit]-robustsortRB = wrapSortAlg Data.Tensort.Robustsort.robustsortRB+robustsortRB :: (Ord a) => [a] -> [a]+robustsortRB = Data.Tensort.Robustsort.robustsortRB  -- | Takes a list of Bits and returns a sorted list of Bits using a Recursive --   Magic Robustsort algorithm@@ -88,7 +86,7 @@ --   'Data.Tensort.Robustsort.robustsortRM' function  --   | ==== __Examples__---   >>> robustsortRM [16, 23, 4, 8, 15, 42]+--   >>> robustsortRM ([16, 23, 4, 8, 15, 42] :: [Int]) --   [4,8,15,16,23,42]-robustsortRM :: [Bit] -> [Bit]-robustsortRM = wrapSortAlg Data.Tensort.Robustsort.robustsortRM+robustsortRM :: (Ord a) => [a] -> [a]+robustsortRM = Data.Tensort.Robustsort.robustsortRM
src/Data/Tensort.hs view
@@ -1,13 +1,11 @@--- | This module provides convenience functions that wraps common Tensort---   functions to sort lists of Bits without dealing with type conversion+-- | This module provides common Tensort functions defined without reference to+--   Bits module Data.Tensort   ( tensort,   ) where  import Data.Tensort.Tensort (tensortBL)-import Data.Tensort.Utils.Types (Bit)-import Data.Tensort.Utils.WrapSortAlg (wrapSortAlg)  -- | Takes a list of Bits and returns a sorted list of Bits using a Standard --   Logarithmic Tensort algorithm@@ -15,7 +13,7 @@ --   This is a convenience function that wraps the 'tensortBL' function  -- | ==== __Examples__---   >>> tensort [16, 23, 4, 8, 15, 42]+--   >>> tensort ([16, 23, 4, 8, 15, 42] :: [Int]) --   [4,8,15,16,23,42]-tensort :: [Bit] -> [Bit]-tensort = wrapSortAlg tensortBL+tensort :: (Ord a) => [a] -> [a]+tensort = tensortBL
src/Data/Tensort/OtherSorts/Mergesort.hs view
@@ -1,55 +1,36 @@--- | This module provides an implementation of the mergesort algorithm suitable---   for sorting lists using the Sortable type.+-- | This module provides an implementation of the mergesort algorithm. module Data.Tensort.OtherSorts.Mergesort (mergesort) where -import Data.Tensort.Utils.ComparisonFunctions (lessThanBit, lessThanRecord)-import Data.Tensort.Utils.Types (Bit, Record, Sortable (..))---- | Takes a Sortable and returns a sorted Sortable using a Mergesort+-- | Takes a list and returns a sorted list using a Mergesort --   algorithm.  -- | ==== __Examples__---  >>> mergesort (SortBit [16, 23, 4, 8, 15, 42])---  SortBit [4,8,15,16,23,42]+--  >>> mergesort ([16, 23, 4, 8, 15, 42] :: [Int])+--  [4,8,15,16,23,42] -----  >>> mergesort (SortRec [(1, 16), (5, 23), (2, 4) ,(3, 8), (0, 15) , (4, 42)])---  SortRec [(2,4),(3,8),(0,15),(1,16),(5,23),(4,42)]-mergesort :: Sortable -> Sortable-mergesort (SortBit xs) = SortBit (mergesortBits xs)-mergesort (SortRec xs) = SortRec (mergesortRecs xs)--mergesortBits :: [Bit] -> [Bit]-mergesortBits = mergeAllBits . map (: [])-  where-    mergeAllBits [] = []-    mergeAllBits [x] = x-    mergeAllBits [x, y] = mergeBits x y-    mergeAllBits remaningElements = mergeAllBits (mergePairs remaningElements)--    mergePairs (x : y : remaningElements) = mergeBits x y : mergePairs remaningElements-    mergePairs x = x--mergeBits :: [Bit] -> [Bit] -> [Bit]-mergeBits [] y = y-mergeBits x [] = x-mergeBits (x : xs) (y : ys)-  | lessThanBit x y = x : mergeBits xs (y : ys)-  | otherwise = y : mergeBits (x : xs) ys+--  >>> mergesort ([(1, 16), (5, 23), (2, 4) ,(3, 8), (0, 15) , (4, 42)] :: [(Int, Int)])+--  [(0,15),(1,16),(2,4),(3,8),(4,42),(5,23)]+mergesort :: (Ord a) => [a] -> [a]+mergesort = mergesortStack . map (: []) -mergesortRecs :: [Record] -> [Record]-mergesortRecs = mergeAllRecs . map (: [])-  where-    mergeAllRecs [] = []-    mergeAllRecs [x] = x-    mergeAllRecs [x, y] = mergeRecs x y-    mergeAllRecs remaningElements = mergeAllRecs (mergePairs remaningElements)+mergesortStack :: (Ord a) => [[a]] -> [a]+mergesortStack [] = []+mergesortStack [l] = l+mergesortStack [l1, l2] = mergeLists l1 l2+mergesortStack remaningElements =+  mergesortStack+    (mergePairsOfLists remaningElements) -    mergePairs (x : y : remaningElements) = mergeRecs x y : mergePairs remaningElements-    mergePairs x = x+mergePairsOfLists :: (Ord a) => [[a]] -> [[a]]+mergePairsOfLists [] = []+mergePairsOfLists [l1] = [l1]+mergePairsOfLists [l1, l2] = [mergeLists l1 l2]+mergePairsOfLists (l1 : l2 : remaningElements) =+  mergeLists l1 l2 : mergePairsOfLists remaningElements -mergeRecs :: [Record] -> [Record] -> [Record]-mergeRecs [] y = y-mergeRecs x [] = x-mergeRecs (x : xs) (y : ys)-  | lessThanRecord x y = x : mergeRecs xs (y : ys)-  | otherwise = y : mergeRecs (x : xs) ys+mergeLists :: (Ord a) => [a] -> [a] -> [a]+mergeLists [] y = y+mergeLists x [] = x+mergeLists (x : xs) (y : ys)+  | x < y = x : mergeLists xs (y : ys)+  | otherwise = y : mergeLists (x : xs) ys
src/Data/Tensort/OtherSorts/Quicksort.hs view
@@ -1,57 +1,34 @@ -- | This module provides an implementation of the quicksort algorithm suitable---   for sorting lists using the Sortable type.+--   for sorting lists. module Data.Tensort.OtherSorts.Quicksort (quicksort) where -import Data.Tensort.Utils.ComparisonFunctions (greaterThanBit, greaterThanRecord)-import Data.Tensort.Utils.Types (Bit, Record, Sortable (..))---- | Takes a Sortable and returns a sorted Sortable using a Quicksort+-- | Takes a list and returns a sorted list using a Quicksort --   algorithm.  -- | ==== __Examples__---  >>> quicksort (SortBit [16, 23, 4, 8, 15, 42])---  SortBit [4,8,15,16,23,42]+--  >>> quicksort ([16, 23, 4, 8, 15, 42] :: [Int])+--  [4,8,15,16,23,42] -----  >>> quicksort (SortRec [(1, 16), (5, 23), (2, 4) ,(3, 8), (0, 15) , (4, 42)])---  SortRec [(2,4),(3,8),(0,15),(1,16),(5,23),(4,42)]-quicksort :: Sortable -> Sortable-quicksort (SortBit []) = SortBit []-quicksort (SortBit [x]) = SortBit [x]-quicksort (SortBit xs) = SortBit (quicksortBits xs)-quicksort (SortRec []) = SortRec []-quicksort (SortRec [x]) = SortRec [x]-quicksort (SortRec xs) = SortRec (quicksortRecs xs)+--  >>> quicksort ([(1, 16), (5, 23), (2, 4) ,(3, 8), (0, 15) , (4, 42)] :: [(Int, Int)])+--  [(0,15),(1,16),(2,4),(3,8),(4,42),(5,23)]+quicksort :: (Ord a) => [a] -> [a]+quicksort [] = []+quicksort [x] = [x]+quicksort xs = quicksort' xs -quicksortBits :: [Bit] -> [Bit]-quicksortBits [] = []-quicksortBits [x] = [x]-quicksortBits xs =+quicksort' :: (Ord a) => [a] -> [a]+quicksort' [] = []+quicksort' [x] = [x]+quicksort' xs =   let (lower, pivot, upper) = getPartitionsBits xs-   in quicksortBits lower ++ [pivot] ++ quicksortBits upper+   in quicksort' lower ++ [pivot] ++ quicksort' upper -getPartitionsBits :: [Bit] -> ([Bit], Bit, [Bit])+getPartitionsBits :: (Ord a) => [a] -> ([a], a, [a]) getPartitionsBits [] = error "From getPartitionsBits: empty input list" getPartitionsBits [x] = ([], x, []) getPartitionsBits (x : xs) = foldr acc ([], x, []) xs   where-    acc :: Bit -> ([Bit], Bit, [Bit]) -> ([Bit], Bit, [Bit])-    acc y (lower, pivot, upper)-      | greaterThanBit y pivot = (lower, pivot, y : upper)-      | otherwise = (y : lower, pivot, upper)--quicksortRecs :: [Record] -> [Record]-quicksortRecs [] = []-quicksortRecs [x] = [x]-quicksortRecs xs =-  let (lower, pivot, upper) = getPartitionsRecs xs-   in quicksortRecs lower ++ [pivot] ++ quicksortRecs upper--getPartitionsRecs :: [Record] -> ([Record], Record, [Record])-getPartitionsRecs [] = error "From getPartitionsRecs: empty input list"-getPartitionsRecs [x] = ([], x, [])-getPartitionsRecs (x : xs) = foldr acc ([], x, []) xs-  where-    acc :: Record -> ([Record], Record, [Record]) -> ([Record], Record, [Record])+    acc :: (Ord a) => a -> ([a], a, [a]) -> ([a], a, [a])     acc y (lower, pivot, upper)-      | greaterThanRecord y pivot = (lower, pivot, y : upper)+      | y > pivot = (lower, pivot, y : upper)       | otherwise = (y : lower, pivot, upper)
src/Data/Tensort/Robustsort.hs view
@@ -1,5 +1,4 @@--- | This module provides variations of the Robustsort algorithm using the---   custom Sortable type for inputs and outputs+-- | This module provides variations of the Robustsort algorithm module Data.Tensort.Robustsort   ( robustsortP,     robustsortB,@@ -28,33 +27,33 @@ import Data.Tensort.Tensort (tensort) import Data.Tensort.Utils.LogNat (getLn, getLnBytesize) import Data.Tensort.Utils.MkTsProps (mkTsProps)-import Data.Tensort.Utils.Types (SortAlg, Sortable (..))+import Data.Tensort.Utils.Types (Bit, SortAlg) --- | Takes a Sortable and returns a sorted Sortable using a Recursive Mundane+-- | Takes a list and returns a sorted list using a Recursive Mundane --   Robustsort algorithm with a Permutationsort adjudicator  -- | ==== __Examples__---  >>> robustsortRP (SortBit [16, 23, 4, 8, 15, 42])---  SortBit [4,8,15,16,23,42]+--  >>> robustsortRP ([16, 23, 4, 8, 15, 42] :: [Int])+--  [4,8,15,16,23,42] -----  >>> robustsortRP (SortRec [(1, 16), (5, 23), (2, 4) ,(3, 8), (0, 15) , (4, 42)])---  SortRec [(2,4),(3,8),(0,15),(1,16),(5,23),(4,42)]-robustsortRP :: Sortable -> Sortable+--  >>> robustsortRP ([(1, 16), (5, 23), (2, 4) ,(3, 8), (0, 15) , (4, 42)] :: [(Int, Int)])+--  [(0,15),(1,16),(2,4),(3,8),(4,42),(5,23)]+robustsortRP :: (Ord a) => [Bit a] -> [Bit a] robustsortRP = robustsortRCustom robustsortP --- | Takes a Sortable and returns a sorted Sortable using a Basic Mundane+-- | Takes a list and returns a sorted list using a Basic Mundane --   Robustsort algorithm with a Permutationsort adjudicator  -- | ==== __Examples__--- >>> robustsortP (SortBit [16, 23, 4, 8, 15, 42])--- SortBit [4,8,15,16,23,42]+-- >>> robustsortP ([16, 23, 4, 8, 15, 42] :: [Int])+-- [4,8,15,16,23,42] ----- >>> robustsortP (SortRec [(1, 16), (5, 23), (2, 4) ,(3, 8), (0, 15) , (4, 42)])--- SortRec [(2,4),(3,8),(0,15),(1,16),(5,23),(4,42)]-robustsortP :: Sortable -> Sortable+-- >>> robustsortP ([(1, 16), (5, 23), (2, 4) ,(3, 8), (0, 15) , (4, 42)] :: [(Int, Int)])+-- [(0,15),(1,16),(2,4),(3,8),(4,42),(5,23)]+robustsortP :: (Ord a) => [Bit a] -> [Bit a] robustsortP = tensort (mkTsProps 3 supersortP) -supersortP :: Sortable -> Sortable+supersortP :: (Ord a) => [Bit a] -> [Bit a] supersortP =   supersort     ( rotationsortReverse,@@ -63,31 +62,31 @@       mundaneSuperStrat     ) --- | Takes a Sortable and returns a sorted Sortable using a Recursive Mundane+-- | Takes a list and returns a sorted list using a Recursive Mundane --   Robustsort algorithm with a Bogosort adjudicator  -- | ==== __Examples__--- >>> robustsortRB (SortBit [16, 23, 4, 8, 15, 42])--- SortBit [4,8,15,16,23,42]+-- >>> robustsortRB ([16, 23, 4, 8, 15, 42] :: [Int])+-- [4,8,15,16,23,42] ----- >>> robustsortRB (SortRec [(1, 16), (5, 23), (2, 4) ,(3, 8), (0, 15) , (4, 42)])--- SortRec [(2,4),(3,8),(0,15),(1,16),(5,23),(4,42)]-robustsortRB :: Sortable -> Sortable+-- >>> robustsortRB ([(1, 16), (5, 23), (2, 4) ,(3, 8), (0, 15) , (4, 42)] :: [(Int, Int)])+-- [(0,15),(1,16),(2,4),(3,8),(4,42),(5,23)]+robustsortRB :: (Ord a) => [Bit a] -> [Bit a] robustsortRB = robustsortRCustom robustsortB --- | Takes a Sortable and returns a sorted Sortable using a Basic Mundane+-- | Takes a list and returns a sorted list using a Basic Mundane --   Robustsort algorithm with a Bogosort adjudicator  -- | ==== __Examples__--- >>> robustsortB (SortBit [16, 23, 4, 8, 15, 42])--- SortBit [4,8,15,16,23,42]+-- >>> robustsortB ([16, 23, 4, 8, 15, 42] :: [Int])+-- [4,8,15,16,23,42] ----- >>> robustsortB (SortRec [(1, 16), (5, 23), (2, 4) ,(3, 8), (0, 15) , (4, 42)])--- SortRec [(2,4),(3,8),(0,15),(1,16),(5,23),(4,42)]-robustsortB :: Sortable -> Sortable+-- >>> robustsortB ([(1, 16), (5, 23), (2, 4) ,(3, 8), (0, 15) , (4, 42)] :: [(Int, Int)])+-- [(0,15),(1,16),(2,4),(3,8),(4,42),(5,23)]+robustsortB :: (Ord a) => [Bit a] -> [Bit a] robustsortB = tensort (mkTsProps 3 supersortB) -supersortB :: Sortable -> Sortable+supersortB :: (Ord a) => [Bit a] -> [Bit a] supersortB =   supersort     ( rotationsortReverse,@@ -96,31 +95,31 @@       mundaneSuperStrat     ) --- | Takes a Sortable and returns a sorted Sortable using a Recursive Magic+-- | Takes a list and returns a sorted list using a Recursive Magic --   Robustsort algorithm  -- | ==== __Examples__--- >>> robustsortRM (SortBit [16, 23, 4, 8, 15, 42])--- SortBit [4,8,15,16,23,42]+-- >>> robustsortRM ([16, 23, 4, 8, 15, 42] :: [Int])+-- [4,8,15,16,23,42] ----- >>> robustsortRM (SortRec [(1, 16), (5, 23), (2, 4) ,(3, 8), (0, 15) , (4, 42)])--- SortRec [(2,4),(3,8),(0,15),(1,16),(5,23),(4,42)]-robustsortRM :: Sortable -> Sortable+-- >>> robustsortRM ([(1, 16), (5, 23), (2, 4) ,(3, 8), (0, 15) , (4, 42)] :: [(Int, Int)])+-- [(0,15),(1,16),(2,4),(3,8),(4,42),(5,23)]+robustsortRM :: (Ord a) => [Bit a] -> [Bit a] robustsortRM = robustsortRCustom robustsortM --- | Takes a Sortable and returns a sorted Sortable using a Basic Magic+-- | Takes a list and returns a sorted list using a Basic Magic --   Robustsort algorithm  -- | ==== __Examples__--- >>> robustsortM (SortBit [16, 23, 4, 8, 15, 42])--- SortBit [4,8,15,16,23,42]+-- >>> robustsortM ([16, 23, 4, 8, 15, 42] :: [Int])+-- [4,8,15,16,23,42] ----- >>> robustsortM (SortRec [(1, 16), (5, 23), (2, 4) ,(3, 8), (0, 15) , (4, 42)])--- SortRec [(2,4),(3,8),(0,15),(1,16),(5,23),(4,42)]-robustsortM :: Sortable -> Sortable+-- >>> robustsortM ([(1, 16), (5, 23), (2, 4) ,(3, 8), (0, 15) , (4, 42)] :: [(Int, Int)])+-- [(0,15),(1,16),(2,4),(3,8),(4,42),(5,23)]+robustsortM :: (Ord a) => [Bit a] -> [Bit a] robustsortM = tensort (mkTsProps 3 supersortM) -supersortM :: Sortable -> Sortable+supersortM :: (Ord a) => [Bit a] -> [Bit a] supersortM =   supersort     ( rotationsortAmbi,@@ -131,8 +130,8 @@  -- | Used for making recursive Robustsort variants -----   Takes the base SortAlg you want to use and a Sortable and returns a sorted---   Sortable.+--   Takes the base SortAlg you want to use and a list and returns a sorted+--   list. -- --   Uses a Logarithmic bytesize to determine when to stop recursing and use --   the base SortAlg to sort the records.@@ -147,19 +146,17 @@ --   to experiment with weirder setups too! -- -- ==== __Examples__--- >>> robustsortRCustom robustsortB (SortBit [16, 23, 4, 8, 15, 42])--- SortBit [4,8,15,16,23,42]+-- >>> robustsortRCustom robustsortB ([16, 23, 4, 8, 15, 42] :: [Int])+-- [4,8,15,16,23,42] ----- >>> robustsortRCustom robustsortB (SortRec [(1, 16), (5, 23), (2, 4) ,(3, 8), (0, 15) , (4, 42)])--- SortRec [(2,4),(3,8),(0,15),(1,16),(5,23),(4,42)]-robustsortRCustom :: SortAlg -> Sortable -> Sortable-robustsortRCustom baseSortAlg xs =-  tensort-    ( mkTsProps-        (getLnBytesize xs)-        (robustsortRecursive (getLnBytesize xs) baseSortAlg)-    )-    xs+-- >>> robustsortRCustom robustsortB ([(1, 16), (5, 23), (2, 4) ,(3, 8), (0, 15) , (4, 42)] :: [(Int, Int)])+-- [(0,15),(1,16),(2,4),(3,8),(4,42),(5,23)]+robustsortRCustom :: (Ord a) => SortAlg (Bit a) -> [Bit a] -> [Bit a]+robustsortRCustom baseSortAlg xs = tensort tsProps xs+  where+    tsProps = mkTsProps bytesize subAlg+    bytesize = getLnBytesize xs+    subAlg = robustsortRecursive bytesize baseSortAlg  -- | Used to create SubAlgorithms for use in recursive Robustsort variants. See --   also `robustsortRCustom`.@@ -168,7 +165,7 @@ --   approximates the natural logarithm of the length of the input list until --   the Bytesize is less than or equal to 27. At this point, the baseSortAlg --   is used to sort the records.-robustsortRecursive :: Int -> SortAlg -> SortAlg+robustsortRecursive :: (Ord a) => Int -> SortAlg (Bit a) -> SortAlg (Bit a) robustsortRecursive bytesize baseSortAlg   -- ln (532048240602) ~= 27   -- ln (27) ~= 3@@ -178,9 +175,8 @@   -- will use the baseSortAlg (such as the basic version of Robustsort with   -- bytesize of 3 used in this module) to sort its records.   | bytesize <= 27 = baseSortAlg-  | otherwise =-      tensort-        ( mkTsProps-            (getLn bytesize)-            (robustsortRecursive (getLn bytesize) baseSortAlg)-        )+  | otherwise = tensort tsProps+  where+    tsProps = mkTsProps bytesize' baseSortAlg'+    bytesize' = getLn bytesize+    baseSortAlg' = robustsortRecursive bytesize' baseSortAlg
src/Data/Tensort/Subalgorithms/Bogosort.hs view
@@ -1,31 +1,30 @@--- | This module provides the bogosort function for sorting Sortable lists+-- | This module provides the bogosort function for sorting lists module Data.Tensort.Subalgorithms.Bogosort (bogosort, bogosortSeeded) where  import Data.Tensort.Utils.Check (isSorted) import Data.Tensort.Utils.RandomizeList (randomizeList)-import Data.Tensort.Utils.Types (Sortable (..)) --- | Takes a Sortable and returns a sorted Sortable using a Bogosort algorithm.+-- | Takes a list and returns a sorted list using a Bogosort algorithm.  -- | ==== __Examples__--- >>> bogosort (SortBit [16, 23, 4, 8, 15, 42])--- SortBit [4,8,15,16,23,42]+-- >>> bogosort ([16, 23, 4, 8, 15, 42] :: [Int])+-- [4,8,15,16,23,42] ----- >>> bogosort (SortRec [(1, 16), (5, 23), (2, 4), (3, 8), (0, 15), (4, 42)])--- SortRec [(2,4),(3,8),(0,15),(1,16),(5,23),(4,42)]-bogosort :: Sortable -> Sortable+-- >>> bogosort ([(1, 16), (5, 23), (2, 4), (3, 8), (0, 15), (4, 42)] :: [(Int, Int)])+-- [(0,15),(1,16),(2,4),(3,8),(4,42),(5,23)]+bogosort :: (Ord a) => [a] -> [a] bogosort = bogosortSeeded 143 --- | Takes a seed for use in random generation and a Sortable and returns a---  sorted Sortable using a Bogosort algorithm.+-- | Takes a seed for use in random generation and a list and returns a+--  sorted list using a Bogosort algorithm.  -- | ==== __Examples__--- >>> bogosortSeeded 42 (SortBit [16, 23, 4, 8, 15, 42])--- SortBit [4,8,15,16,23,42]+-- >>> bogosortSeeded 42 ([16, 23, 4, 8, 15, 42] :: [Int])+-- [4,8,15,16,23,42] ----- >>> bogosortSeeded 24 (SortRec [(1, 16), (5, 23), (2, 4), (3, 8), (0, 15), (4, 42)])--- SortRec [(2,4),(3,8),(0,15),(1,16),(5,23),(4,42)]-bogosortSeeded :: Int -> Sortable -> Sortable+-- >>> bogosortSeeded 24 ([(1, 16), (5, 23), (2, 4), (3, 8), (0, 15), (4, 42)] :: [(Int, Int)])+-- [(0,15),(1,16),(2,4),(3,8),(4,42),(5,23)]+bogosortSeeded :: (Ord a) => Int -> [a] -> [a] bogosortSeeded seed xs   | isSorted xs = xs   | otherwise = bogosortSeeded (seed + 1) (randomizeList seed xs)
src/Data/Tensort/Subalgorithms/Bubblesort.hs view
@@ -1,45 +1,34 @@--- | This module provides the bubblesort function for sorting Sortable lists+-- | This module provides the bubblesort function for sorting Bit lists module Data.Tensort.Subalgorithms.Bubblesort (bubblesort) where -import Data.Tensort.Utils.ComparisonFunctions-  ( greaterThanBit,-    greaterThanRecord,-  )-import Data.Tensort.Utils.Types (Sortable (..))---- | Takes a Sortable and returns a sorted Sortable using a Bubblesort+-- | Takes a Bit and returns a sorted Bit using a Bubblesort --   algorithm.  -- | ==== __Examples__--- >>> bubblesort (SortBit [16, 23, 4, 8, 15, 42])--- SortBit [4,8,15,16,23,42]+-- >>> bubblesort ([16, 23, 4, 8, 15, 42] :: [Int])+-- [4,8,15,16,23,42] ----- >>> bubblesort (SortRec [(1, 16), (5, 23), (2, 4), (3, 8), (0, 15), (4, 42)])--- SortRec [(2,4),(3,8),(0,15),(1,16),(5,23),(4,42)]-bubblesort :: Sortable -> Sortable-bubblesort (SortBit bits) =-  SortBit-    ( bublesortIterable greaterThanBit bits 0 (length bits)-    )-bubblesort (SortRec recs) =-  SortRec-    ( bublesortIterable greaterThanRecord recs 0 (length recs)-    )+-- >>> bubblesort ([(1, 16), (5, 23), (2, 4), (3, 8), (0, 15), (4, 42)] :: [(Int, Int)])+-- [(0,15),(1,16),(2,4),(3,8),(4,42),(5,23)]+bubblesort :: (Ord a) => [a] -> [a]+bubblesort bits =+  bubblesort' bits 0 (length bits) -bublesortIterable :: (Ord a) => (a -> a -> Bool) -> [a] -> Int -> Int -> [a]-bublesortIterable greaterThan xs currentIndex i+bubblesort' :: (Ord a) => [a] -> Int -> Int -> [a]+bubblesort' xs currentIndex i   | length xs < 2 = xs   | i < 1 =       xs   | currentIndex > length xs - 2 =-      bublesortIterable greaterThan xs 0 (i - 1)+      bubblesort' xs 0 (i - 1)   | otherwise =-      let left = take currentIndex xs-          right = drop (currentIndex + 2) xs-          x = xs !! currentIndex-          y = xs !! (currentIndex + 1)-          leftElemGreater = greaterThan x y-          swappedXs = left ++ [y] ++ [x] ++ right-       in if leftElemGreater-            then bublesortIterable greaterThan swappedXs (currentIndex + 1) i-            else bublesortIterable greaterThan xs (currentIndex + 1) i+      if leftElemGreater+        then bubblesort' swappedXs (currentIndex + 1) i+        else bubblesort' xs (currentIndex + 1) i+  where+    left = take currentIndex xs+    right = drop (currentIndex + 2) xs+    x = xs !! currentIndex+    y = xs !! (currentIndex + 1)+    leftElemGreater = x > y+    swappedXs = left ++ [y] ++ [x] ++ right
src/Data/Tensort/Subalgorithms/Exchangesort.hs view
@@ -1,40 +1,37 @@--- | This module provides the bubblesort function for sorting Sortable lists+-- | This module provides the exchangesort function for sorting lists module Data.Tensort.Subalgorithms.Exchangesort (exchangesort) where -import Data.Tensort.Utils.ComparisonFunctions (greaterThanBit, greaterThanRecord)-import Data.Tensort.Utils.Types (Sortable (..))---- | Takes a Sortable and returns a sorted Sortable using an Exchangesort+-- | Takes a list and returns a sorted list using an Exchangesort --   algorithm.  -- | ==== __Examples__--- >>> exchangesort (SortBit [16, 23, 4, 8, 15, 42])--- SortBit [4,8,15,16,23,42]+-- >>> exchangesort ([16, 23, 4, 8, 15, 42] :: [Int])+-- [4,8,15,16,23,42] ----- >>> exchangesort (SortRec [(1, 16), (5, 23), (2, 4) ,(3, 8), (0, 15) , (4, 42)])--- SortRec [(2,4),(3,8),(0,15),(1,16),(5,23),(4,42)]-exchangesort :: Sortable -> Sortable-exchangesort (SortBit bits) = SortBit (exchangesortIterable greaterThanBit bits 0 (length bits - 1))-exchangesort (SortRec recs) = SortRec (exchangesortIterable greaterThanRecord recs 0 (length recs - 1))+-- >>> exchangesort ([(1, 16), (5, 23), (2, 4) ,(3, 8), (0, 15) , (4, 42)] :: [(Int, Int)])+-- [(0,15),(1,16),(2,4),(3,8),(4,42),(5,23)]+exchangesort :: (Ord a) => [a] -> [a]+exchangesort bits = exchangesort' bits 0 (length bits - 1) -exchangesortIterable :: (Ord a) => (a -> a -> Bool) -> [a] -> Int -> Int -> [a]-exchangesortIterable greaterThan xs i j+exchangesort' :: (Ord a) => [a] -> Int -> Int -> [a]+exchangesort' xs i j   | i > length xs - 1 =       xs   | j < 0 =-      exchangesortIterable greaterThan xs (i + 1) (length xs - 1)+      exchangesort' xs (i + 1) (length xs - 1)   | i == j =-      exchangesortIterable greaterThan xs i (j - 1)+      exchangesort' xs i (j - 1)   | otherwise =-      let mini = min i j-          maxi = max i j-          left = take mini xs-          middle = take (maxi - mini - 1) (drop (mini + 1) xs)-          right = drop (maxi + 1) xs-          x = xs !! mini-          y = xs !! maxi-          leftElemGreater = greaterThan x y-          swappedXs = left ++ [y] ++ middle ++ [x] ++ right-       in if leftElemGreater-            then exchangesortIterable greaterThan swappedXs i (j - 1)-            else exchangesortIterable greaterThan xs i (j - 1)+      if leftElemGreater+        then exchangesort' swappedXs i (j - 1)+        else exchangesort' xs i (j - 1)+  where+    mini = min i j+    maxi = max i j+    left = take mini xs+    middle = take (maxi - mini - 1) (drop (mini + 1) xs)+    right = drop (maxi + 1) xs+    x = xs !! mini+    y = xs !! maxi+    leftElemGreater = x > y+    swappedXs = left ++ [y] ++ middle ++ [x] ++ right
src/Data/Tensort/Subalgorithms/Magicsort.hs view
@@ -1,4 +1,4 @@--- | This module provides the magicsort function for sorting Sortable lists+-- | This module provides the magicsort function for sorting lists module Data.Tensort.Subalgorithms.Magicsort   ( magicsort,   )@@ -6,30 +6,24 @@  import Data.Tensort.Subalgorithms.Bogosort (bogosort) import Data.Tensort.Subalgorithms.Permutationsort (permutationsort)-import Data.Tensort.Utils.Types (Sortable (..)) --- | Takes a Sortable and returns a sorted Sortable.+-- | Takes a list and returns a sorted list. -----   Runs both Permutationsort and Bogosort on the input Sortable and compares+--   Runs both Permutationsort and Bogosort on the input list and compares --   the results. If the results agree, returns the result of Permutationsort, --   otherwise repeats the process.  -- | ==== __Examples__--- >>> magicsort (SortBit [16, 23, 4, 8, 15, 42])--- SortBit [4,8,15,16,23,42]+-- >>> magicsort ([16, 23, 4, 8, 15, 42] :: [Int])+-- [4,8,15,16,23,42] ----- >>> magicsort (SortRec [(1, 16), (5, 23), (2, 4) ,(3, 8), (0, 15), (4, 42)])--- SortRec [(2,4),(3,8),(0,15),(1,16),(5,23),(4,42)]-magicsort :: Sortable -> Sortable-magicsort xs = do-  let result1 = permutationsort xs-  let result2 = bogosort xs-  if verifyResults result1 result2+-- >>> magicsort ([(1, 16), (5, 23), (2, 4) ,(3, 8), (0, 15), (4, 42)] :: [(Int, Int)])+-- [(0,15),(1,16),(2,4),(3,8),(4,42),(5,23)]+magicsort :: (Ord a) => [a] -> [a]+magicsort xs =+  if result1 == result2     then result1     else magicsort xs--verifyResults :: Sortable -> Sortable -> Bool-verifyResults (SortBit xs) (SortBit ys) = xs == ys-verifyResults (SortRec xs) (SortRec ys) = map snd xs == map snd ys-verifyResults (SortBit _) (SortRec _) = False-verifyResults (SortRec _) (SortBit _) = False+  where+    result1 = permutationsort xs+    result2 = bogosort xs
src/Data/Tensort/Subalgorithms/Permutationsort.hs view
@@ -1,42 +1,23 @@--- | This module provides the permutationsort function for sorting Sortable---   lists+-- | This module provides the permutationsort function for sorting lists module Data.Tensort.Subalgorithms.Permutationsort (permutationsort) where  import Data.List (permutations) import Data.Tensort.Utils.Check (isSorted)-import Data.Tensort.Utils.Types-  ( Bit,-    Record,-    Sortable (..),-    fromSortBit,-    fromSortRec,-  ) --- | Takes a Sortable and returns a sorted Sortable using Permutationsort---   algorithm+-- | Takes a list and returns a sorted list using Permutationsort algorithm  -- | ==== __Examples__--- >>> permutationsort (SortBit [16, 23, 4, 8, 15, 42])--- SortBit [4,8,15,16,23,42]+-- >>> permutationsort ([16, 23, 4, 8, 15, 42] :: [Int])+-- [4,8,15,16,23,42] ----- >>> permutationsort (SortRec [(1, 16), (5, 23), (2, 4) ,(3, 8), (0, 15) , (4, 42)])--- SortRec [(2,4),(3,8),(0,15),(1,16),(5,23),(4,42)]-permutationsort :: Sortable -> Sortable-permutationsort (SortBit xs) = SortBit (acc (permutations x) [])-  where-    x = xs-    acc :: [[Bit]] -> [Bit] -> [Bit]-    acc [] unsortedPermutations =-      fromSortBit (permutationsort (SortBit unsortedPermutations))-    acc (permutation : remainingPermutations) unsortedPermutations-      | isSorted (SortBit permutation) = permutation-      | otherwise = acc remainingPermutations unsortedPermutations-permutationsort (SortRec xs) = SortRec (acc (permutations x) [])+-- >>> permutationsort ([(1, 16), (5, 23), (2, 4) ,(3, 8), (0, 15) , (4, 42)] :: [(Int, Int)])+-- [(0,15),(1,16),(2,4),(3,8),(4,42),(5,23)]+permutationsort :: (Ord a) => [a] -> [a]+permutationsort xs = acc (permutations xs) []   where-    x = xs-    acc :: [[Record]] -> [Record] -> [Record]+    acc :: (Ord a) => [[a]] -> [a] -> [a]     acc [] unsortedPermutations =-      fromSortRec (permutationsort (SortRec unsortedPermutations))+      permutationsort unsortedPermutations     acc (permutation : remainingPermutations) unsortedPermutations-      | isSorted (SortRec permutation) = permutation+      | isSorted permutation = permutation       | otherwise = acc remainingPermutations unsortedPermutations
src/Data/Tensort/Subalgorithms/Rotationsort.hs view
@@ -1,4 +1,4 @@--- | This module provides Rotationsort variants for sorting Sortable lists.+-- | This module provides Rotationsort variants for sorting lists. -- -- | I was having some issues with the swaps for larger input lists, so for now --   these functions are only implemented for lists of length 3 or less.@@ -10,323 +10,202 @@   ) where -import Data.Tensort.Utils.ComparisonFunctions-  ( greaterThanOrEqualBit,-    greaterThanOrEqualRecord,-  )-import Data.Tensort.Utils.Types (Sortable (..))---- | Takes a Sortable and returns a sorted Sortable using a Rotationsort+-- | Takes a list and returns a sorted list using a Rotationsort --  algorithm. -- --  I was having some issues with the swaps for larger input lists, so for now --  this function is only implemented for lists of length 3 or less.  -- | ==== __Examples__--- >>> rotationsort (SortBit [1,3,2])--- SortBit [1,2,3]+-- >>> rotationsort ([1,3,2] :: [Int])+-- [1,2,3] ----- >>> rotationsort (SortRec [(3, 1), (1, 3), (2, 2)])--- SortRec [(3,1),(2,2),(1,3)]-rotationsort :: Sortable -> Sortable-rotationsort (SortBit bits) =-  let result =-        rotationsortIterable greaterThanOrEqualBit bits 0 False False-   in SortBit result-rotationsort (SortRec recs) =-  let result =-        rotationsortIterable greaterThanOrEqualRecord recs 0 False False-   in SortRec result+-- >>> rotationsort ([(3, 1), (1, 3), (2, 2)] :: [(Int, Int)])+-- [(1,3),(2,2),(3,1)]+rotationsort :: (Ord a) => [a] -> [a]+rotationsort bits = rotationsort' bits 0 False False --- | Takes a Sortable and returns a sorted Sortable using an Ambidextrous+-- | Takes a list and returns a sorted list using an Ambidextrous --   Rotationsort algorithm. -- --  I was having some issues with the swaps for larger input lists, so for now --  this function is only implemented for lists of length 3 or less.  -- | ==== __Examples__--- >>> rotationsortAmbi (SortBit [1,3,2])--- SortBit [1,2,3]+-- >>> rotationsortAmbi ([1,3,2] :: [Int])+-- [1,2,3] ----- >>> rotationsortAmbi (SortRec [(3, 1), (1, 3), (2, 2)])--- SortRec [(3,1),(2,2),(1,3)]-rotationsortAmbi :: Sortable -> Sortable-rotationsortAmbi (SortBit bits) =-  let result =-        rotationsortIterable greaterThanOrEqualBit bits 0 True False-   in SortBit result-rotationsortAmbi (SortRec recs) =-  let result =-        rotationsortIterable greaterThanOrEqualRecord recs 0 True False-   in SortRec result+-- >>> rotationsortAmbi ([(3, 1), (1, 3), (2, 2)] :: [(Int, Int)])+-- [(1,3),(2,2),(3,1)]+rotationsortAmbi :: (Ord a) => [a] -> [a]+rotationsortAmbi bits = rotationsort' bits 0 True False --- | Takes a Sortable and returns a sorted Sortable using a Reverse+-- | Takes a list and returns a sorted list using a Reverse --   Rotationsort algorithm. -- --   I was having some issues with the swaps for larger input lists, so for now --   this function is only implemented for lists of length 3 or less.  -- | ==== __Examples__--- >>> rotationsortReverse (SortBit [1,3,2])--- SortBit [1,2,3]+-- >>> rotationsortReverse ([1,3,2] :: [Int])+-- [1,2,3] ----- >>> rotationsortReverse (SortRec [(3, 1), (1, 3), (2, 2)])--- SortRec [(3,1),(2,2),(1,3)]-rotationsortReverse :: Sortable -> Sortable-rotationsortReverse (SortBit bits) =-  let result =-        rotationsortIterable-          greaterThanOrEqualBit-          bits-          (length bits - 1)-          False-          True-   in SortBit result-rotationsortReverse (SortRec recs) =-  let result =-        rotationsortIterable-          greaterThanOrEqualRecord-          recs-          (length recs - 1)-          False-          True-   in SortRec result+-- >>> rotationsortReverse ([(3, 1), (1, 3), (2, 2)] :: [(Int, Int)])+-- [(1,3),(2,2),(3,1)]+rotationsortReverse :: (Ord a) => [a] -> [a]+rotationsortReverse bits = rotationsort' bits (length bits - 1) False True --- | Takes a Sortable and returns a sorted Sortable using an Ambidextrous+-- | Takes a list and returns a sorted list using an Ambidextrous --   Reverse Rotationsort algorithm. -- --   I was having some issues with the swaps for larger input lists, so for now --   this function is only implemented for lists of length 3 or less.  -- | ==== __Examples__--- >>> rotationsortReverseAmbi (SortBit [1,3,2])--- SortBit [1,2,3]+-- >>> rotationsortReverseAmbi ([1,3,2] :: [Int])+-- [1,2,3] ----- >>> rotationsortReverseAmbi (SortRec [(3, 1), (1, 3), (2, 2)])--- SortRec [(3,1),(2,2),(1,3)]-rotationsortReverseAmbi :: Sortable -> Sortable-rotationsortReverseAmbi (SortBit bits) =-  let result =-        rotationsortIterable-          greaterThanOrEqualBit-          bits-          (length bits - 1)-          True-          True-   in SortBit result-rotationsortReverseAmbi (SortRec recs) =-  let result =-        rotationsortIterable-          greaterThanOrEqualRecord-          recs-          (length recs - 1)-          True-          True-   in SortRec result+-- >>> rotationsortReverseAmbi ([(3, 1), (1, 3), (2, 2)] :: [(Int, Int)])+-- [(1,3),(2,2),(3,1)]+rotationsortReverseAmbi :: (Ord a) => [a] -> [a]+rotationsortReverseAmbi bits = rotationsort' bits (length bits - 1) True True -rotationsortIterable ::-  (Ord a) =>-  (a -> a -> Bool) ->-  [a] ->-  Int ->-  Bool ->-  Bool ->-  [a]-rotationsortIterable greaterThanOrEqual xs currentIndex isAmbi isReverse+rotationsort' :: (Ord a) => [a] -> Int -> Bool -> Bool -> [a]+rotationsort' xs currentIndex isAmbi isReverse   | length xs > 3 =       error-        "From rotationsortIterable: algorithm not yet implemented for lists of length greater than 3"+        "From rotationsort': algorithm not yet implemented for lists of length greater than 3"   | currentIndex < 0 || currentIndex >= length xs =       xs   | length xs < 2 = xs   | length xs == 2 =-      rotatationsortPair greaterThanOrEqual xs currentIndex isAmbi isReverse+      rotatationsortPair xs currentIndex isAmbi isReverse   | currentIndex == firstIndex (length xs) isReverse =-      rotationsortHead greaterThanOrEqual xs currentIndex isAmbi isReverse+      rotationsortHead xs currentIndex isAmbi isReverse   | currentIndex == lastIndex (length xs) isReverse =-      rotationsortLast greaterThanOrEqual xs currentIndex isAmbi isReverse+      rotationsortLast xs currentIndex isAmbi isReverse   | otherwise =-      rotationsortMiddle greaterThanOrEqual xs currentIndex isAmbi isReverse+      rotationsortMiddle xs currentIndex isAmbi isReverse -rotatationsortPair ::-  (Ord a) =>-  (a -> a -> Bool) ->-  [a] ->-  Int ->-  Bool ->-  Bool ->-  [a]-rotatationsortPair greaterThanOrEqual xs currentIndex isAmbi isReverse =-  let x = head xs-      y = xs !! 1-      secondElemGreater = greaterThanOrEqual y x-      swappedXs = y : [x]-   in switch secondElemGreater swappedXs+rotatationsortPair :: (Ord a) => [a] -> Int -> Bool -> Bool -> [a]+rotatationsortPair xs currentIndex isAmbi isReverse+  | not secondElemGreater =+      rotationsort'+        swappedXs+        (firstIndex (length xs) isReverse)+        isAmbi+        isReverse+  | otherwise =+      rotationsort'+        xs+        (nextIndex currentIndex isReverse)+        isAmbi+        isReverse   where-    switch secondElemGreater swappedXs-      | not secondElemGreater =-          rotationsortIterable-            greaterThanOrEqual-            swappedXs-            (firstIndex (length xs) isReverse)-            isAmbi-            isReverse-      | otherwise =-          rotationsortIterable-            greaterThanOrEqual-            xs-            (nextIndex currentIndex isReverse)-            isAmbi-            isReverse+    x = head xs+    y = xs !! 1+    secondElemGreater = y >= x+    swappedXs = y : [x] -rotationsortHead ::-  (Ord a) =>-  (a -> a -> Bool) ->-  [a] ->-  Int ->-  Bool ->-  Bool ->-  [a]-rotationsortHead greaterThanOrEqual xs currentIndex isAmbi isReverse =-  let w = xs !! lastIndex (length xs) isReverse-      x = xs !! currentIndex-      y = xs !! nextIndex currentIndex isReverse-      rotateToFirst =-        if isReverse then [y] ++ [x] ++ [w] else [w] ++ [x] ++ [y]-      rotateBackward =-        if isReverse then [w] ++ [x] ++ [y] else [y] ++ [x] ++ [w]-   in switch+rotationsortHead :: (Ord a) => [a] -> Int -> Bool -> Bool -> [a]+rotationsortHead xs currentIndex isAmbi isReverse+  | not $ lastElemOrdered xs currentIndex isReverse =+      rotationsort'         rotateToFirst+        (firstIndex (length xs) isReverse)+        isAmbi+        isReverse+  | not $ nextElemOrdered xs currentIndex isReverse =+      rotationsort'         rotateBackward+        (firstIndex (length xs) isReverse)+        isAmbi+        isReverse+  | otherwise =+      rotationsort'+        xs+        (nextIndex currentIndex isReverse)+        isAmbi+        isReverse   where-    switch-      rotateToFirst-      rotateBackward-        | not (lastElemOrdered greaterThanOrEqual xs currentIndex isReverse) =-            rotationsortIterable-              greaterThanOrEqual-              rotateToFirst-              (firstIndex (length xs) isReverse)-              isAmbi-              isReverse-        | not (nextElemOrdered greaterThanOrEqual xs currentIndex isReverse) =-            rotationsortIterable-              greaterThanOrEqual-              rotateBackward-              (firstIndex (length xs) isReverse)-              isAmbi-              isReverse-        | otherwise =-            rotationsortIterable-              greaterThanOrEqual-              xs-              (nextIndex currentIndex isReverse)-              isAmbi-              isReverse+    w = xs !! lastIndex (length xs) isReverse+    x = xs !! currentIndex+    y = xs !! nextIndex currentIndex isReverse+    rotateToFirst =+      if isReverse then [y] ++ [x] ++ [w] else [w] ++ [x] ++ [y]+    rotateBackward =+      if isReverse then [w] ++ [x] ++ [y] else [y] ++ [x] ++ [w] -rotationsortMiddle ::-  (Ord a) =>-  (a -> a -> Bool) ->-  [a] ->-  Int ->-  Bool ->-  Bool ->-  [a]-rotationsortMiddle greaterThanOrEqual xs currentIndex isAmbi isReverse =-  let w = xs !! prevIndex currentIndex isReverse-      x = xs !! currentIndex-      y = xs !! nextIndex currentIndex isReverse-      rotateBackward =-        if isReverse then [x] ++ [y] ++ [w] else [y] ++ [w] ++ [x]-      rotateForward =-        if isReverse then [y] ++ [w] ++ [x] else [x] ++ [y] ++ [w]-   in switch+rotationsortMiddle :: (Ord a) => [a] -> Int -> Bool -> Bool -> [a]+rotationsortMiddle xs currentIndex isAmbi isReverse+  | not $ nextElemOrdered xs currentIndex isReverse =+      rotationsort'         rotateBackward+        (firstIndex (length xs) isReverse)+        isAmbi+        isReverse+  | not isAmbi =+      rotationsort'+        xs+        (nextIndex currentIndex isReverse)+        isAmbi+        isReverse+  | not $ prevElemOrdered xs currentIndex isReverse =+      rotationsort'         rotateForward+        (prevIndex currentIndex isReverse)+        isAmbi+        isReverse+  | otherwise =+      rotationsort'+        xs+        (nextIndex currentIndex isReverse)+        isAmbi+        isReverse   where-    switch-      rotateBackward-      rotateForward-        | not (nextElemOrdered greaterThanOrEqual xs currentIndex isReverse) =-            rotationsortIterable-              greaterThanOrEqual-              rotateBackward-              (firstIndex (length xs) isReverse)-              isAmbi-              isReverse-        | not isAmbi =-            rotationsortIterable-              greaterThanOrEqual-              xs-              (nextIndex currentIndex isReverse)-              isAmbi-              isReverse-        | not (prevElemOrdered greaterThanOrEqual xs currentIndex isReverse) =-            rotationsortIterable-              greaterThanOrEqual-              rotateForward-              (prevIndex currentIndex isReverse)-              isAmbi-              isReverse-        | otherwise =-            rotationsortIterable-              greaterThanOrEqual-              xs-              (nextIndex currentIndex isReverse)-              isAmbi-              isReverse+    w = xs !! prevIndex currentIndex isReverse+    x = xs !! currentIndex+    y = xs !! nextIndex currentIndex isReverse+    rotateBackward =+      if isReverse then [x] ++ [y] ++ [w] else [y] ++ [w] ++ [x]+    rotateForward =+      if isReverse then [y] ++ [w] ++ [x] else [x] ++ [y] ++ [w]  rotationsortLast ::-  (Ord a) =>-  (a -> a -> Bool) ->-  [a] ->-  Int ->-  Bool ->-  Bool ->-  [a]-rotationsortLast greaterThanOrEqual xs currentIndex isAmbi isReverse =-  let w = xs !! prevIndex currentIndex isReverse-      x = xs !! currentIndex-      y = xs !! firstIndex (length xs) isReverse-      rotateForward =-        if isReverse then [w] ++ [x] ++ [y] else [y] ++ [x] ++ [w]-      rotateToLast =-        if isReverse then [y] ++ [x] ++ [w] else [w] ++ [x] ++ [y]-   in switch-        rotateForward+  (Ord a) => [a] -> Int -> Bool -> Bool -> [a]+rotationsortLast xs currentIndex isAmbi isReverse+  | not isAmbi =+      rotationsort'+        xs+        (nextIndex currentIndex isReverse)+        isAmbi+        isReverse+  | not $ firstElemOrdered xs currentIndex isReverse =+      rotationsort'         rotateToLast+        (prevIndex currentIndex isReverse)+        isAmbi+        isReverse+  | not $ prevElemOrdered xs currentIndex isReverse =+      rotationsort'+        rotateForward+        (prevIndex currentIndex isReverse)+        isAmbi+        isReverse+  | otherwise =+      rotationsort'+        xs+        (nextIndex currentIndex isReverse)+        isAmbi+        isReverse   where-    switch-      rotateForward-      rotateToLast-        | not isAmbi =-            rotationsortIterable-              greaterThanOrEqual-              xs-              (nextIndex currentIndex isReverse)-              isAmbi-              isReverse-        | not (firstElemOrdered greaterThanOrEqual xs currentIndex isReverse) =-            rotationsortIterable-              greaterThanOrEqual-              rotateToLast-              (prevIndex currentIndex isReverse)-              isAmbi-              isReverse-        | not (prevElemOrdered greaterThanOrEqual xs currentIndex isReverse) =-            rotationsortIterable-              greaterThanOrEqual-              rotateForward-              (prevIndex currentIndex isReverse)-              isAmbi-              isReverse-        | otherwise =-            rotationsortIterable-              greaterThanOrEqual-              xs-              (nextIndex currentIndex isReverse)-              isAmbi-              isReverse+    w = xs !! prevIndex currentIndex isReverse+    x = xs !! currentIndex+    y = xs !! firstIndex (length xs) isReverse+    rotateForward =+      if isReverse then [w] ++ [x] ++ [y] else [y] ++ [x] ++ [w]+    rotateToLast =+      if isReverse then [y] ++ [x] ++ [w] else [w] ++ [x] ++ [y]  nextIndex :: Int -> Bool -> Int nextIndex currentIndex isReverse@@ -348,26 +227,26 @@   | isReverse = listLength - 1   | otherwise = 0 -nextElemOrdered :: (Ord a) => (a -> a -> Bool) -> [a] -> Int -> Bool -> Bool-nextElemOrdered greaterThanOrEqual xs currentIndex isReverse =-  let x = xs !! currentIndex-      y = xs !! nextIndex currentIndex isReverse-   in if isReverse then greaterThanOrEqual x y else greaterThanOrEqual y x+nextElemOrdered :: (Ord a) => [a] -> Int -> Bool -> Bool+nextElemOrdered xs currentIndex isReverse = if isReverse then x >= y else y >= x+  where+    x = xs !! currentIndex+    y = xs !! nextIndex currentIndex isReverse -prevElemOrdered :: (Ord a) => (a -> a -> Bool) -> [a] -> Int -> Bool -> Bool-prevElemOrdered greaterThanOrEqual xs currentIndex isReverse =-  let x = xs !! currentIndex-      w = xs !! prevIndex currentIndex isReverse-   in if isReverse then greaterThanOrEqual w x else greaterThanOrEqual x w+prevElemOrdered :: (Ord a) => [a] -> Int -> Bool -> Bool+prevElemOrdered xs currentIndex isReverse = if isReverse then w >= x else x >= w+  where+    x = xs !! currentIndex+    w = xs !! prevIndex currentIndex isReverse -firstElemOrdered :: (Ord a) => (a -> a -> Bool) -> [a] -> Int -> Bool -> Bool-firstElemOrdered greaterThanOrEqual xs currentIndex isReverse =-  let x = xs !! currentIndex-      w = xs !! firstIndex (length xs) isReverse-   in if isReverse then greaterThanOrEqual w x else greaterThanOrEqual x w+firstElemOrdered :: (Ord a) => [a] -> Int -> Bool -> Bool+firstElemOrdered xs currentIndex isReverse = if isReverse then w >= x else x >= w+  where+    x = xs !! currentIndex+    w = xs !! firstIndex (length xs) isReverse -lastElemOrdered :: (Ord a) => (a -> a -> Bool) -> [a] -> Int -> Bool -> Bool-lastElemOrdered greaterThanOrEqual xs currentIndex isReverse =-  let x = xs !! currentIndex-      y = xs !! lastIndex (length xs) isReverse-   in if isReverse then greaterThanOrEqual x y else greaterThanOrEqual y x+lastElemOrdered :: (Ord a) => [a] -> Int -> Bool -> Bool+lastElemOrdered xs currentIndex isReverse = if isReverse then x >= y else y >= x+  where+    x = xs !! currentIndex+    y = xs !! lastIndex (length xs) isReverse
src/Data/Tensort/Subalgorithms/Supersort.hs view
@@ -7,11 +7,7 @@   ) where -import Data.Tensort.Utils.Types-  ( SortAlg,-    Sortable (..),-    SupersortStrat,-  )+import Data.Tensort.Utils.Types (SortAlg, SupersortStrat)  -- | Used for creating a Supersort algorithm that adjudicates between 3 sorting --   algorithms.@@ -25,21 +21,23 @@ -- >>> import Data.Tensort.Subalgorithms.Permutationsort (permutationsort) -- >>> import Data.Tensort.OtherSorts.Mergesort (mergesort) ----- >>> supersort (mergesort, bubblesort, permutationsort, mundaneSuperStrat) (SortBit [16, 23, 4, 8, 15, 42])--- SortBit [4,8,15,16,23,42]+-- >>> supersort (mergesort, bubblesort, permutationsort, mundaneSuperStrat) ([16, 23, 4, 8, 15, 42] :: [Int])+-- [4,8,15,16,23,42] ----- >>> supersort (mergesort, bubblesort, permutationsort, mundaneSuperStrat) (SortRec [(16, 23), (4, 8), (15, 42)])--- SortRec [(4,8),(16,23),(15,42)]+-- >>> supersort (mergesort, bubblesort, permutationsort, mundaneSuperStrat) ([(16, 23), (4, 8), (15, 42)] :: [(Int, Int)])+-- [(4,8),(15,42),(16,23)] supersort ::-  (SortAlg, SortAlg, SortAlg, SupersortStrat) ->-  Sortable ->-  Sortable-supersort (subAlg1, subAlg2, subAlg3, superStrat) xs = do-  let result1 = subAlg1 xs-  let result2 = subAlg2 xs+  (Ord a) =>+  (SortAlg a, SortAlg a, SortAlg a, SupersortStrat a) ->+  [a] ->+  [a]+supersort (subAlg1, subAlg2, subAlg3, superStrat) xs =   if result1 == result2     then result1     else superStrat (result1, result2, subAlg3 xs)+  where+    result1 = subAlg1 xs+    result2 = subAlg2 xs  -- | Takes 3 SortAlgs and adjudicates between them to find a common result. --   Optimized for use in Mundane Robustsort variants.@@ -49,13 +47,14 @@ -- >>> import Data.Tensort.OtherSorts.Mergesort (mergesort) -- >>> import Data.Tensort.Subalgorithms.Permutationsort (permutationsort) ----- >>> supersort (mergesort, bubblesort, permutationsort, mundaneSuperStrat) (SortBit [16, 23, 4, 8, 15, 42])--- SortBit [4,8,15,16,23,42]+-- >>> supersort (mergesort, bubblesort, permutationsort, mundaneSuperStrat) ([16, 23, 4, 8, 15, 42] :: [Int])+-- [4,8,15,16,23,42] ----- >>> supersort (mergesort, bubblesort, permutationsort, mundaneSuperStrat) (SortRec [(16, 23), (4, 8), (15, 42)])--- SortRec [(4,8),(16,23),(15,42)]-mundaneSuperStrat :: SupersortStrat-mundaneSuperStrat (result1, result2, result3) = if result2 == result3 then result2 else result1+-- >>> supersort (mergesort, bubblesort, permutationsort, mundaneSuperStrat) ([(16, 23), (4, 8), (15, 42)] :: [(Int, Int)])+-- [(4,8),(15,42),(16,23)]+mundaneSuperStrat :: (Ord a) => SupersortStrat a+mundaneSuperStrat (result1, result2, result3) =+  if result2 == result3 then result2 else result1  -- | Takes 3 SortAlgs and adjudicates between them to find a common result. --   Optimized for use in Magic Robustsort variants.@@ -69,10 +68,10 @@ -- >>> import Data.Tensort.OtherSorts.Mergesort (mergesort) -- >>> import Data.Tensort.Subalgorithms.Permutationsort (permutationsort) ----- >>> supersort (mergesort, bubblesort, permutationsort, magicSuperStrat) (SortBit [16, 23, 4, 8, 15, 42])--- SortBit [4,8,15,16,23,42]+-- >>> supersort (mergesort, bubblesort, permutationsort, magicSuperStrat) ([16, 23, 4, 8, 15, 42] :: [Int])+-- [4,8,15,16,23,42] ----- >>> supersort (mergesort, bubblesort, permutationsort, magicSuperStrat) (SortRec [(16, 23), (4, 8), (15, 42)])--- SortRec [(4,8),(16,23),(15,42)]-magicSuperStrat :: SupersortStrat+-- >>> supersort (mergesort, bubblesort, permutationsort, magicSuperStrat) ([(16, 23), (4, 8), (15, 42)] :: [(Int, Int)])+-- [(4,8),(15,42),(16,23)]+magicSuperStrat :: (Ord a) => SupersortStrat a magicSuperStrat = mundaneSuperStrat
src/Data/Tensort/Tensort.hs view
@@ -1,5 +1,4 @@--- | This module provides variations of the Tensort algorithm using the---   custom Sortable type for inputs and outputs+-- | This module provides variations of the Tensort algorithm module Data.Tensort.Tensort   ( tensort,     tensortB4,@@ -10,86 +9,78 @@  import Data.Tensort.Subalgorithms.Bubblesort (bubblesort) import Data.Tensort.Utils.Compose (createInitialTensors)-import Data.Tensort.Utils.Convert (rawToBytes)+import Data.Tensort.Utils.Convert (rawBitsToBytes) import Data.Tensort.Utils.LogNat (getLnBytesize) import Data.Tensort.Utils.MkTsProps (mkTsProps) import Data.Tensort.Utils.RandomizeList (randomizeList) import Data.Tensort.Utils.Reduce (reduceTensorStacks)-import Data.Tensort.Utils.Render (getSortedBitsFromTensor)+import Data.Tensort.Utils.Render (getSortedBits) import Data.Tensort.Utils.Types-  ( Sortable (..),+  ( Bit,     TensortProps (..),-    fromSBitBits,-    fromSBitRecs,   ) --- | Sort a Sortable list using a custom Tensort algorithm+-- | Sort a list using a custom Tensort algorithm -----   Takes TensortProps (Bytesize and SubAlgorithm) and a Sortable and returns---   a sorted Sortable+--   Takes TensortProps (Bytesize and SubAlgorithm) and a list and returns+--   a sorted list  -- | ==== __Examples__ -- >>> import Data.Tensort.Subalgorithms.Bubblesort (bubblesort) -- >>> import Data.Tensort.Utils.MkTsProps (mkTsProps)--- >>> tensort (mkTsProps 2 bubblesort) (SortBit [16, 23, 4, 8, 15, 42])--- SortBit [4,8,15,16,23,42]+-- >>> tensort (mkTsProps 2 bubblesort) ([16, 23, 4, 8, 15, 42] :: [Int])+-- [4,8,15,16,23,42] ----- >>> tensort (mkTsProps 2 bubblesort) (SortRec [(1, 16), (5, 23), (2, 4) ,(3, 8), (0, 15) , (4, 42)])--- SortRec [(2,4),(3,8),(0,15),(1,16),(5,23),(4,42)]-tensort :: TensortProps -> Sortable -> Sortable-tensort _ (SortBit []) = SortBit []-tensort _ (SortBit [x]) = SortBit [x]-tensort tsProps (SortBit [x, y]) = subAlgorithm tsProps (SortBit [x, y])-tensort tsProps (SortBit xs) =-  let bits = randomizeList 143 (SortBit xs)-      bytes = rawToBytes tsProps bits-      tensorStacks = createInitialTensors tsProps bytes-      topTensor = reduceTensorStacks tsProps tensorStacks-   in fromSBitBits (getSortedBitsFromTensor (subAlgorithm tsProps) topTensor)-tensort _ (SortRec []) = SortRec []-tensort _ (SortRec [x]) = SortRec [x]-tensort tsProps (SortRec [x, y]) = subAlgorithm tsProps (SortRec [x, y])-tensort tsProps (SortRec xs) =-  let recs = randomizeList 143 (SortRec xs)-      bytes = rawToBytes tsProps recs-      tensorStacks = createInitialTensors tsProps bytes-      topTensor = reduceTensorStacks tsProps tensorStacks-   in fromSBitRecs (getSortedBitsFromTensor (subAlgorithm tsProps) topTensor)+-- >>> tensort (mkTsProps 2 bubblesort) ([(1, 16), (5, 23), (2, 4) ,(3, 8), (0, 15) , (4, 42)] :: [(Int, Int)])+-- [(0,15),(1,16),(2,4),(3,8),(4,42),(5,23)]+tensort :: (Ord a) => TensortProps a -> [Bit a] -> [Bit a]+tensort _ [] = []+tensort _ [x] = [x]+tensort tsProps [x, y] = subAlgorithm tsProps [x, y]+tensort tsProps xs = getSortedBits subAlg topTensor+  where+    subAlg = subAlgorithm tsProps+    topTensor = reduceTensorStacks tsProps tensorStacks+    tensorStacks = createInitialTensors tsProps bytes+    bytes = rawBitsToBytes tsProps bits+    bits = randomizeList 143 xs --- | Sort a Sortable list using a Standard Tensort algorithm with a 4-Bit+-- | Sort a list using a Standard Tensort algorithm with a 4-Bit --   Bytesize  -- | ==== __Examples__--- >>> tensortB4 (SortBit [16, 23, 4, 8, 15, 42])--- SortBit [4,8,15,16,23,42]+-- >>> tensortB4 ([16, 23, 4, 8, 15, 42] :: [Int])+-- [4,8,15,16,23,42] ----- >>> tensortB4 (SortRec [(1, 16), (5, 23), (2, 4) ,(3, 8), (0, 15) , (4, 42)])--- SortRec [(2,4),(3,8),(0,15),(1,16),(5,23),(4,42)]-tensortB4 :: Sortable -> Sortable-tensortB4 = tensort (mkTsProps 4 bubblesort)+-- >>> tensortB4 ([(1, 16), (5, 23), (2, 4) ,(3, 8), (0, 15) , (4, 42)] :: [(Int, Int)])+-- [(0,15),(1,16),(2,4),(3,8),(4,42),(5,23)]+tensortB4 :: (Ord a) => [Bit a] -> [Bit a]+tensortB4 = tensort $ mkTsProps 4 bubblesort --- | Sort a Sortable list using a Standard Tensort algorithm with a custom+-- | Sort a list using a Standard Tensort algorithm with a custom --   Bytesize  -- | ==== __Examples__--- >>> tensortBN 3 (SortBit [16, 23, 4, 8, 15, 42])--- SortBit [4,8,15,16,23,42]+-- >>> tensortBN 3 ([16, 23, 4, 8, 15, 42] :: [Int])+-- [4,8,15,16,23,42] ----- >>> tensortBN 3 (SortRec [(1, 16), (5, 23), (2, 4) ,(3, 8), (0, 15) , (4, 42)])--- SortRec [(2,4),(3,8),(0,15),(1,16),(5,23),(4,42)]-tensortBN :: Int -> Sortable -> Sortable-tensortBN n = tensort (mkTsProps n bubblesort)+-- >>> tensortBN 3 ([(1, 16), (5, 23), (2, 4) ,(3, 8), (0, 15) , (4, 42)] :: [(Int, Int)])+-- [(0,15),(1,16),(2,4),(3,8),(4,42),(5,23)]+tensortBN :: (Ord a) => Int -> [Bit a] -> [Bit a]+tensortBN n = tensort $ mkTsProps n bubblesort --- | Sort a Sortable list using a Standard Logarithmic Tensort algorithm+-- | Sort a list using a Standard Logarithmic Tensort algorithm -- --   Standard Logarithmic Tensort uses a Bytesize that approximates the natural --   logarithm of the length of the input list and a Bubblesort subalgorithm  -- | ==== __Examples__--- >>> tensortBL (SortBit [16, 23, 4, 8, 15, 42])--- SortBit [4,8,15,16,23,42]+-- >>> tensortBL ([16, 23, 4, 8, 15, 42] :: [Int])+-- [4,8,15,16,23,42] ----- >>> tensortBL (SortRec [(1, 16), (5, 23), (2, 4) ,(3, 8), (0, 15) , (4, 42)])--- SortRec [(2,4),(3,8),(0,15),(1,16),(5,23),(4,42)]-tensortBL :: Sortable -> Sortable-tensortBL xs = tensort (mkTsProps (getLnBytesize xs) bubblesort) xs+-- >>> tensortBL ([(1, 16), (5, 23), (2, 4) ,(3, 8), (0, 15) , (4, 42)] :: [(Int, Int)])+-- [(0,15),(1,16),(2,4),(3,8),(4,42),(5,23)]+tensortBL :: (Ord a) => [Bit a] -> [Bit a]+tensortBL xs = tensort tsProps xs+  where+    tsProps = mkTsProps (getLnBytesize xs) bubblesort
src/Data/Tensort/Utils/Check.hs view
@@ -2,27 +2,17 @@ --   elements is sorted in ascending order. module Data.Tensort.Utils.Check (isSorted) where -import Data.Tensort.Utils.ComparisonFunctions-  ( lessThanOrEqualBit,-    lessThanOrEqualRecord,-  )-import Data.Tensort.Utils.Types (Sortable (..))---- | Takes a Sortable list and returns True if the list is sorted in ascending+-- | Takes a list and returns True if the list is sorted in ascending --   order and False otherwise.  -- | ==== __Examples__--- >>> isSorted (SortBit [0, 1, 2, 3, 4])+-- >>> isSorted ([0, 1, 2, 3, 4] :: [Int]) -- True ----- >>> isSorted (SortBit [0, 1, 2, 4, 3])+-- >>> isSorted ([0, 1, 2, 4, 3] :: [Int]) -- False-isSorted :: Sortable -> Bool-isSorted (SortBit []) = True-isSorted (SortBit [_]) = True-isSorted (SortBit (x : y : remainingElements)) =-  lessThanOrEqualBit x y && isSorted (SortBit (y : remainingElements))-isSorted (SortRec []) = True-isSorted (SortRec [_]) = True-isSorted (SortRec (x : y : remainingElements)) =-  lessThanOrEqualRecord x y && isSorted (SortRec (y : remainingElements))+isSorted :: (Ord a) => [a] -> Bool+isSorted [] = True+isSorted [_] = True+isSorted (x : y : remainingElements) =+  x <= y && isSorted (y : remainingElements)
− src/Data/Tensort/Utils/ComparisonFunctions.hs
@@ -1,45 +0,0 @@-module Data.Tensort.Utils.ComparisonFunctions-  ( lessThanBit,-    lessThanRecord,-    lessThanOrEqualBit,-    lessThanOrEqualRecord,-    greaterThanBit,-    greaterThanRecord,-    greaterThanOrEqualBit,-    greaterThanOrEqualRecord,-    equalBit,-    equalRecord,-  )-where--import Data.Tensort.Utils.Types (Bit, Record)--lessThanBit :: Bit -> Bit -> Bool-lessThanBit x y = x < y--lessThanRecord :: Record -> Record -> Bool-lessThanRecord x y = snd x < snd y--lessThanOrEqualBit :: Bit -> Bit -> Bool-lessThanOrEqualBit x y = x <= y--lessThanOrEqualRecord :: Record -> Record -> Bool-lessThanOrEqualRecord x y = snd x <= snd y--greaterThanBit :: Bit -> Bit -> Bool-greaterThanBit x y = x > y--greaterThanRecord :: Record -> Record -> Bool-greaterThanRecord x y = snd x > snd y--greaterThanOrEqualBit :: Bit -> Bit -> Bool-greaterThanOrEqualBit x y = x >= y--greaterThanOrEqualRecord :: Record -> Record -> Bool-greaterThanOrEqualRecord x y = snd x >= snd y--equalBit :: Bit -> Bit -> Bool-equalBit x y = x == y--equalRecord :: Record -> Record -> Bool-equalRecord x y = snd x == snd y
src/Data/Tensort/Utils/Compose.hs view
@@ -1,48 +1,23 @@ -- | Module for creating Tensors from Bytes and Tensors.------   Functions ending in "B" are for sorting Bits in a base (non-recursive)---   Tensort variant.------   Functions ending in "R" are for sorting Records when used in a recursive---   Tensort variant.------   TODO: See if we can clean up the type conversion here. module Data.Tensort.Utils.Compose   ( createInitialTensors,     createTensor,   ) where -import Data.Tensort.Utils.SimplifyRegister-  ( applySortingFromSimplifiedRegister,-    simplifyRegister,-  )+import Data.Tensort.Utils.SortRecs (sortRecs) import Data.Tensort.Utils.Split (splitEvery) import Data.Tensort.Utils.Types-  ( Byte,-    ByteR,+  ( Bit,+    Byte,     Memory (..),-    MemoryR (..),-    Record,-    RecordR,-    SBit (..),-    SBytes (..),-    SMemory (..),-    SRecord (..),-    STensor (..),-    STensors (..),+    Record (..),+    Register,     SortAlg,-    Sortable (..),-    Tensor,-    TensorR,+    Tensor (..),     TensortProps (..),-    fromSBitBit,-    fromSBitRec,-    fromSRecordArrayBit,-    fromSRecordArrayRec,-    fromSTensorBit,-    fromSTensorRec,-    fromSortRec,+    fromRecord,+    fromTensor,   )  -- | Convert a list of Bytes to a list of TensorStacks.@@ -54,55 +29,26 @@ -- | ==== __Examples__ -- >>> import Data.Tensort.Subalgorithms.Bubblesort (bubblesort) -- >>> import Data.Tensort.Utils.MkTsProps (mkTsProps)--- >>> createInitialTensors (mkTsProps 2 bubblesort) (SBytesBit [[2,4],[6,8],[1,3],[5,7]])--- STensorsBit [([(0,3),(1,7)],ByteMem [[1,3],[5,7]]),([(0,4),(1,8)],ByteMem [[2,4],[6,8]])]-createInitialTensors :: TensortProps -> SBytes -> STensors-createInitialTensors tsProps (SBytesBit bytes) =-  STensorsBit (createInitialTensorsB tsProps bytes)-createInitialTensors tsProps (SBytesRec recs) =-  STensorsRec (createInitialTensorsR tsProps recs)--createInitialTensorsB :: TensortProps -> [Byte] -> [Tensor]-createInitialTensorsB tsProps bytes =+-- >>> createInitialTensors (mkTsProps 2 bubblesort) [[2,4] :: [Int],[6,8] :: [Int],[1,3] :: [Int],[5,7] :: [Int]]+-- [Tensor ([Record (3,0),Record (7,1)],ByteMem [[1,3],[5,7]]),Tensor ([Record (4,0),Record (8,1)],ByteMem [[2,4],[6,8]])]+createInitialTensors :: (Ord a) => TensortProps a -> [Byte a] -> [Tensor a]+createInitialTensors tsProps bytes =   foldr acc [] (splitEvery (bytesize tsProps) bytes)   where-    acc :: [Byte] -> [Tensor] -> [Tensor]     acc byte tensorStacks =       tensorStacks-        ++ [ fromSTensorBit-               (getTensorFromBytes (subAlgorithm tsProps) (SBytesBit byte))-           ]--createInitialTensorsR :: TensortProps -> [ByteR] -> [TensorR]-createInitialTensorsR tsProps bytesR =-  foldr acc [] (splitEvery (bytesize tsProps) bytesR)-  where-    acc :: [ByteR] -> [TensorR] -> [TensorR]-    acc byteR tensorStacks =-      tensorStacks-        ++ [ fromSTensorRec-               (getTensorFromBytes (subAlgorithm tsProps) (SBytesRec byteR))-           ]+        ++ [tensorStack]+      where+        tensorStack = getTensorFromBytes subAlg byte+        subAlg = subAlgorithm tsProps  -- | Create a Tensor from a Memory. -- --   Aliases to getTensorFromBytes for ByteMem and getTensorFromTensors for --   TensorMem.-createTensor :: SortAlg -> SMemory -> STensor-createTensor subAlg (SMemoryBit memory) = createTensorB subAlg memory-createTensor subAlg (SMemoryRec memoryR) = createTensorR subAlg memoryR--createTensorB :: SortAlg -> Memory -> STensor-createTensorB subAlg (ByteMem bytes) =-  getTensorFromBytes subAlg (SBytesBit bytes)-createTensorB subAlg (TensorMem tensors) =-  getTensorFromTensors subAlg (STensorsBit tensors)--createTensorR :: SortAlg -> MemoryR -> STensor-createTensorR subAlg (ByteMemR bytesR) =-  getTensorFromBytes subAlg (SBytesRec bytesR)-createTensorR subAlg (TensorMemR tensorsR) =-  getTensorFromTensors subAlg (STensorsRec tensorsR)+createTensor :: (Ord a) => SortAlg a -> Memory a -> Tensor a+createTensor subAlg (ByteMem bytes) = getTensorFromBytes subAlg bytes+createTensor subAlg (TensorMem tensors) = getTensorFromTensors subAlg tensors  -- | Convert a list of Bytes to a Tensor. @@ -117,78 +63,32 @@  -- | ==== __Examples__ -- >>> import Data.Tensort.Subalgorithms.Bubblesort (bubblesort)--- >>> getTensorFromBytes bubblesort (SBytesBit [[2,4,6,8],[1,3,5,7]])--- STensorBit ([(1,7),(0,8)],ByteMem [[2,4,6,8],[1,3,5,7]])-getTensorFromBytes :: SortAlg -> SBytes -> STensor-getTensorFromBytes subAlg (SBytesBit bytes) =-  STensorBit (getTensorFromBytesB subAlg bytes)-getTensorFromBytes subAlg (SBytesRec recs) =-  STensorRec (getTensorFromBytesR subAlg recs)--getTensorFromBytesB :: SortAlg -> [Byte] -> Tensor-getTensorFromBytesB subAlg bytes = do-  let register = acc bytes [] 0-  let register' = fromSortRec (subAlg (SortRec register))-  (register', ByteMem bytes)-  where-    acc :: [Byte] -> [Record] -> Int -> [Record]-    acc [] register _ = register-    acc ([] : remainingBytes) register i = acc remainingBytes register (i + 1)-    acc (byte : remainingBytes) register i =-      acc remainingBytes (register ++ [(i, last byte)]) (i + 1)--getTensorFromBytesR :: SortAlg -> [ByteR] -> TensorR-getTensorFromBytesR subAlg bytesR = do-  let registerR = acc bytesR [] 0-  let simplifiedRegiser = simplifyRegister registerR-  let simplifiedRegiser' = fromSortRec (subAlg (SortRec simplifiedRegiser))-  let registerR' =-        applySortingFromSimplifiedRegister simplifiedRegiser' registerR-  (registerR', ByteMemR bytesR)+-- >>> getTensorFromBytes bubblesort [[2,4,6,8] :: [Int],[1,3,5,7] :: [Int]]+-- Tensor ([Record (7,1),Record (8,0)],ByteMem [[2,4,6,8],[1,3,5,7]])+getTensorFromBytes :: (Ord a) => SortAlg a -> [Byte a] -> Tensor a+getTensorFromBytes subAlg bytes = Tensor (register', ByteMem bytes)   where-    acc :: [ByteR] -> [RecordR] -> Int -> [RecordR]-    acc [] register _ = register-    acc ([] : remainingBytesR) registerR i =-      acc remainingBytesR registerR (i + 1)-    acc (byteR : remainingBytesR) registerR i =-      acc remainingBytesR (registerR ++ [(i, last byteR)]) (i + 1)+    register' = sortRecs subAlg $ map Record register+    register = acc bytes [] 0+    acc [] regi _ = regi+    acc ([] : remainingBytes) regi i = acc remainingBytes regi (i + 1)+    acc (byte : remainingBytes) regi i =+      acc remainingBytes (regi ++ [record]) (i + 1)+      where+        record = (last byte, i :: Int)  -- | Create a TensorStack with the collated and sorted References from the --   Tensors as its Register and the original Tensors as its Memory.  -- | ==== __Examples__ -- >>> import Data.Tensort.Subalgorithms.Bubblesort (bubblesort)--- >>> getTensorFromTensors bubblesort (STensorsBit [([(0,13),(1,18)],ByteMem [[11,13],[15,18]]),([(1,14),(0,17)],ByteMem [[16,17],[12,14]])])--- STensorBit ([(1,17),(0,18)],TensorMem [([(0,13),(1,18)],ByteMem [[11,13],[15,18]]),([(1,14),(0,17)],ByteMem [[16,17],[12,14]])])-getTensorFromTensors :: SortAlg -> STensors -> STensor-getTensorFromTensors subAlg (STensorsBit tensors) =-  STensorBit (getTensorFromTensorsB subAlg tensors)-getTensorFromTensors subAlg (STensorsRec tensors) =-  STensorRec (getTensorFromTensorsR subAlg tensors)--getTensorFromTensorsB :: SortAlg -> [Tensor] -> Tensor-getTensorFromTensorsB subAlg tensors =-  ( fromSortRec-      ( subAlg-          ( SortRec-              ( fromSRecordArrayBit-                  (getRegisterFromTensors (STensorsBit tensors))-              )-          )-      ),-    TensorMem tensors-  )--getTensorFromTensorsR :: SortAlg -> [TensorR] -> TensorR-getTensorFromTensorsR subAlg tensorsR = do-  let registerR = getRegisterFromTensors (STensorsRec tensorsR)-  let simplifiedRegiser = simplifyRegister (fromSRecordArrayRec registerR)-  let simplifiedRegiser' = fromSortRec (subAlg (SortRec simplifiedRegiser))-  let registerR' =-        applySortingFromSimplifiedRegister-          simplifiedRegiser'-          (fromSRecordArrayRec registerR)-  (registerR', TensorMemR tensorsR)+-- >>> getTensorFromTensors bubblesort [Tensor ([Record (0,13),Record (1,18)],ByteMem [[11,13] :: [Int],[15,18] :: [Int]]),Tensor ([Record (1,14),Record (0,17)],ByteMem [[16,17] :: [Int],[12,14] :: [Int]])]+-- Tensor ([Record (0,1),Record (1,0)],TensorMem [Tensor ([Record (0,13),Record (1,18)],ByteMem [[11,13],[15,18]]),Tensor ([Record (1,14),Record (0,17)],ByteMem [[16,17],[12,14]])])+getTensorFromTensors :: (Ord a) => SortAlg a -> [Tensor a] -> Tensor a+getTensorFromTensors subAlg tensors = Tensor (sortedRegister, TensorMem tensors)+  where+    sortedRegister = sortRecs subAlg unsortedRegister+    unsortedRegister = getRegisterFromTensors tensors  -- | Used in creating a Register for a newly-created Tensor which encloses --   other Tensors.@@ -201,51 +101,20 @@ --   getTensorFromTensors function.  -- | ==== __Examples__--- >>> getRegisterFromTensors (STensorsBit [([(0,13),(1,18)],ByteMem [[11,13],[15,18]]),([(0,14),(1,17)],ByteMem [[12,14],[16,17]]),([(0,3),(1,7)],ByteMem [[1,3],[5,7]]),([(0,4),(1,8)],ByteMem [[2,4],[6,8]])])--- [SRecordBit (0,18),SRecordBit (1,17),SRecordBit (2,7),SRecordBit (3,8)]-getRegisterFromTensors :: STensors -> [SRecord]-getRegisterFromTensors (STensorsBit tensors) = getRegisterFromTensorsB tensors-getRegisterFromTensors (STensorsRec tensors) = getRegisterFromTensorsR tensors--getRegisterFromTensorsB :: [Tensor] -> [SRecord]-getRegisterFromTensorsB tensors = acc tensors []+-- >>> getRegisterFromTensors [Tensor ([Record (0 :: Int,13),Record (1 :: Int,18)],ByteMem [[11,13] :: [Int],[15,18] :: [Int]]),Tensor ([Record (0 :: Int,14),Record (1 :: Int,17)],ByteMem [[12,14] :: [Int],[16,17] :: [Int]]),Tensor ([Record (0 :: Int,3),Record (1 :: Int,7)],ByteMem [[1,3] :: [Int],[5,7] :: [Int]]),Tensor ([Record (0 :: Int,4),Record (1 :: Int,8)],ByteMem [[2,4] :: [Int],[6,8] :: [Int]])]+-- [Record (1,0),Record (1,1),Record (1,2),Record (1,3)]+getRegisterFromTensors :: [Tensor a] -> [Record a]+getRegisterFromTensors tensors = acc tensors []   where-    acc :: [Tensor] -> [SRecord] -> [SRecord]+    acc :: [Tensor a] -> [Record a] -> [Record a]     acc [] records = records-    acc (([], _) : remainingTensors) records = acc remainingTensors records+    acc (Tensor ([], _) : remainingTensors) records = acc remainingTensors records     acc (tensor : remainingTensors) records =-      acc-        remainingTensors-        ( records-            ++ [ SRecordBit-                   ( i,-                     fromSBitBit-                       (getTopBitFromTensorStack (STensorBit tensor))-                   )-               ]-        )-      where-        i = length records--getRegisterFromTensorsR :: [TensorR] -> [SRecord]-getRegisterFromTensorsR tensorsR = acc tensorsR []-  where-    acc :: [TensorR] -> [SRecord] -> [SRecord]-    acc [] records = records-    acc (([], _) : remainingTensorsR) records = acc remainingTensorsR records-    acc (tensorR : remainingTensorsR) records =-      acc-        remainingTensorsR-        ( records-            ++ [ SRecordRec-                   ( i,-                     fromSBitRec-                       (getTopBitFromTensorStack (STensorRec tensorR))-                   )-               ]-        )+      acc remainingTensors $ records ++ [Record record]       where+        record = (topBit, i)         i = length records+        topBit = getTopBitFromTensorStack (fromTensor tensor)  -- | Get the top Bit from a TensorStack. @@ -256,10 +125,11 @@ -- | This is also expected to be the highest value in the TensorStack.  -- | ==== __Examples__--- >>> getTopBitFromTensorStack (STensorBit ([(0,28),(1,38)],TensorMem [([(0,27),(1,28)],TensorMem [([(0,23),(1,27)],ByteMem [[21,23],[25,27]]),([(0,24),(1,28)],ByteMem [[22,24],[26,28]])]),([(1,37),(0,38)],TensorMem [([(0,33),(1,38)],ByteMem [[31,33],[35,38]]),([(0,34),(1,37)],ByteMem [[32,14],[36,37]])])]))--- SBitBit 38-getTopBitFromTensorStack :: STensor -> SBit-getTopBitFromTensorStack (STensorBit tensor) =-  SBitBit (snd (last (fst tensor)))-getTopBitFromTensorStack (STensorRec tensorR) =-  SBitRec (snd (last (fst tensorR)))+-- >>> getTopBitFromTensorStack ([Record (0 :: Int,28),Record (1 :: Int,38)],TensorMem [Tensor ([Record (0 :: Int,27),Record (1 :: Int,28)],TensorMem [Tensor ([Record (0 :: Int,23),Record (1 :: Int,27)],ByteMem [[21,23] :: [Int],[25,27] :: [Int]]),Tensor ([Record (0 :: Int,24),Record (1 :: Int,28)],ByteMem [[22,24] :: [Int],[26,28] :: [Int]])]),Tensor ([Record (1 :: Int,37),Record (0 :: Int,38)],TensorMem [Tensor ([Record (0 :: Int,33),Record (1 :: Int,38)],ByteMem [[31,33] :: [Int],[35,38] :: [Int]]),Tensor ([Record (0 :: Int,34),Record (1 :: Int,37)],ByteMem [[32,14] :: [Int],[36,37] :: [Int]])])])+-- 1+getTopBitFromTensorStack :: (Register a, Memory a) -> Bit a+getTopBitFromTensorStack tensor =+  let register = fst tensor+      topRecord = last register+      topBit = fst (fromRecord topRecord)+   in topBit
src/Data/Tensort/Utils/Convert.hs view
@@ -1,18 +1,11 @@--- | Module for converting raw input data into SBytes.--- --   TODO: See if we can clean up the type conversion here.-module Data.Tensort.Utils.Convert (rawToBytes) where+module Data.Tensort.Utils.Convert (rawBitsToBytes) where  import Data.Tensort.Utils.Split (splitEvery) import Data.Tensort.Utils.Types   ( Bit,     Byte,-    Record,-    SBytes (SBytesBit, SBytesRec),-    Sortable (..),     TensortProps (..),-    fromSortBit,-    fromSortRec,   )  -- | Convert a list of Bits to a list of Bytes of given bytesize, sorting@@ -21,22 +14,13 @@ -- | ==== __Examples__ --   >>> import Data.Tensort.Subalgorithms.Bubblesort (bubblesort) --   >>> import Data.Tensort.Utils.MkTsProps (mkTsProps)---   >>> rawBitsToBytes (mkTsProps 4 bubblesort) [5,1,3,7,8,2,4,6]+--   >>> rawBitsToBytes (mkTsProps 4 bubblesort) ([5,1,3,7,8,2,4,6] :: [Int]) --   [[2,4,6,8],[1,3,5,7]]-rawToBytes :: TensortProps -> Sortable -> SBytes-rawToBytes tsProps (SortBit xs) = SBytesBit (rawBitsToBytes tsProps xs)-rawToBytes tsProps (SortRec xs) = SBytesRec (rawRecsToBytes tsProps xs)--rawBitsToBytes :: TensortProps -> [Bit] -> [Byte]-rawBitsToBytes tsProps bits = foldr acc [] (splitEvery (bytesize tsProps) bits)-  where-    acc :: [Bit] -> [Byte] -> [Byte]-    acc byte bytes =-      bytes ++ [fromSortBit (subAlgorithm tsProps (SortBit byte))]--rawRecsToBytes :: TensortProps -> [Record] -> [[Record]]-rawRecsToBytes tsProps recs = foldr acc [] (splitEvery (bytesize tsProps) recs)+rawBitsToBytes :: TensortProps a -> [Bit a] -> [Byte a]+rawBitsToBytes tsProps bits = foldr acc [] bytes   where-    acc :: [Record] -> [[Record]] -> [[Record]]-    acc rbyte rbytes =-      rbytes ++ [fromSortRec (subAlgorithm tsProps (SortRec rbyte))]+    bytes = splitEvery (bytesize tsProps) bits+    acc byte bytesSorted =+      bytesSorted ++ [byteSorted]+      where+        byteSorted = subAlgorithm tsProps byte
src/Data/Tensort/Utils/LogNat.hs view
@@ -2,25 +2,22 @@ --   a way useful for creating logarithmic Bytesizes. module Data.Tensort.Utils.LogNat (getLnBytesize, getLn) where -import Data.Tensort.Utils.Types (Sortable (..))---- | Calculates a suitable logarithmic Bytesize for a given Sortable list.+-- | Calculates a suitable logarithmic Bytesize for a given list.  -- | ==== __Examples__--- >>> getLnBytesize (SortBit [1 .. 27])+-- >>> getLnBytesize ([1 .. 27] :: [Int]) -- 4 ----- >>> getLnBytesize  (SortRec [(1, 16), (5, 23), (2, 4) ,(3, 8), (0, 15) , (4, 42)])+-- >>> getLnBytesize  ([(1, 16), (5, 23), (2, 4), (3, 8), (0, 15) , (4, 42)] :: [(Int, Int)]) -- 2-getLnBytesize :: Sortable -> Int-getLnBytesize (SortBit xs) = getLn (length xs)-getLnBytesize (SortRec xs) = getLn (length xs)+getLnBytesize :: (Ord a) => [a] -> Int+getLnBytesize xs = getLn $ length xs  -- | Calculates the natural logarithm of an integer, rounded up to the nearest --   integer. -- -- | ==== __Examples__--- >>> getLn 27+-- >>> getLn (27 :: Int) -- 4 getLn :: Int -> Int-getLn x = ceiling (log (fromIntegral x) :: Double)+getLn x = ceiling $ log (fromIntegral x :: Double)
src/Data/Tensort/Utils/MkTsProps.hs view
@@ -3,6 +3,6 @@  import Data.Tensort.Utils.Types (SortAlg, TensortProps (..)) --- | Wraps in integer Bytesize and a SubAlgorithm together as TensortProps.-mkTsProps :: Int -> SortAlg -> TensortProps+-- | Wraps an integer Bytesize and a SubAlgorithm together as TensortProps.+mkTsProps :: (Ord a) => Int -> SortAlg a -> TensortProps a mkTsProps bSize subAlg = TensortProps {bytesize = bSize, subAlgorithm = subAlg}
src/Data/Tensort/Utils/RandomizeList.hs view
@@ -1,21 +1,18 @@ -- | This module prvodies the randomizeList function, which randomizes the---   order of elements in Sortable lists.+--   order of elements in sortable lists. module Data.Tensort.Utils.RandomizeList (randomizeList) where -import Data.Tensort.Utils.Types (Sortable (..)) import System.Random (mkStdGen) import System.Random.Shuffle (shuffle') --- | Takes a seed for random generation and a Sortable list and returns a new---   Sortable list with the same elements as the input list but in a random---   order.+-- | Takes a seed for random generation and a list and returns a new+--   list with the same elements as the input list but in a random order.  -- | ==== __Examples__--- >>> randomizeList 143 (SortBit [4, 8, 15, 16, 23, 42])--- SortBit [16,23,4,8,15,42]+-- >>> randomizeList 143 ([4, 8, 15, 16, 23, 42] :: [Int])+-- [16,23,4,8,15,42] ----- >>> randomizeList 143 (SortRec [(2,4),(3,8),(0,15),(1,16),(5,23),(4,42)])--- SortRec [(1,16),(5,23),(2,4),(3,8),(0,15),(4,42)]-randomizeList :: Int -> Sortable -> Sortable-randomizeList seed (SortBit xs) = SortBit (shuffle' xs (length xs) (mkStdGen seed))-randomizeList seed (SortRec xs) = SortRec (shuffle' xs (length xs) (mkStdGen seed))+-- >>> randomizeList 143 ([(2,4),(3,8),(0,15),(1,16),(5,23),(4,42)] :: [(Int, Int)])+-- [(1,16),(5,23),(2,4),(3,8),(0,15),(4,42)]+randomizeList :: (Ord a) => Int -> [a] -> [a]+randomizeList seed xs = shuffle' xs (length xs) $ mkStdGen seed
src/Data/Tensort/Utils/Reduce.hs view
@@ -1,29 +1,13 @@ -- | This module provides functions to reduce a list of TensorStacks into a --   more compact list of TensorStacks.------   Functions ending in "B" are for sorting Bits in a base (non-recursive)---   Tensort variant.------   Functions ending in "R" are for sorting Records when used in a recursive---   Tensort variant.------   TODO: See if we can clean up the type conversion here. module Data.Tensort.Utils.Reduce (reduceTensorStacks) where  import Data.Tensort.Utils.Compose (createTensor) import Data.Tensort.Utils.Split (splitEvery) import Data.Tensort.Utils.Types   ( Memory (..),-    MemoryR (..),-    SMemory (..),-    STensorStack,-    STensorStacks,-    STensors (..),     TensorStack,-    TensorStackR,     TensortProps (..),-    fromSTensorBit,-    fromSTensorRec,   )  -- | Take a list of TensorStacks and group them together in new@@ -35,33 +19,19 @@ -- | ==== __Examples__ -- >>> import Data.Tensort.Subalgorithms.Bubblesort (bubblesort) -- >>> import Data.Tensort.Utils.MkTsProps (mkTsProps)--- >>> reduceTensorStacks (mkTsProps 2 bubblesort) (STensorsBit [([(0, 33), (1, 38)], ByteMem [[31, 33], [35, 38]]), ([(0, 34), (1, 37)], ByteMem [[32, 14], [36, 37]]), ([(0, 23), (1, 27)], ByteMem [[21, 23], [25, 27]]), ([(0, 24), (1, 28)], ByteMem [[22, 24], [26, 28]]),([(0,13),(1,18)],ByteMem [[11,13],[15,18]]),([(0,14),(1,17)],ByteMem [[12,14],[16,17]]),([(0,3),(1,7)],ByteMem [[1,3],[5,7]]),([(0,4),(1,8)],ByteMem [[2,4],[6,8]])])--- STensorBit ([(1,18),(0,38)],TensorMem [([(0,28),(1,38)],TensorMem [([(0,27),(1,28)],TensorMem [([(0,23),(1,27)],ByteMem [[21,23],[25,27]]),([(0,24),(1,28)],ByteMem [[22,24],[26,28]])]),([(1,37),(0,38)],TensorMem [([(0,33),(1,38)],ByteMem [[31,33],[35,38]]),([(0,34),(1,37)],ByteMem [[32,14],[36,37]])])]),([(0,8),(1,18)],TensorMem [([(0,7),(1,8)],TensorMem [([(0,3),(1,7)],ByteMem [[1,3],[5,7]]),([(0,4),(1,8)],ByteMem [[2,4],[6,8]])]),([(1,17),(0,18)],TensorMem [([(0,13),(1,18)],ByteMem [[11,13],[15,18]]),([(0,14),(1,17)],ByteMem [[12,14],[16,17]])])])])-reduceTensorStacks :: TensortProps -> STensorStacks -> STensorStack-reduceTensorStacks tsProps (STensorsBit tensorStacks) =-  reduceTensorStacksB tsProps tensorStacks-reduceTensorStacks tsProps (STensorsRec tensorStacks) =-  reduceTensorStacksR tsProps tensorStacks--reduceTensorStacksB :: TensortProps -> [TensorStack] -> STensorStack-reduceTensorStacksB tsProps tensorStacks = do-  let newTensorStacks = reduceTensorStacksSinglePass tsProps tensorStacks-  if length newTensorStacks <= bytesize tsProps-    then-      createTensor-        (subAlgorithm tsProps)-        (SMemoryBit (TensorMem newTensorStacks))-    else reduceTensorStacksB tsProps newTensorStacks--reduceTensorStacksR :: TensortProps -> [TensorStackR] -> STensorStack-reduceTensorStacksR tsProps tensorStacks = do-  let newTensorStacks = reduceTensorStacksRSinglePass tsProps tensorStacks+-- >>> import Data.Tensort.Utils.Types (Record (..))+-- >>> import Data.Tensort.Utils.Types (Tensor (..))+-- >>> reduceTensorStacks (mkTsProps 2 bubblesort) [Tensor ([Record (0 :: Int, 33), Record (1 :: Int, 38)], ByteMem [[31, 33] :: [Int], [35, 38] :: [Int]]), Tensor ([Record (0 :: Int, 34), Record (1 :: Int, 37)], ByteMem [[32, 14] :: [Int], [36, 37] :: [Int]]), Tensor ([Record (0 :: Int, 23), Record (1 :: Int, 27)], ByteMem [[21, 23] :: [Int], [25, 27] :: [Int]]), Tensor ([Record (0 :: Int, 24), Record (1 :: Int, 28)], ByteMem [[22, 24] :: [Int], [26, 28] :: [Int]]),Tensor ([Record (0 :: Int,13),Record (1 :: Int,18)],ByteMem [[11,13] :: [Int],[15,18] :: [Int]]),Tensor ([Record (0 :: Int,14),Record (1 :: Int,17)],ByteMem [[12,14] :: [Int],[16,17] :: [Int]]),Tensor ([Record (0 :: Int,3),Record (1 :: Int,7)],ByteMem [[1,3] :: [Int],[5,7] :: [Int]]),Tensor ([Record (0 :: Int,4),Record (1 :: Int,8)],ByteMem [[2,4] :: [Int],[6,8] :: [Int]])]+-- Tensor ([Record (1,0),Record (1,1),Record (1,2),Record (1,3)],TensorMem [Tensor ([Record (1,0),Record (1,1)],TensorMem [Tensor ([Record (0,3),Record (1,7)],ByteMem [[1,3],[5,7]]),Tensor ([Record (0,4),Record (1,8)],ByteMem [[2,4],[6,8]])]),Tensor ([Record (1,0),Record (1,1)],TensorMem [Tensor ([Record (0,13),Record (1,18)],ByteMem [[11,13],[15,18]]),Tensor ([Record (0,14),Record (1,17)],ByteMem [[12,14],[16,17]])]),Tensor ([Record (1,0),Record (1,1)],TensorMem [Tensor ([Record (0,23),Record (1,27)],ByteMem [[21,23],[25,27]]),Tensor ([Record (0,24),Record (1,28)],ByteMem [[22,24],[26,28]])]),Tensor ([Record (1,0),Record (1,1)],TensorMem [Tensor ([Record (0,33),Record (1,38)],ByteMem [[31,33],[35,38]]),Tensor ([Record (0,34),Record (1,37)],ByteMem [[32,14],[36,37]])])])+reduceTensorStacks :: (Ord a) => TensortProps a -> [TensorStack a] -> TensorStack a+reduceTensorStacks tsProps tensorStacks =   if length newTensorStacks <= bytesize tsProps-    then-      createTensor-        (subAlgorithm tsProps)-        (SMemoryRec (TensorMemR newTensorStacks))-    else reduceTensorStacksR tsProps newTensorStacks+    then createTensor subAlg memory+    else reduceTensorStacks tsProps newTensorStacks+  where+    subAlg = subAlgorithm tsProps+    memory = TensorMem tensorStacks+    newTensorStacks = reduceTensorStacksSinglePass tsProps tensorStacks  -- | Take a list of TensorStacks and group them together in new --   TensorStacks each containing bytesize number of Tensors (former@@ -72,38 +42,23 @@ -- | ==== __Examples__ -- >>> import Data.Tensort.Subalgorithms.Bubblesort (bubblesort) -- >>> import Data.Tensort.Utils.MkTsProps (mkTsProps)--- >>> reduceTensorStacksSinglePass (mkTsProps 2 bubblesort) [([(0,13),(1,18)],ByteMem [[11,13],[15,18]]),([(0,14),(1,17)],ByteMem [[12,14],[16,17]]),([(0,3),(1,7)],ByteMem [[1,3],[5,7]]),([(0,4),(1,8)],ByteMem [[2,4],[6,8]])]--- [([(0,7),(1,8)],TensorMem [([(0,3),(1,7)],ByteMem [[1,3],[5,7]]),([(0,4),(1,8)],ByteMem [[2,4],[6,8]])]),([(1,17),(0,18)],TensorMem [([(0,13),(1,18)],ByteMem [[11,13],[15,18]]),([(0,14),(1,17)],ByteMem [[12,14],[16,17]])])]+-- >>> import Data.Tensort.Utils.Types (Record (..))+-- >>> import Data.Tensort.Utils.Types (Tensor (..))+-- >>> reduceTensorStacksSinglePass (mkTsProps 2 bubblesort) [Tensor ([Record (0 :: Int,13),Record (1 :: Int,18)],ByteMem [[11,13] :: [Int],[15,18] :: [Int]]),Tensor ([Record (0 :: Int,14),Record (1 :: Int,17)],ByteMem [[12,14] :: [Int],[16,17] :: [Int]]),Tensor ([Record (0 :: Int,3),Record (1 :: Int,7)],ByteMem [[1,3] :: [Int],[5,7] :: [Int]]),Tensor ([Record (0 :: Int,4),Record (1 :: Int,8)],ByteMem [[2,4] :: [Int],[6,8] :: [Int]])]+-- [Tensor ([Record (1,0),Record (1,1)],TensorMem [Tensor ([Record (0,3),Record (1,7)],ByteMem [[1,3],[5,7]]),Tensor ([Record (0,4),Record (1,8)],ByteMem [[2,4],[6,8]])]),Tensor ([Record (1,0),Record (1,1)],TensorMem [Tensor ([Record (0,13),Record (1,18)],ByteMem [[11,13],[15,18]]),Tensor ([Record (0,14),Record (1,17)],ByteMem [[12,14],[16,17]])])] reduceTensorStacksSinglePass ::-  TensortProps ->-  [TensorStack] ->-  [TensorStack]+  (Ord a) =>+  TensortProps a ->+  [TensorStack a] ->+  [TensorStack a] reduceTensorStacksSinglePass tsProps tensorStacks =-  foldr acc [] (splitEvery (bytesize tsProps) tensorStacks)-  where-    acc :: [TensorStack] -> [TensorStack] -> [TensorStack]-    acc tensorStack newTensorStacks =-      newTensorStacks-        ++ [ fromSTensorBit-               ( createTensor-                   (subAlgorithm tsProps)-                   (SMemoryBit (TensorMem tensorStack))-               )-           ]--reduceTensorStacksRSinglePass ::-  TensortProps ->-  [TensorStackR] ->-  [TensorStackR]-reduceTensorStacksRSinglePass tsProps tensorStacks =-  foldr acc [] (splitEvery (bytesize tsProps) tensorStacks)+  foldr acc [] tensorStacks'   where-    acc :: [TensorStackR] -> [TensorStackR] -> [TensorStackR]+    tensorStacks' = splitEvery (bytesize tsProps) tensorStacks     acc tensorStack newTensorStacks =       newTensorStacks-        ++ [ fromSTensorRec-               ( createTensor-                   (subAlgorithm tsProps)-                   (SMemoryRec (TensorMemR tensorStack))-               )-           ]+        ++ [newTensorStack]+      where+        newTensorStack = createTensor subAlg memory+        subAlg = subAlgorithm tsProps+        memory = TensorMem tensorStack
src/Data/Tensort/Utils/Render.hs view
@@ -1,75 +1,38 @@ -- | Module for rendering a sorted list of Bits from a list of TensorStacks.------   Functions ending in "B" are for sorting Bits in a base (non-recursive)---   Tensort variant.------   Functions ending in "R" are for sorting Records when used in a recursive---   Tensort variant.------   TODO: See if we can clean up the type conversion here.-module Data.Tensort.Utils.Render (getSortedBitsFromTensor) where+module Data.Tensort.Utils.Render (getSortedBits) where  import Data.Maybe (isNothing) import Data.Tensort.Utils.Compose (createTensor) import Data.Tensort.Utils.Types-  ( Bit,-    BitR,-    Memory (..),-    MemoryR (..),-    SBit (..),-    SMemory (..),-    STensor (..),-    STensorStack,+  ( Memory (..),+    Register,     SortAlg,-    Sortable (..),-    Tensor,-    TensorR,-    TensorStack,-    TensorStackR,+    Tensor (..),+    TopBit,     fromJust,-    fromSTensorBit,-    fromSTensorRec,-    fromSortBit,-    fromSortRec,+    fromRecord,+    fromTensor,   )  -- | Compile a sorted list of Bits from a list of TensorStacks.  -- | ==== __Examples__ -- >>> import Data.Tensort.Subalgorithms.Bubblesort (bubblesort)--- >>> getSortedBitsFromTensor bubblesort (STensorBit ([(0,5),(1,7)],ByteMem [[1,5],[3,7]]))--- [SBitBit 1,SBitBit 3,SBitBit 5,SBitBit 7]--- >>> getSortedBitsFromTensor bubblesort (STensorBit ([(0,8),(1,18)],TensorMem [([(0,7),(1,8)],TensorMem [([(0,3),(1,7)],ByteMem [[1,3],[5,7]]),([(0,4),(1,8)],ByteMem [[2,4],[6,8]])]),([(1,17),(0,18)],TensorMem [([(0,13),(1,18)],ByteMem [[11,13],[15,18]]),([(0,14),(1,17)],ByteMem [[12,14],[16,17]])])]))--- [SBitBit 1,SBitBit 2,SBitBit 3,SBitBit 4,SBitBit 5,SBitBit 6,SBitBit 7,SBitBit 8,SBitBit 11,SBitBit 12,SBitBit 13,SBitBit 14,SBitBit 15,SBitBit 16,SBitBit 17,SBitBit 18]-getSortedBitsFromTensor :: SortAlg -> STensorStack -> [SBit]-getSortedBitsFromTensor subAlg (STensorBit tensorRaw) =-  getSortedBitsFromTensorB subAlg tensorRaw-getSortedBitsFromTensor subAlg (STensorRec tensorRaw) =-  getSortedBitsFromTensorR subAlg tensorRaw--getSortedBitsFromTensorB :: SortAlg -> TensorStack -> [SBit]-getSortedBitsFromTensorB subAlg tensorRaw = acc tensorRaw []-  where-    acc :: TensorStack -> [SBit] -> [SBit]-    acc tensor sortedBits = do-      let (nextBit, tensor') = removeTopBitFromTensorB subAlg tensor-      let nextBit' = SBitBit nextBit-      if isNothing tensor'-        then nextBit' : sortedBits-        else do-          acc (fromJust tensor') (nextBit' : sortedBits)--getSortedBitsFromTensorR :: SortAlg -> TensorStackR -> [SBit]-getSortedBitsFromTensorR subAlg tensorRaw = acc tensorRaw []+-- >>> import Data.Tensort.Utils.Types (Record (..))+-- >>> getSortedBits bubblesort (Tensor ([Record (0,5),Record (1,7)],ByteMem [[1,5],[3,7]]))+-- [1,3,5,7]+-- >>> getSortedBits bubblesort (Tensor ([(0,8),(1,18)],TensorMem [([(0,7),(1,8)],TensorMem [([(0,3),(1,7)],ByteMem [[1,3],[5,7]]),([(0,4),(1,8)],ByteMem [[2,4],[6,8]])]),([(1,17),(0,18)],TensorMem [([(0,13),(1,18)],ByteMem [[11,13],[15,18]]),([(0,14),(1,17)],ByteMem [[12,14],[16,17]])])]))+-- [1,2,3,4,5,6,7,8,11,12,13,14,15,16,17,18]+getSortedBits :: (Ord a) => SortAlg a -> Tensor a -> [a]+getSortedBits subAlg tensorRaw = acc (fromTensor tensorRaw) []   where-    acc :: TensorStackR -> [SBit] -> [SBit]-    acc tensor sortedBits = do-      let (nextBit, tensor') = removeTopBitFromTensorR subAlg tensor-      let nextBit' = SBitRec nextBit+    acc tensor sortedBits =       if isNothing tensor'         then nextBit' : sortedBits-        else do-          acc (fromJust tensor') (nextBit' : sortedBits)+        else acc (fromJust tensor') (nextBit' : sortedBits)+      where+        (nextBit, tensor') = removeTopBit subAlg tensor+        nextBit' = nextBit  -- | For use in compiling a list of Tensors into a sorted list of Bits. --@@ -78,104 +41,56 @@  -- | ==== __Examples__ --   >>> import Data.Tensort.Subalgorithms.Bubblesort (bubblesort)---   >>> removeTopBitFromTensorB bubblesort ([(0,5),(1,7)],ByteMem [[1,5],[3,7]])+--   >>> import Data.Tensort.Utils.Types (Record (..))+--   >>> removeTopBit bubblesort ([Record (0,5),Record (1,7)],ByteMem [[1,5],[3,7]]) --   (7,Just ([(1,3),(0,5)],ByteMem [[1,5],[3]]))-removeTopBitFromTensorB :: SortAlg -> Tensor -> (Bit, Maybe Tensor)-removeTopBitFromTensorB subAlg (register, memory) = do-  let topRecord = last register-  let topAddress = fst topRecord-  let (topBit, memory') = removeBitFromMemoryB subAlg memory topAddress-  if isNothing memory'-    then (topBit, Nothing)-    else-      ( topBit,-        Just-          ( fromSTensorBit-              ( createTensor-                  subAlg-                  (SMemoryBit (fromJust memory'))-              )-          )-      )--removeTopBitFromTensorR :: SortAlg -> TensorR -> (BitR, Maybe TensorR)-removeTopBitFromTensorR subAlg (register, memory) = do-  let topRecord = last register-  let topAddress = fst topRecord-  let (topBit, memory') = removeBitFromMemoryR subAlg memory topAddress+removeTopBit :: (Ord a) => SortAlg a -> (Register a, Memory a) -> (TopBit a, Maybe (Register a, Memory a))+removeTopBit subAlg (register, memory) =   if isNothing memory'     then (topBit, Nothing)-    else-      ( topBit,-        Just-          ( fromSTensorRec-              ( createTensor-                  subAlg-                  (SMemoryRec (fromJust memory'))-              )-          )-      )+    else (topBit, tensor)+  where+    (topBit, memory') = removeBit subAlg memory topAddress+    topRecord = last register+    topAddress = snd $ fromRecord topRecord+    tensor = Just tensorRaw+    tensorRaw = fromTensor $ createTensor subAlg memRefined+    memRefined = fromJust memory' -removeBitFromMemoryB :: SortAlg -> Memory -> Int -> (Bit, Maybe Memory)-removeBitFromMemoryB subAlg (ByteMem bytes) i = do-  let topByte = bytes !! i-  let topBit = last topByte-  let topByte' = init topByte+removeBit :: (Ord a) => SortAlg a -> Memory a -> Int -> (TopBit a, Maybe (Memory a))+removeBit subAlg (ByteMem bytes) i =   case length topByte' of-    0 -> do-      let bytes' = take i bytes ++ drop (i + 1) bytes-      if null bytes'-        then (topBit, Nothing)-        else (topBit, Just (ByteMem bytes'))-    1 -> do-      let bytes' = take i bytes ++ [topByte'] ++ drop (i + 1) bytes-      (topBit, Just (ByteMem bytes'))-    _ -> do-      let topByte'' = fromSortBit (subAlg (SortBit topByte'))-      let bytes' = take i bytes ++ [topByte''] ++ drop (i + 1) bytes-      (topBit, Just (ByteMem bytes'))-removeBitFromMemoryB subAlg (TensorMem tensors) i = do-  let topTensor = tensors !! i-  let (topBit, topTensor') = removeTopBitFromTensorB subAlg topTensor-  if isNothing topTensor'-    then do-      let tensors' = take i tensors ++ drop (i + 1) tensors-      if null tensors'-        then (topBit, Nothing)-        else (topBit, Just (TensorMem tensors'))-    else do-      let tensors' =-            take i tensors ++ [fromJust topTensor'] ++ drop (i + 1) tensors-      (topBit, Just (TensorMem tensors'))--removeBitFromMemoryR :: SortAlg -> MemoryR -> Int -> (BitR, Maybe MemoryR)-removeBitFromMemoryR subAlg (ByteMemR bytesR) i = do-  let topByteR = bytesR !! i-  let topBitR = last topByteR-  let topByteR' = init topByteR-  case length topByteR' of-    0 -> do-      let bytesR' = take i bytesR ++ drop (i + 1) bytesR-      if null bytesR'-        then (topBitR, Nothing)-        else (topBitR, Just (ByteMemR bytesR'))-    1 -> do-      let bytesR' = take i bytesR ++ [topByteR'] ++ drop (i + 1) bytesR-      (topBitR, Just (ByteMemR bytesR'))-    _ -> do-      let topByteR'' = fromSortRec (subAlg (SortRec topByteR'))-      let bytesR' = take i bytesR ++ [topByteR''] ++ drop (i + 1) bytesR-      (topBitR, Just (ByteMemR bytesR'))-removeBitFromMemoryR subAlg (TensorMemR tensorsR) i = do-  let topTensorR = tensorsR !! i-  let (topBitR, topTensorR') = removeTopBitFromTensorR subAlg topTensorR-  if isNothing topTensorR'-    then do-      let tensorsR' = take i tensorsR ++ drop (i + 1) tensorsR-      if null tensorsR'-        then (topBitR, Nothing)-        else (topBitR, Just (TensorMemR tensorsR'))-    else do-      let tensorsR' =-            take i tensorsR ++ [fromJust topTensorR'] ++ drop (i + 1) tensorsR-      (topBitR, Just (TensorMemR tensorsR'))+    0 ->+      let bytes' = left ++ right+       in if null bytes'+            then (topBit, Nothing)+            else (topBit, justMem bytes')+    1 ->+      let bytes' = left ++ [topByte'] ++ right+       in (topBit, justMem bytes')+    _ ->+      let bytes' = left ++ [topByte''] ++ right+          topByte'' = subAlg topByte'+       in (topBit, justMem bytes')+  where+    topByte = bytes !! i+    topBit = last topByte+    topByte' = init topByte+    justMem = Just . ByteMem+    left = take i bytes+    right = drop (i + 1) bytes+removeBit subAlg (TensorMem tensors) i+  | isNothing topTensor' =+      let tensors' = left ++ right+       in if null tensors'+            then (topBit, Nothing)+            else (topBit, justMem tensors')+  | otherwise =+      let tensors' = left ++ [Tensor (fromJust topTensor')] ++ right+       in (topBit, justMem tensors')+  where+    topTensor = tensors !! i+    (topBit, topTensor') = removeTopBit subAlg $ fromTensor topTensor+    justMem = Just . TensorMem+    left = take i tensors+    right = drop (i + 1) tensors
− src/Data/Tensort/Utils/SimplifyRegister.hs
@@ -1,40 +0,0 @@--- | This module provides functions to simplify sorting Registers in Tensort---   variants that are sorting Records in their input instead of Bits.-module Data.Tensort.Utils.SimplifyRegister-  ( simplifyRegister,-    applySortingFromSimplifiedRegister,-  )-where--import qualified Data.Bifunctor-import Data.Tensort.Utils.Types (Record, RecordR)---- | For use in Tensort variants that are sorting Records in their input---   instead of Bits.------   This function simplifies the Register used for sorting Records by---   replacing the TopRecord of each RecordR with its TopBit. This returns---   a Register of standard Records that can be used for sorting.-simplifyRegister :: [RecordR] -> [Record]-simplifyRegister = map (Data.Bifunctor.second snd)---- | For use in Tensort variants that are sorting Records in their input---  instead of Bits.------  This function takes a simplified Register that has been sorted and the---  unsimplified, unsorted, original RegisterR. It puts the elements of the---  original RegisterR in the same order as the simplified, sorted Register---  and returns the sorted RegisterR.-applySortingFromSimplifiedRegister :: [Record] -> [RecordR] -> [RecordR]-applySortingFromSimplifiedRegister-  sortedSimplifiedRegister-  unsortedRegiserR = do-    let registerR = acc sortedSimplifiedRegister [] unsortedRegiserR-    registerR-    where-      acc :: [Record] -> [RecordR] -> [RecordR] -> [RecordR]-      acc [] sortedRegisterR _ = sortedRegisterR-      acc (record : remainingRecords) sortedRegisterR unsortedRegiserR' = do-        let i = fst record-        let recordR = head (filter (\(i', _) -> i' == i) unsortedRegiserR')-        acc remainingRecords (sortedRegisterR ++ [recordR]) unsortedRegiserR'
+ src/Data/Tensort/Utils/SortRecs.hs view
@@ -0,0 +1,20 @@+module Data.Tensort.Utils.SortRecs (sortRecs) where++import Data.List (delete)+import Data.Tensort.Utils.Types (Bit, Record (..), SortAlg, fromRecord)++sortRecs :: (Ord a) => SortAlg a -> [Record a] -> [Record a]+sortRecs sortAlg recs =+  let topBits = map (fst . fromRecord) recs+      sortedTopBits = sortAlg topBits+      sortedRecs = orderRecsByTopBits sortedTopBits recs []+   in sortedRecs++orderRecsByTopBits :: (Ord a) => [Bit a] -> [Record a] -> [Record a] -> [Record a]+orderRecsByTopBits [] [] recs' = recs'+orderRecsByTopBits [_] [rec] recs' = recs' ++ [rec]+orderRecsByTopBits (topBit : topBits) recs recs' =+  let rec = head $ filter (\(x, _) -> x == topBit) (map fromRecord recs)+      recs'' = delete rec (map fromRecord recs)+   in orderRecsByTopBits topBits (map Record recs'') (recs' ++ [Record rec])+orderRecsByTopBits _ _ _ = error "orderRecsByTopBits: topBits and recs must be of equal length"
src/Data/Tensort/Utils/Types.hs view
@@ -1,33 +1,30 @@ {-# LANGUAGE GADTs #-}  -- | This module provides types used in the Tensort package.------   Since these packages are only for sorting Ints currently, every data---   type is a structure of Ints. module Data.Tensort.Utils.Types where  -- | TensortProps contains the Bytesize and SubAlgorithm used in a Tensort --   algorithm.-data TensortProps = TensortProps {bytesize :: Int, subAlgorithm :: SortAlg}---- | A Bit is a single element of the list to be sorted. For our current---   purposes that means it is an Int.+data TensortProps a = TensortProps+  { bytesize :: Int,+    subAlgorithm :: SortAlg a+  } ---   The definition of a Bit may be expanded in the future to include any Ord.-type Bit = Int+-- | A Bit is a single element of the list to be sorted.+type Bit a = a  -- | A Byte is a list of Bits standardized to a fixed maximum length (Bytesize).  --   The length should be set either in or upstream of any function that uses --   Bytes.-type Byte = [Bit]+type Byte a = [Bit a]  -- | An Address is a index number pointing to data stored in Memory. type Address = Int  -- | A TopBit contains a copy of the last (i.e. highest) Bit in a Byte or --   Tensor.-type TopBit = Bit+type TopBit a = Bit a  -- | A Record is an element in a Tensor's Register --   containing an Address pointer and a TopBit value.@@ -37,17 +34,28 @@  --   A Record's TopBit is a copy of the last (i.e. highest) Bit in the Byte or --   Tensor that the Record references.-type Record = (Address, TopBit) +--   Records are ordered by their TopBits.+newtype Record a = Record (TopBit a, Address) deriving (Show)++instance (Eq a) => Eq (Record a) where+  (Record (tb1, _)) == (Record (tb2, _)) = tb1 == tb2++instance (Ord a) => Ord (Record a) where+  compare (Record (tb1, _)) (Record (tb2, _)) = compare tb1 tb2++fromRecord :: Record a -> (TopBit a, Address)+fromRecord (Record (tb, a)) = (tb, a)+ -- | A Register is a list of Records allowing for easy access to data in a --   Tensor's Memory.-type Register = [Record]+type Register a = [Record a]  -- | A Memory contains the data to be sorted, either in the form of Bytes or --   Tensors.-data Memory-  = ByteMem [Byte]-  | TensorMem [Tensor]+data Memory a+  = ByteMem [Byte a]+  | TensorMem [Tensor a]   deriving (Show, Eq, Ord)  -- | A Tensor contains data to be sorted in a structure allowing for@@ -57,257 +65,31 @@ --   contains.  --   The Register is a list of Records referencing the top Bits in Memory.-type Tensor = (Register, Memory)+newtype Tensor a = Tensor (Register a, Memory a) deriving (Show, Eq, Ord) +fromTensor :: Tensor a -> (Register a, Memory a)+fromTensor (Tensor (r, ByteMem m)) = (r, ByteMem m)+fromTensor (Tensor (r, TensorMem m)) = (r, TensorMem m)+ -- | A TensorStack is a top-level Tensor. In the final stages of Tensort, the --   number of TensorStacks will be equal to (or sometimes less than) the --   bytesize, but before that time there are expected to be many more --   TensorStacks.-type TensorStack = Tensor---- | We use a Sortable type to sort list of Bits and lists of Records.-data Sortable-  = SortBit [Bit]-  | SortRec [Record]-  deriving (Show, Eq, Ord)---- | Converts a Sortable list to a list of Bits.-fromSortBit :: Sortable -> [Bit]-fromSortBit (SortBit bits) = bits-fromSortBit (SortRec _) =-  error-    "From fromSortBit: This is for sorting Bits - you gave me Records"---- | Converts a Sortable list to a list of Records.-fromSortRec :: Sortable -> [Record]-fromSortRec (SortRec recs) = recs-fromSortRec (SortBit _) =-  error-    "From fromSortRec: This is for sorting Records - you gave me Bits"+type TensorStack a = Tensor a --- | A sorting algorithm is a function that takes a Sortable and returns a---   sorted Sortable.-type SortAlg = Sortable -> Sortable+-- | A sorting algorithm is a function that takes a list of ordered elements+--   and returns that list sorted.+type SortAlg a = [a] -> [a]  -- | SupersortProps consist of three sorting algorithms to adjuditcate between --   and a SupersortStrat that does the adjudication.-type SupersortProps = (SortAlg, SortAlg, SortAlg, SupersortStrat)+type SupersortProps a = (SortAlg a, SortAlg a, SortAlg a, SupersortStrat a) --- | A SupersortStrat takes three Sortables and determines which of the three+-- | A SupersortStrat takes three lists and determines which of the three --   is most likely to be in the correct order.-type SupersortStrat = (Sortable, Sortable, Sortable) -> Sortable+type SupersortStrat a = ([a], [a], [a]) -> [a]  -- | Converts a Maybe into a value or throws an error if the Maybe is Nothing. fromJust :: Maybe a -> a fromJust (Just x) = x fromJust Nothing = error "fromJust: Nothing"------------------------------------------- Types used for recursive Tensort --------------------------------------------- | This is a `Bit` type that is used when sorting Records in a recursive---   Tensort variant.-type BitR = Record---- | This is a conversion type that allows for sorting both Bits and Records.---   It is useful in recursive Tensort variants.-data SBit-  = SBitBit Bit-  | SBitRec Record-  deriving (Show, Eq, Ord)---- | Converts an SBit into a Bit.-fromSBitBit :: SBit -> Bit-fromSBitBit (SBitBit bit) = bit-fromSBitBit (SBitRec _) =-  error-    "From fromSBitBit: This is for sorting Bits - you gave me Records"---- | Converts an SBit into a Record.-fromSBitRec :: SBit -> Record-fromSBitRec (SBitRec record) = record-fromSBitRec (SBitBit _) =-  error-    "From fromSBitRec: This is for sorting Records - you gave me Bits"---- | Converts a list of Bits into a Sortable.-fromSBitBits :: [SBit] -> Sortable-fromSBitBits = SortBit . map fromSBitBit---- | Converts a list of Records into a Sortable.-fromSBitRecs :: [SBit] -> Sortable-fromSBitRecs = SortRec . map fromSBitRec---- | This is a `Byte` type that is used when sorting Records in a recursive---   Tensort variant.-type ByteR = [Record]---- | This is a conversion type that allows for sorting both Bits and Records.---   It is useful in recursive Tensort variants.-data SBytes-  = SBytesBit [Byte]-  | SBytesRec [ByteR]-  deriving (Show, Eq, Ord)---- | Converts an SBytes list into a list of Bytes.-fromSBytesBit :: SBytes -> [[Bit]]-fromSBytesBit (SBytesBit bits) = bits-fromSBytesBit (SBytesRec _) =-  error-    "From fromSBytesBit: This is for sorting Bits - you gave me Records"---- | Converts an SBytes list into a list of ByteRs.-fromSBytesRec :: SBytes -> [[Record]]-fromSBytesRec (SBytesRec recs) = recs-fromSBytesRec (SBytesBit _) =-  error-    "From fromSBytesRec: This is for sorting Records - you gave me Bits"---- | This is a `TopBit` type that is used when sorting Records in a recursive---   Tensort variant.-type TopBitR = Record---- | This is a `Record` type that is used when sorting Records in a recursive---   Tensort variant.-type RecordR = (Address, TopBitR)---- | This is a conversion type that allows for sorting both Records and Bits.---   It is useful in recursive Tensort variants.-data SRecord-  = SRecordBit Record-  | SRecordRec RecordR-  deriving (Show, Eq, Ord)---- | Converts an SRecord into a Record.-fromSRecordBit :: SRecord -> Record-fromSRecordBit (SRecordBit record) = record-fromSRecordBit (SRecordRec _) =-  error-    "From fromSRecordBit: This is for sorting Records - you gave me Bits"---- | Converts an SRecord into a RecordR.-fromSRecordRec :: SRecord -> RecordR-fromSRecordRec (SRecordRec record) = record-fromSRecordRec (SRecordBit _) =-  error-    "From fromSRecordRec: This is for sorting Bits - you gave me Records"---- | This is a conversion type that allows for sorting both Records and Bits.---   It is useful in recursive Tensort variants.-data SRecords-  = SRecordsBit [Record]-  | SRecordsRec [RecordR]-  deriving (Show, Eq, Ord)---- | Converts an SRecords list into a list of Records.-fromSRecordsBit :: SRecords -> [Record]-fromSRecordsBit (SRecordsBit records) = records-fromSRecordsBit (SRecordsRec _) =-  error-    "From fromSRecordsBit: This is for sorting Records - you gave me Bits"---- | Converts an SRecords list into a list of RecordRs.-fromSRecordsRec :: SRecords -> [RecordR]-fromSRecordsRec (SRecordsRec records) = records-fromSRecordsRec (SRecordsBit _) =-  error-    "From fromSRecordsRec: This is for sorting Bits - you gave me Records"---- | Converts a list of SRecords into a list of Records.-fromSRecordArrayBit :: [SRecord] -> [Record]-fromSRecordArrayBit = map fromSRecordBit---- | Converts a list of SRecords into a list of RecordRs.-fromSRecordArrayRec :: [SRecord] -> [RecordR]-fromSRecordArrayRec = map fromSRecordRec---- | This is a `Register` type that is used when sorting Records in a recursive---   Tensort variant.-type RegisterR = [RecordR]---- | This is a `Memory` type that is used when sorting Records in a recursive---   Tensort variant.-data MemoryR-  = ByteMemR [ByteR]-  | TensorMemR [TensorR]-  deriving (Show, Eq, Ord)---- | This is a conversion type that allows for sorting both Bits and Records.---   It is useful in recursive Tensort variants.-data SMemory-  = SMemoryBit Memory-  | SMemoryRec MemoryR-  deriving (Show, Eq, Ord)---- | Converts an SMemory to a Memory.-fromSMemoryBit :: SMemory -> Memory-fromSMemoryBit (SMemoryBit memory) = memory-fromSMemoryBit (SMemoryRec _) =-  error-    "From fromSTensorsRec: This is for sorting Bits - you gave me Records"---- | Converts an SMemory to a MemoryR.-fromSMemoryRec :: SMemory -> MemoryR-fromSMemoryRec (SMemoryRec memory) = memory-fromSMemoryRec (SMemoryBit _) =-  error-    "From fromSMemoryRec: This is for sorting Records - you gave me Bits"---- | This is a `Tensor` type that is used when sorting Records in a recursive---   Tensort variant.-type TensorR = (RegisterR, MemoryR)---- | This is a conversion type that allows for sorting both Bits and Records.---   It is useful in recursive Tensort variants.-data STensor-  = STensorBit Tensor-  | STensorRec TensorR-  deriving (Show, Eq, Ord)---- | Converts an STensor into a Tensor.-fromSTensorBit :: STensor -> Tensor-fromSTensorBit (STensorBit tensor) = tensor-fromSTensorBit (STensorRec _) =-  error-    "From fromSTensorBit: This is for sorting Tensors - you gave me Records"---- | Converts an STensor into a TensorR.-fromSTensorRec :: STensor -> TensorR-fromSTensorRec (STensorRec tensor) = tensor-fromSTensorRec (STensorBit _) =-  error-    "From fromSTensorRec: This is for sorting Records - you gave me Tensors"---- | This is a conversion type that allows for sorting both Bits and Records.---   It is useful in recursive Tensort variants.-data STensors-  = STensorsBit [Tensor]-  | STensorsRec [TensorR]-  deriving (Show, Eq, Ord)---- | Converts an STensors list into a list of Tensors.-fromSTensorsBit :: STensors -> [Tensor]-fromSTensorsBit (STensorsBit tensors) = tensors-fromSTensorsBit (STensorsRec _) =-  error-    "From fromSTensorsBit: This is for sorting Tensors - you gave me Records"---- | Converts an STensors list into a list of TensorRs.-fromSTensorsRec :: STensors -> [TensorR]-fromSTensorsRec (STensorsRec tensors) = tensors-fromSTensorsRec (STensorsBit _) =-  error-    "From fromSTensorsRec: This is for sorting Records - you gave me Tensors"---- | This is a `TensorStack` type that is used when sorting Records in a---   recursive Tensort variant.-type TensorStackR = TensorR---- | This is a conversion type that allows for sorting both Tensors and---   Records. It is useful in recursive Tensort variants.-type STensorStack = STensor---- | This is a conversion type that allows for sorting both Tensors and---   Records. It is useful in recursive Tensort variants.-type STensorStacks = STensors
− src/Data/Tensort/Utils/WrapSortAlg.hs
@@ -1,19 +0,0 @@--- | This module provides convenience functions to wrap sorting algorithms---   that use the Sortable type so they can be used without worrying about---   type conversion.-module Data.Tensort.Utils.WrapSortAlg-  ( wrapSortAlg,-  )-where--import Data.Tensort.Utils.Types (Bit, SortAlg, Sortable (SortBit), fromSortBit)---- | Wraps a sorting algorithm that uses the Sortable type so it can be used---   to sort Bits without worrying about type conversion.---- | ==== __Examples__---  >>> import Data.Tensort.Robustsort (robustsortM)---  >>> (wrapSortAlg robustsortM) [16, 23, 4, 8, 15, 42]---  [4,8,15,16,23,42]-wrapSortAlg :: SortAlg -> ([Bit] -> [Bit])-wrapSortAlg sortAlg xs = fromSortBit (sortAlg (SortBit xs))
tensort.cabal view
@@ -20,7 +20,7 @@ -- PVP summary:     +-+------- breaking API changes --                  | | +----- non-breaking API additions --                  | | | +--- code changes with no API change-version:            1.0.1.4+version:            1.1.0.0  tested-with:        GHC==9.12.1,                      GHC==9.10.1, @@ -48,9 +48,8 @@ -- A longer description of the package. description:        A tunable tensor-based structure for sorting algorithms                      along with various sample configurations. Birthed from an -                    exploration of robustness in algorithms for sorting -                    integers, inspired by -                    [Beyond Efficiency](https://www.cs.unm.edu/~ackley/be-201301131528.pdf) +                    exploration of robustness in sorting algorithms, inspired+                    by [Beyond Efficiency](https://www.cs.unm.edu/~ackley/be-201301131528.pdf)                      by David H. Ackley and                      [Beyond Efficiency by Dave Ackley](https://futureofcoding.org/episodes/070)                      by Future of Coding.@@ -116,17 +115,15 @@                       Data.Tensort.Utils.LogNat,                       Data.Tensort.Utils.MkTsProps,                       Data.Tensort.Utils.RandomizeList,+                      Data.Tensort.Utils.SortRecs,                       Data.Tensort.Utils.Types,-                      Data.Tensort.Utils.WrapSortAlg,      -- Modules included in this library but not exported.     other-modules:    Data.Tensort.Utils.Split,-                      Data.Tensort.Utils.ComparisonFunctions,                       Data.Tensort.Utils.Convert,                       Data.Tensort.Utils.Compose,                       Data.Tensort.Utils.Reduce,                       Data.Tensort.Utils.Render,-                      Data.Tensort.Utils.SimplifyRegister,      -- LANGUAGE extensions used by modules in this package.     -- other-extensions:
test/Main.hs view
@@ -3,7 +3,7 @@ module Main (main) where  import Test.QCheck-import Test.SortSpec (result_is_sorted_custom_bitsize)+import Test.SortSpec (result_is_sorted_custom_bitsize_ints) import Test.SortingAlgorithms import Test.TestCheck (check) @@ -11,12 +11,26 @@ --   suite to fail if any of the individual tests fail main :: IO () main = do-  mapM_ qcheckSortable sortingAlgorithmsSortable-  mapM_ qcheckSortableShort sortingAlgorithmsSortableShort-  mapM_ qcheckSortableTiny sortingAlgorithmsSortableTiny-  mapM_ qcheckBits sortingAlgorithmsBits+  mapM_ qcheckBitsInt sortingAlgorithms+  mapM_ qcheckRecsInt sortingAlgorithms+  mapM_ qcheckRecsShortInt sortingAlgorithmsShort+  mapM_ qcheckRecsTinyInt sortingAlgorithmsTiny+  mapM_ qcheckBitsOnlyInt sortingAlgorithmsBitsOnly+  mapM_ qcheckBitsInteger sortingAlgorithms+  mapM_ qcheckBitsFloat sortingAlgorithms+  mapM_ qcheckBitsDouble sortingAlgorithms+  mapM_ qcheckBitsRational sortingAlgorithms+  mapM_ qcheckBitsChar sortingAlgorithms+  mapM_ qcheckBitsString sortingAlgorithms+  mapM_ qcheckBitsBool sortingAlgorithms+  mapM_ qcheckBitsWord sortingAlgorithms+  mapM_ qcheckBitsOrdering sortingAlgorithms+  mapM_ qcheckBitsMaybe sortingAlgorithms+  mapM_ qcheckBitsEither sortingAlgorithms+  mapM_ qcheckBitsTuple sortingAlgorithms+  mapM_ qcheckBitsList sortingAlgorithms   putStrLn "Running test suite!"   putStrLn "Standard Custom Bitsize Tensort returns a sorted array..."-  check result_is_sorted_custom_bitsize+  check result_is_sorted_custom_bitsize_ints   putStrLn "True!"   putStrLn "All tests pass!"
test/Test/QCheck.hs view
@@ -1,42 +1,139 @@ module Test.QCheck-  ( qcheckSortable,-    qcheckSortableShort,-    qcheckSortableTiny,-    qcheckBits,+  ( qcheckBitsInt,+    qcheckRecsShortInt,+    qcheckRecsTinyInt,+    qcheckBitsOnlyInt,+    qcheckRecsInt,+    qcheckBitsChar,+    qcheckBitsString,+    qcheckBitsList,+    qcheckBitsFloat,+    qcheckBitsDouble,+    qcheckBitsInteger,+    qcheckBitsRational,+    qcheckBitsBool,+    qcheckBitsWord,+    qcheckBitsOrdering,+    qcheckBitsMaybe,+    qcheckBitsEither,+    qcheckBitsTuple,   ) where -import Data.Tensort.Utils.Types (Bit, SortAlg)+import Data.Tensort.Utils.Types (SortAlg) import Test.SortSpec-  ( result_is_sorted_bits,-    result_is_sorted_bits_only,-    result_is_sorted_records,-    result_is_sorted_records_short,-    result_is_sorted_records_tiny,+  ( result_is_sorted_bits_only_ints,+    result_is_sorted_generic,+    result_is_sorted_records_ints,+    result_is_sorted_records_ints_short,+    result_is_sorted_records_ints_tiny,   ) import Test.TestCheck (check) -qcheckSortable :: (SortAlg, String) -> IO ()-qcheckSortable (sort, sortName) = do-  putStrLn (sortName ++ " returns a sorted array..")-  check (result_is_sorted_bits sort)-  check (result_is_sorted_records sort)+qcheckBitsInt :: (SortAlg Int, String) -> IO ()+qcheckBitsInt (sort, sortName) = do+  putStrLn (sortName ++ " returns a sorted array with Ints..")+  check (result_is_sorted_generic sort)   putStrLn "True!" -qcheckSortableShort :: (SortAlg, String) -> IO ()-qcheckSortableShort (sort, sortName) = do-  putStrLn (sortName ++ " returns a sorted array..")-  check (result_is_sorted_records_short sort)+qcheckRecsInt :: (SortAlg (Int, Int), String) -> IO ()+qcheckRecsInt (sort, sortName) = do+  putStrLn (sortName ++ " returns a sorted array with Ints..")+  check (result_is_sorted_records_ints sort)   putStrLn "True!" -qcheckSortableTiny :: (SortAlg, String) -> IO ()-qcheckSortableTiny (sort, sortName) = do-  putStrLn (sortName ++ " returns a sorted array..")-  check (result_is_sorted_records_tiny sort)+qcheckRecsShortInt :: (SortAlg (Int, Int), String) -> IO ()+qcheckRecsShortInt (sort, sortName) = do+  putStrLn (sortName ++ " returns a sorted array with Ints..")+  check (result_is_sorted_records_ints_short sort)   putStrLn "True!" -qcheckBits :: ([Bit] -> [Bit], String) -> IO ()-qcheckBits (sort, sortName) = do-  putStrLn (sortName ++ " returns a sorted array..")-  check (result_is_sorted_bits_only sort)+qcheckRecsTinyInt :: (SortAlg (Int, Int), String) -> IO ()+qcheckRecsTinyInt (sort, sortName) = do+  putStrLn (sortName ++ " returns a sorted array with Ints..")+  check (result_is_sorted_records_ints_tiny sort)+  putStrLn "True!"++qcheckBitsOnlyInt :: ([Int] -> [Int], String) -> IO ()+qcheckBitsOnlyInt (sort, sortName) = do+  putStrLn (sortName ++ " returns a sorted array with Ints..")+  check (result_is_sorted_bits_only_ints sort)+  putStrLn "True!"++qcheckBitsInteger :: (SortAlg Integer, String) -> IO ()+qcheckBitsInteger (sort, sortName) = do+  putStrLn (sortName ++ " returns a sorted array with Integers..")+  check (result_is_sorted_generic sort)+  putStrLn "True!"++qcheckBitsFloat :: (SortAlg Float, String) -> IO ()+qcheckBitsFloat (sort, sortName) = do+  putStrLn (sortName ++ " returns a sorted array with Floats..")+  check (result_is_sorted_generic sort)+  putStrLn "True!"++qcheckBitsDouble :: (SortAlg Double, String) -> IO ()+qcheckBitsDouble (sort, sortName) = do+  putStrLn (sortName ++ " returns a sorted array with Doubles..")+  check (result_is_sorted_generic sort)+  putStrLn "True!"++qcheckBitsRational :: (SortAlg Rational, String) -> IO ()+qcheckBitsRational (sort, sortName) = do+  putStrLn (sortName ++ " returns a sorted array with Rationals..")+  check (result_is_sorted_generic sort)+  putStrLn "True!"++qcheckBitsChar :: (SortAlg Char, String) -> IO ()+qcheckBitsChar (sort, sortName) = do+  putStrLn (sortName ++ " returns a sorted array with Chars..")+  check (result_is_sorted_generic sort)+  putStrLn "True!"++qcheckBitsString :: (SortAlg String, String) -> IO ()+qcheckBitsString (sort, sortName) = do+  putStrLn (sortName ++ " returns a sorted array with Strings..")+  check (result_is_sorted_generic sort)+  putStrLn "True!"++qcheckBitsBool :: (SortAlg Bool, String) -> IO ()+qcheckBitsBool (sort, sortName) = do+  putStrLn (sortName ++ " returns a sorted array with Bools..")+  check (result_is_sorted_generic sort)+  putStrLn "True!"++qcheckBitsWord :: (SortAlg Word, String) -> IO ()+qcheckBitsWord (sort, sortName) = do+  putStrLn (sortName ++ " returns a sorted array with Words..")+  check (result_is_sorted_generic sort)+  putStrLn "True!"++qcheckBitsOrdering :: (SortAlg Ordering, String) -> IO ()+qcheckBitsOrdering (sort, sortName) = do+  putStrLn (sortName ++ " returns a sorted array with Orderings..")+  check (result_is_sorted_generic sort)+  putStrLn "True!"++qcheckBitsMaybe :: (SortAlg (Maybe Int), String) -> IO ()+qcheckBitsMaybe (sort, sortName) = do+  putStrLn (sortName ++ " returns a sorted array with Maybes..")+  check (result_is_sorted_generic sort)+  putStrLn "True!"++qcheckBitsEither :: (SortAlg (Either Int Char), String) -> IO ()+qcheckBitsEither (sort, sortName) = do+  putStrLn (sortName ++ " returns a sorted array with Eithers..")+  check (result_is_sorted_generic sort)+  putStrLn "True!"++qcheckBitsTuple :: (SortAlg (Int, Int), String) -> IO ()+qcheckBitsTuple (sort, sortName) = do+  putStrLn (sortName ++ " returns a sorted array with Tuples..")+  check (result_is_sorted_generic sort)+  putStrLn "True!"++qcheckBitsList :: (SortAlg [Int], String) -> IO ()+qcheckBitsList (sort, sortName) = do+  putStrLn (sortName ++ " returns a sorted array with Lists..")+  check (result_is_sorted_generic sort)   putStrLn "True!"
test/Test/SortSpec.hs view
@@ -1,90 +1,118 @@+{-# OPTIONS_GHC -Wno-unrecognised-pragmas #-}++{-# HLINT ignore "Use camelCase" #-} module Test.SortSpec-  ( result_is_sorted_bits,-    result_is_sorted_bits_short,-    result_is_sorted_bits_tiny,-    result_is_sorted_records,-    result_is_sorted_records_short,-    result_is_sorted_records_tiny,-    result_is_sorted_custom_bitsize,-    result_is_sorted_bits_only,-    result_is_sorted_bits_only_short,+  ( result_is_sorted_ints,+    result_is_sorted_ints_short,+    result_is_sorted_ints_tiny,+    result_is_sorted_records_ints,+    result_is_sorted_records_ints_short,+    result_is_sorted_records_ints_tiny,+    result_is_sorted_custom_bitsize_ints,+    result_is_sorted_bits_only_ints,+    result_is_sorted_bits_only_ints_short,+    result_is_sorted_chars,+    result_is_sorted_strings,+    result_is_sorted_lists,+    result_is_sorted_generic,   ) where  import Data.Tensort.Tensort (tensortBN) import Data.Tensort.Utils.Check (isSorted)-import Data.Tensort.Utils.Types (Bit, Record, SortAlg, Sortable (..))+import Data.Tensort.Utils.Types (SortAlg) import Test.QuickCheck -result_is_sorted_bits :: SortAlg -> [Bit] -> Property-result_is_sorted_bits sort unsortedList =-  within-    1000000-    ( (length unsortedList < 10)-        ==> isSorted (sort (SortBit unsortedList))-    )+result_is_sorted_ints :: SortAlg Int -> [Int] -> Property+result_is_sorted_ints sort unsortedList =+  within limitStd (constraint ==> success)+  where+    constraint = length unsortedList < 10+    success = isSorted $ sort unsortedList -result_is_sorted_bits_short :: SortAlg -> [Bit] -> Property-result_is_sorted_bits_short sort unsortedList =-  within-    1000000-    ( (length unsortedList < 6)-        ==> isSorted (sort (SortBit unsortedList))-    )+result_is_sorted_ints_short :: SortAlg Int -> [Int] -> Property+result_is_sorted_ints_short sort unsortedList =+  within limitStd (constraint ==> success)+  where+    constraint = length unsortedList < 6+    success = isSorted $ sort unsortedList -result_is_sorted_bits_tiny :: SortAlg -> [Bit] -> Property-result_is_sorted_bits_tiny sort unsortedList =-  within-    1000000-    ( (length unsortedList < 3)-        ==> isSorted (sort (SortBit unsortedList))-    )+result_is_sorted_ints_tiny :: SortAlg Int -> [Int] -> Property+result_is_sorted_ints_tiny sort unsortedList =+  within limitStd (constraint ==> success)+  where+    constraint = length unsortedList < 3+    success = isSorted $ sort unsortedList -result_is_sorted_records :: SortAlg -> [Record] -> Property-result_is_sorted_records sort unsortedList =-  within-    1000000-    ( (length unsortedList < 10)-        ==> isSorted (sort (SortRec unsortedList))-    )+result_is_sorted_records_ints :: SortAlg (Int, Int) -> [(Int, Int)] -> Property+result_is_sorted_records_ints sort unsortedList =+  within limitStd (constraint ==> success)+  where+    constraint = length unsortedList < 10+    success = isSorted $ sort unsortedList -result_is_sorted_records_short :: SortAlg -> [Record] -> Property-result_is_sorted_records_short sort unsortedList =-  within-    1000000-    ( (length unsortedList < 6)-        ==> isSorted (sort (SortRec unsortedList))-    )+result_is_sorted_records_ints_short :: SortAlg (Int, Int) -> [(Int, Int)] -> Property+result_is_sorted_records_ints_short sort unsortedList =+  within limitStd (constraint ==> success)+  where+    constraint = length unsortedList < 6+    success = isSorted $ sort unsortedList -result_is_sorted_records_tiny :: SortAlg -> [Record] -> Property-result_is_sorted_records_tiny sort unsortedList =-  within-    1000000-    ( (length unsortedList < 3)-        ==> isSorted (sort (SortRec unsortedList))-    )+result_is_sorted_records_ints_tiny :: SortAlg (Int, Int) -> [(Int, Int)] -> Property+result_is_sorted_records_ints_tiny sort unsortedList =+  within limitStd (constraint ==> success)+  where+    constraint = length unsortedList < 3+    success = isSorted $ sort unsortedList -result_is_sorted_custom_bitsize :: Int -> [Bit] -> Property-result_is_sorted_custom_bitsize n unsortedList =-  within-    1000000-    ( (length unsortedList < 15)-        && (n > 1)-          ==> isSorted (tensortBN n (SortBit unsortedList))-    )+result_is_sorted_custom_bitsize_ints :: Int -> [Int] -> Property+result_is_sorted_custom_bitsize_ints n unsortedList =+  within limitStd (constraint ==> success)+  where+    constraint = (length unsortedList < 15) && (n > 1)+    success = isSorted (tensortBN n unsortedList) -result_is_sorted_bits_only :: ([Bit] -> [Bit]) -> [Bit] -> Property-result_is_sorted_bits_only sort unsortedList =-  within-    1000000-    ( (length unsortedList < 10)-        ==> isSorted (SortBit (sort unsortedList))-    )+result_is_sorted_bits_only_ints :: ([Int] -> [Int]) -> [Int] -> Property+result_is_sorted_bits_only_ints sort unsortedList =+  within limitStd (constraint ==> success)+  where+    constraint = length unsortedList < 10+    success = isSorted $ sort unsortedList -result_is_sorted_bits_only_short :: ([Bit] -> [Bit]) -> [Bit] -> Property-result_is_sorted_bits_only_short sort unsortedList =-  within-    1000000-    ( (length unsortedList < 6)-        ==> isSorted (SortBit (sort unsortedList))-    )+result_is_sorted_bits_only_ints_short :: ([Int] -> [Int]) -> [Int] -> Property+result_is_sorted_bits_only_ints_short sort unsortedList =+  within limitStd (constraint ==> success)+  where+    constraint = length unsortedList < 6+    success = isSorted $ sort unsortedList++result_is_sorted_chars :: SortAlg Char -> [Char] -> Property+result_is_sorted_chars sort unsortedList =+  within limitStd (constraint ==> success)+  where+    constraint = length unsortedList < 10+    success = isSorted $ sort unsortedList++result_is_sorted_strings :: SortAlg String -> [String] -> Property+result_is_sorted_strings sort unsortedList =+  within limitStd (constraint ==> success)+  where+    constraint = length unsortedList < 10+    success = isSorted $ sort unsortedList++result_is_sorted_lists :: (Ord a) => SortAlg [a] -> [[a]] -> Property+result_is_sorted_lists sort unsortedList =+  within limitStd (constraint ==> success)+  where+    constraint = length unsortedList < 10+    success = isSorted $ sort unsortedList++result_is_sorted_generic :: (Ord a) => SortAlg a -> [a] -> Property+result_is_sorted_generic sort unsortedList =+  within limitStd (constraint ==> success)+  where+    constraint = length unsortedList < 10+    success = isSorted $ sort unsortedList++limitStd :: Int+limitStd = 1000000
test/Test/SortingAlgorithms.hs view
@@ -1,8 +1,8 @@ module Test.SortingAlgorithms-  ( sortingAlgorithmsSortable,-    sortingAlgorithmsSortableShort,-    sortingAlgorithmsSortableTiny,-    sortingAlgorithmsBits,+  ( sortingAlgorithms,+    sortingAlgorithmsShort,+    sortingAlgorithmsTiny,+    sortingAlgorithmsBitsOnly,   ) where @@ -38,12 +38,12 @@   ) import Data.Tensort.Tensort (tensort, tensortB4, tensortBL) import Data.Tensort.Utils.MkTsProps (mkTsProps)-import Data.Tensort.Utils.Types (Bit, SortAlg, Sortable)+import Data.Tensort.Utils.Types (SortAlg) -tensortCustomExample :: Sortable -> Sortable+tensortCustomExample :: (Ord a) => [a] -> [a] tensortCustomExample = tensort (mkTsProps 8 mergesort) -supersortMundaneCustomExample :: Sortable -> Sortable+supersortMundaneCustomExample :: (Ord a) => [a] -> [a] supersortMundaneCustomExample =   supersort     ( quicksort,@@ -52,7 +52,7 @@       mundaneSuperStrat     ) -supersortMagicCustomExample :: Sortable -> Sortable+supersortMagicCustomExample :: (Ord a) => [a] -> [a] supersortMagicCustomExample =   supersort     ( bogosort,@@ -61,18 +61,18 @@       magicSuperStrat     ) -robustsortMundaneCustomExample :: Sortable -> Sortable+robustsortMundaneCustomExample :: (Ord a) => [a] -> [a] robustsortMundaneCustomExample =   tensort     (mkTsProps 3 supersortMundaneCustomExample) -robustsortMagicCustomExample :: Sortable -> Sortable+robustsortMagicCustomExample :: (Ord a) => [a] -> [a] robustsortMagicCustomExample =   tensort     (mkTsProps 3 supersortMagicCustomExample) -sortingAlgorithmsSortable :: [(SortAlg, String)]-sortingAlgorithmsSortable =+sortingAlgorithms :: (Ord a) => [(SortAlg a, String)]+sortingAlgorithms =   [ (quicksort, "Quicksort"),     (mergesort, "Mergesort"),     (bubblesort, "Bubblesort"),@@ -91,8 +91,8 @@     (robustsortRM, "Recursive Magic Robustsort")   ] -sortingAlgorithmsSortableShort :: [(SortAlg, String)]-sortingAlgorithmsSortableShort =+sortingAlgorithmsShort :: (Ord a) => [(SortAlg a, String)]+sortingAlgorithmsShort =   [ (bogosort, "Bogosort"),     (magicsort, "Magicsort"),     (robustsortP, "Standard Mundane Robustsort with Permutationsort adjudicator"),@@ -102,16 +102,16 @@     (supersortMagicCustomExample, "Custom Magic Supersort")   ] -sortingAlgorithmsSortableTiny :: [(SortAlg, String)]-sortingAlgorithmsSortableTiny =+sortingAlgorithmsTiny :: (Ord a) => (Ord a) => [(SortAlg a, String)]+sortingAlgorithmsTiny =   [ (rotationsort, "Rotationsort"),     (rotationsortReverse, "Reverse Rotationsort"),     (rotationsortAmbi, "Ambidextrous Rotationsort"),     (rotationsortReverseAmbi, "Reverse Ambidextrous Rotationsort")   ] -sortingAlgorithmsBits :: [([Bit] -> [Bit], String)]-sortingAlgorithmsBits =+sortingAlgorithmsBitsOnly :: (Ord a) => [([a] -> [a], String)]+sortingAlgorithmsBitsOnly =   [ (Data.Tensort.tensort, "Top-level Tensort"),     ( Data.Robustsort.robustsortP,       "Top-level Mundane Robustsort with Permutationsort adjudicator"