tensort 1.0.0.0 → 1.0.1.0
raw patch · 16 files changed
+503/−242 lines, 16 filesdep −timePVP ok
version bump matches the API change (PVP)
Dependencies removed: time
API changes (from Hackage documentation)
+ Data.Tensort.Utils.LogNat: getLn :: Int -> Int
+ Data.Tensort.Utils.LogNat: getLnBytesize :: Sortable -> Int
Files
- CHANGELOG.md +8/−0
- README.md +1/−1
- src/Data/Robustsort.hs +9/−9
- src/Data/Tensort.hs +1/−1
- src/Data/Tensort/Robustsort.hs +42/−8
- src/Data/Tensort/Subalgorithms/Magicsort.hs +1/−1
- src/Data/Tensort/Tensort.hs +13/−18
- src/Data/Tensort/Utils/Check.hs +8/−3
- src/Data/Tensort/Utils/Compose.hs +85/−22
- src/Data/Tensort/Utils/Convert.hs +17/−3
- src/Data/Tensort/Utils/LogNat.hs +26/−0
- src/Data/Tensort/Utils/Reduce.hs +51/−13
- src/Data/Tensort/Utils/Render.hs +55/−7
- src/Data/Tensort/Utils/SimplifyRegister.hs +12/−10
- src/Data/Tensort/Utils/Types.hs +172/−144
- tensort.cabal +2/−2
CHANGELOG.md view
@@ -64,3 +64,11 @@ * Add more helper functions * 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++* Cleanup and improve documentation++* Cleanup code a bit
README.md view
@@ -20,7 +20,7 @@ alt="When sorting a randomly shuffled deck of cards, Quicksort makes 202 positional errors, Mergesort makes 201, Bubblesort makes 4, Tensort makes 51, Mundane Robustsort makes 11, and Magic Robustsort makes- [CENSORED]">+ [SPOILERS]"> <figcaption><i> Read on for the full data, or <a href="#comparing-it-all">
src/Data/Robustsort.hs view
@@ -24,7 +24,7 @@ -- | Takes a list of Bits and returns a sorted list of Bits using a Basic -- Mundane Robustsort algorithm with a Permutationsort adjudicator ----- | This is a convenience function that wraps the+-- This is a convenience function that wraps the -- 'Data.Tensort.Robustsort.robustsortP' function -- | ==== __Examples__@@ -36,7 +36,7 @@ -- | Takes a list of Bits and returns a sorted list of Bits using a Basic -- Mundane Robustsort algorithm with a Bogosort adjudicator ----- | This is a convenience function that wraps the+-- This is a convenience function that wraps the -- 'Data.Tensort.Robustsort.robustsortB' function -- | ==== __Examples__@@ -48,7 +48,7 @@ -- | Takes a list of Bits and returns a sorted list of Bits using a Basic -- Magic Robustsort algorithm ----- | This is a convenience function that wraps the+-- This is a convenience function that wraps the -- 'Data.Tensort.Robustsort.robustsortM' function -- | ==== __Examples__@@ -60,10 +60,10 @@ -- | Takes a list of Bits and returns a sorted list of Bits using a Recursive -- Mundane Robustsort algorithm with a Permutationsort adjudicator ----- | This is a convenience function that wraps the--- 'Data.Tensort.Robustsort.robustsortRP' function+-- This is a convenience function that wraps the+-- 'Data.Tensort.Robustsort.robustsortRP' function --- | ==== __Examples__+-- | ==== __Examples__ -- >>> robustsortRP [16, 23, 4, 8, 15, 42] -- [4,8,15,16,23,42] robustsortRP :: [Bit] -> [Bit]@@ -72,8 +72,8 @@ -- | Takes a list of Bits and returns a sorted list of Bits using a Recursive -- Mundane Robustsort algorithm with a Bogosort adjudicator ----- | This is a convenience function that wraps the--- 'Data.Tensort.Robustsort.robustsortRB' function+-- This is a convenience function that wraps the+-- 'Data.Tensort.Robustsort.robustsortRB' function -- | ==== __Examples__ -- >>> robustsortRB [16, 23, 4, 8, 15, 42]@@ -84,7 +84,7 @@ -- | Takes a list of Bits and returns a sorted list of Bits using a Recursive -- Magic Robustsort algorithm ----- | This is a convenience function that wraps the+-- This is a convenience function that wraps the -- 'Data.Tensort.Robustsort.robustsortRM' function -- | ==== __Examples__
src/Data/Tensort.hs view
@@ -12,7 +12,7 @@ -- | Takes a list of Bits and returns a sorted list of Bits using a Standard -- Logarithmic Tensort algorithm ----- | This is a convenience function that wraps the 'tensortBL' function+-- This is a convenience function that wraps the 'tensortBL' function -- | ==== __Examples__ -- >>> tensort [16, 23, 4, 8, 15, 42]
src/Data/Tensort/Robustsort.hs view
@@ -26,6 +26,7 @@ supersort, ) 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 (..)) @@ -35,6 +36,9 @@ -- | ==== __Examples__ -- >>> robustsortRP (SortBit [16, 23, 4, 8, 15, 42]) -- SortBit [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 = robustsortRCustom robustsortP @@ -44,6 +48,9 @@ -- | ==== __Examples__ -- >>> robustsortP (SortBit [16, 23, 4, 8, 15, 42]) -- SortBit [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 = tensort (mkTsProps 3 supersortP) @@ -62,6 +69,9 @@ -- | ==== __Examples__ -- >>> robustsortRB (SortBit [16, 23, 4, 8, 15, 42]) -- SortBit [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 = robustsortRCustom robustsortB @@ -71,6 +81,9 @@ -- | ==== __Examples__ -- >>> robustsortB (SortBit [16, 23, 4, 8, 15, 42]) -- SortBit [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 = tensort (mkTsProps 3 supersortB) @@ -89,6 +102,9 @@ -- | ==== __Examples__ -- >>> robustsortRM (SortBit [16, 23, 4, 8, 15, 42]) -- SortBit [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 = robustsortRCustom robustsortM @@ -98,6 +114,9 @@ -- | ==== __Examples__ -- >>> robustsortM (SortBit [16, 23, 4, 8, 15, 42]) -- SortBit [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 = tensort (mkTsProps 3 supersortM) @@ -110,7 +129,29 @@ magicSuperStrat ) --- | Used for making recursive Robustsort algorithms+-- | Used for making recursive Robustsort variants+--+-- Takes the base SortAlg you want to use and a Sortable and returns a sorted+-- Sortable.+--+-- Uses a Logarithmic bytesize to determine when to stop recursing and use+-- the base SortAlg to sort the records.+--+-- Uses the base SortAlg once the bytesize is less than or equal to 27. This+-- number is chosen because it is the natural logarithm of 27 is close to+-- 3 (it's abuot 3.3) and the square root of 27 is 3, so it's likely to be an+-- efficient choice.+--+-- This confiuguration is tailored to using a standard basic Robustsort+-- algorithm (i.e. with a Bytesize of 3) as the base SortAlg. You're welcome+-- 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 (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@@ -119,13 +160,6 @@ (robustsortRecursive (getLnBytesize xs) baseSortAlg) ) xs--getLnBytesize :: Sortable -> Int-getLnBytesize (SortBit xs) = getLn (length xs)-getLnBytesize (SortRec xs) = getLn (length xs)--getLn :: Int -> Int-getLn x = ceiling (log (fromIntegral x) :: Double) robustsortRecursive :: Int -> SortAlg -> SortAlg robustsortRecursive bytesize baseSortAlg
src/Data/Tensort/Subalgorithms/Magicsort.hs view
@@ -11,7 +11,7 @@ -- | Takes a Sortable and returns a sorted Sortable ----- | Adjudicates between three other sorting algorithms to return a robust+-- Adjudicates between three other sorting algorithms to return a robust -- solution -- | ==== __Examples__
src/Data/Tensort/Tensort.hs view
@@ -11,15 +11,21 @@ import Data.Tensort.Subalgorithms.Bubblesort (bubblesort) import Data.Tensort.Utils.Compose (createInitialTensors) import Data.Tensort.Utils.Convert (rawToBytes)+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.Types (Sortable (..), TensortProps (..), fromSBitBits, fromSBitRecs)+import Data.Tensort.Utils.Types+ ( Sortable (..),+ TensortProps (..),+ fromSBitBits,+ fromSBitRecs,+ ) --- | Sort a list of Sortables using a custom Tensort algorithm+-- | Sort a Sortable list using a custom Tensort algorithm ----- | Takes TensortProps and a Sortable and returns a sorted Sortable+-- Takes TensortProps and a Sortable and returns a sorted Sortable -- | ==== __Examples__ -- >>> import Data.Tensort.Subalgorithms.Bubblesort (bubblesort)@@ -49,7 +55,7 @@ let topTensor = reduceTensorStacks tsProps tensorStacks fromSBitRecs (getSortedBitsFromTensor (subAlgorithm tsProps) topTensor) --- | Sort a list of Sortables using a Standard Tensort algorithm with a 4-Bit+-- | Sort a Sortable list using a Standard Tensort algorithm with a 4-Bit -- Bytesize -- | ==== __Examples__@@ -61,7 +67,7 @@ tensortB4 :: Sortable -> Sortable tensortB4 = tensort (mkTsProps 4 bubblesort) --- | Sort a list of Sortables using a Standard Tensort algorithm with a custom+-- | Sort a Sortable list using a Standard Tensort algorithm with a custom -- Bytesize -- | ==== __Examples__@@ -73,7 +79,7 @@ tensortBN :: Int -> Sortable -> Sortable tensortBN n = tensort (mkTsProps n bubblesort) --- | Sort a list of Sortables using a Standard Logarithmic Tensort algorithm+-- | Sort a Sortable list using a Standard Logarithmic Tensort algorithm -- | ==== __Examples__ -- >>> tensortBL (SortBit [16, 23, 4, 8, 15, 42])@@ -82,15 +88,4 @@ -- >>> 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 (calculateBytesize xs) bubblesort) xs---- | Calculate a logarithmic Bytesize from a Sortable---- | ==== __Examples__--- >>> calculateBytesize (SortRec [(1, 16), (5, 23), (2, 4) ,(3, 8), (0, 15) , (4, 42)])--- 2-calculateBytesize :: Sortable -> Int-calculateBytesize (SortBit xs) =- ceiling (log (fromIntegral (length xs)) :: Double)-calculateBytesize (SortRec xs) =- ceiling (log (fromIntegral (length xs)) :: Double)+tensortBL xs = tensort (mkTsProps (getLnBytesize xs) bubblesort) xs
src/Data/Tensort/Utils/Check.hs view
@@ -2,7 +2,10 @@ -- elements is sorted in ascending order. module Data.Tensort.Utils.Check (isSorted) where -import Data.Tensort.Utils.ComparisonFunctions (lessThanOrEqualBit, lessThanOrEqualRecord)+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@@ -17,7 +20,9 @@ isSorted :: Sortable -> Bool isSorted (SortBit []) = True isSorted (SortBit [_]) = True-isSorted (SortBit (x : y : remainingElements)) = lessThanOrEqualBit x y && isSorted (SortBit (y : remainingElements))+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 (SortRec (x : y : remainingElements)) =+ lessThanOrEqualRecord x y && isSorted (SortRec (y : remainingElements))
src/Data/Tensort/Utils/Compose.hs view
@@ -1,3 +1,9 @@+-- | Module for creating Tensors from Bytes and Tensors+--+-- 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,@@ -54,16 +60,26 @@ STensorsRec (createInitialTensorsRecs tsProps recs) createInitialTensorsBits :: TensortProps -> [Byte] -> [Tensor]-createInitialTensorsBits tsProps bytes = foldr acc [] (splitEvery (bytesize tsProps) bytes)+createInitialTensorsBits tsProps bytes =+ foldr acc [] (splitEvery (bytesize tsProps) bytes) where acc :: [Byte] -> [Tensor] -> [Tensor]- acc byte tensorStacks = tensorStacks ++ [fromSTensorBit (getTensorFromBytes (subAlgorithm tsProps) (SBytesBit byte))]+ acc byte tensorStacks =+ tensorStacks+ ++ [ fromSTensorBit+ (getTensorFromBytes (subAlgorithm tsProps) (SBytesBit byte))+ ] createInitialTensorsRecs :: TensortProps -> [ByteR] -> [TensorR]-createInitialTensorsRecs tsProps bytesR = foldr acc [] (splitEvery (bytesize tsProps) bytesR)+createInitialTensorsRecs tsProps bytesR =+ foldr acc [] (splitEvery (bytesize tsProps) bytesR) where acc :: [ByteR] -> [TensorR] -> [TensorR]- acc byteR tensorStacks = tensorStacks ++ [fromSTensorRec (getTensorFromBytes (subAlgorithm tsProps) (SBytesRec byteR))]+ acc byteR tensorStacks =+ tensorStacks+ ++ [ fromSTensorRec+ (getTensorFromBytes (subAlgorithm tsProps) (SBytesRec byteR))+ ] -- | Create a Tensor from a Memory -- Aliases to getTensorFromBytes for ByteMem and getTensorFromTensors for@@ -73,12 +89,16 @@ 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)+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)+createTensorR subAlg (ByteMemR bytesR) =+ getTensorFromBytes subAlg (SBytesRec bytesR)+createTensorR subAlg (TensorMemR tensorsR) =+ getTensorFromTensors subAlg (STensorsRec tensorsR) -- | Convert a list of Bytes to a Tensor @@ -96,8 +116,10 @@ -- >>> 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)+getTensorFromBytes subAlg (SBytesBit bytes) =+ STensorBit (getTensorFromBytesB subAlg bytes)+getTensorFromBytes subAlg (SBytesRec recs) =+ STensorRec (getTensorFromBytesR subAlg recs) getTensorFromBytesB :: SortAlg -> [Byte] -> Tensor getTensorFromBytesB subAlg bytes = do@@ -108,20 +130,24 @@ 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)+ 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+ let registerR' =+ applySortingFromSimplifiedRegister simplifiedRegiser' registerR (registerR', ByteMemR bytesR) 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)+ acc ([] : remainingBytesR) registerR i =+ acc remainingBytesR registerR (i + 1)+ acc (byteR : remainingBytesR) registerR i =+ acc remainingBytesR (registerR ++ [(i, last byteR)]) (i + 1) -- | Create a TensorStack with the collated and sorted References from the -- Tensors as the Register and the original Tensors as the data@@ -131,18 +157,33 @@ -- >>> 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)+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)+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)+ let registerR' =+ applySortingFromSimplifiedRegister+ simplifiedRegiser'+ (fromSRecordArrayRec registerR) (registerR', TensorMemR tensorsR) -- | For each Tensor, produces a Record by combining the top bit of the@@ -164,7 +205,17 @@ acc :: [Tensor] -> [SRecord] -> [SRecord] acc [] records = records acc (([], _) : remainingTensors) records = acc remainingTensors records- acc (tensor : remainingTensors) records = acc remainingTensors (records ++ [SRecordBit (i, fromSBitBit (getTopBitFromTensorStack (STensorBit tensor)))])+ acc (tensor : remainingTensors) records =+ acc+ remainingTensors+ ( records+ ++ [ SRecordBit+ ( i,+ fromSBitBit+ (getTopBitFromTensorStack (STensorBit tensor))+ )+ ]+ ) where i = length records @@ -174,7 +225,17 @@ 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 (tensorR : remainingTensorsR) records =+ acc+ remainingTensorsR+ ( records+ ++ [ SRecordRec+ ( i,+ fromSBitRec+ (getTopBitFromTensorStack (STensorRec tensorR))+ )+ ]+ ) where i = length records @@ -190,8 +251,10 @@ -- >>> 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) = getTopBitFromTensorStackB tensor-getTopBitFromTensorStack (STensorRec tensorR) = getTopBitFromTensorStackR tensorR+getTopBitFromTensorStack (STensorBit tensor) =+ getTopBitFromTensorStackB tensor+getTopBitFromTensorStack (STensorRec tensorR) =+ getTopBitFromTensorStackR tensorR getTopBitFromTensorStackB :: Tensor -> SBit getTopBitFromTensorStackB (register, _) = SBitBit (snd (last register))
src/Data/Tensort/Utils/Convert.hs view
@@ -1,7 +1,19 @@+-- | Module for converting raw input data to SBytes+--+-- TODO: See if we can clean up the type conversion here module Data.Tensort.Utils.Convert (rawToBytes) where import Data.Tensort.Utils.Split (splitEvery)-import Data.Tensort.Utils.Types (Bit, Byte, Record, SBytes (SBytesBit, SBytesRec), Sortable (..), TensortProps (..), fromSortBit, fromSortRec)+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 -- each byte with the given subalgorithm.@@ -19,10 +31,12 @@ rawBitsToBytes tsProps bits = foldr acc [] (splitEvery (bytesize tsProps) bits) where acc :: [Bit] -> [Byte] -> [Byte]- acc byte bytes = bytes ++ [fromSortBit (subAlgorithm tsProps (SortBit byte))]+ acc byte bytes =+ bytes ++ [fromSortBit (subAlgorithm tsProps (SortBit byte))] rawRecsToBytes :: TensortProps -> [Record] -> [[Record]] rawRecsToBytes tsProps recs = foldr acc [] (splitEvery (bytesize tsProps) recs) where acc :: [Record] -> [[Record]] -> [[Record]]- acc rbyte rbytes = rbytes ++ [fromSortRec (subAlgorithm tsProps (SortRec rbyte))]+ acc rbyte rbytes =+ rbytes ++ [fromSortRec (subAlgorithm tsProps (SortRec rbyte))]
+ src/Data/Tensort/Utils/LogNat.hs view
@@ -0,0 +1,26 @@+-- | This module provides functions for calculating the natural logarithms in+-- a way useful for creating logarithmic Bytesizes+module Data.Tensort.Utils.LogNat (getLnBytesize, getLn) where++import Data.Tensort.Utils.Types (Sortable (..))++-- | Calculate a suitable logarithmic Bytesize from a Sortable++-- | ==== __Examples__+-- >>> getLnBytesize (SortBit [1 .. 27])+-- 4+--+-- >>> getLnBytesize (SortRec [(1, 16), (5, 23), (2, 4) ,(3, 8), (0, 15) , (4, 42)])+-- 2+getLnBytesize :: Sortable -> Int+getLnBytesize (SortBit xs) = getLn (length xs)+getLnBytesize (SortRec xs) = getLn (length xs)++-- | Calculate a the natural logarithm of an Int, rounded up to the nearest+-- integer+--+-- | ==== __Examples__+-- >>> getLn 27+-- 4+getLn :: Int -> Int+getLn x = ceiling (log (fromIntegral x) :: Double)
src/Data/Tensort/Utils/Reduce.hs view
@@ -1,3 +1,10 @@+-- | This module provides functions to reduce a list of TensorStacks into a+-- more compact list of TensorStacks+--+-- 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)@@ -20,7 +27,7 @@ -- TensorStacks, each containing bytesize number of Tensors (former -- TensorStacks), until the number of TensorStacks is equal to the bytesize --- | The Registers of the new TensorStacks are bubblesorted, as usual+-- The Registers of the new TensorStacks are bubblesorted, as usual -- | ==== __Examples__ -- >>> import Data.Tensort.Subalgorithms.Bubblesort (bubblesort)@@ -28,41 +35,72 @@ -- >>> 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+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))+ then+ createTensor+ (subAlgorithm tsProps)+ (SMemoryBit (TensorMem newTensorStacks)) else reduceTensorStacksB tsProps newTensorStacks reduceTensorStacksR :: TensortProps -> [TensorStackR] -> STensorStack reduceTensorStacksR tsProps tensorStacks = do let newTensorStacks = reduceTensorStacksRSinglePass tsProps tensorStacks if length newTensorStacks <= bytesize tsProps- then createTensor (subAlgorithm tsProps) (SMemoryRec (TensorMemR newTensorStacks))+ then+ createTensor+ (subAlgorithm tsProps)+ (SMemoryRec (TensorMemR newTensorStacks)) else reduceTensorStacksR tsProps newTensorStacks -- | Take a list of TensorStacks and group them together in new--- TensorStacks each containing bytesize number of Tensors (former TensorStacks)+-- TensorStacks each containing bytesize number of Tensors (former+-- TensorStacks) --- | The Registers of the new TensorStacks are bubblesorted, as usual+-- The Registers of the new TensorStacks are bubblesorted, as usual -- | ==== __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]])])]-reduceTensorStacksSinglePass :: TensortProps -> [TensorStack] -> [TensorStack]-reduceTensorStacksSinglePass tsProps tensorStacks = foldr acc [] (splitEvery (bytesize tsProps) tensorStacks)+reduceTensorStacksSinglePass ::+ TensortProps ->+ [TensorStack] ->+ [TensorStack]+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)))]+ acc tensorStack newTensorStacks =+ newTensorStacks+ ++ [ fromSTensorBit+ ( createTensor+ (subAlgorithm tsProps)+ (SMemoryBit (TensorMem tensorStack))+ )+ ] -reduceTensorStacksRSinglePass :: TensortProps -> [TensorStackR] -> [TensorStackR]-reduceTensorStacksRSinglePass tsProps tensorStacks = foldr acc [] (splitEvery (bytesize tsProps) tensorStacks)+reduceTensorStacksRSinglePass ::+ TensortProps ->+ [TensorStackR] ->+ [TensorStackR]+reduceTensorStacksRSinglePass tsProps tensorStacks =+ foldr acc [] (splitEvery (bytesize tsProps) tensorStacks) where acc :: [TensorStackR] -> [TensorStackR] -> [TensorStackR]- acc tensorStack newTensorStacks = newTensorStacks ++ [fromSTensorRec (createTensor (subAlgorithm tsProps) (SMemoryRec (TensorMemR tensorStack)))]+ acc tensorStack newTensorStacks =+ newTensorStacks+ ++ [ fromSTensorRec+ ( createTensor+ (subAlgorithm tsProps)+ (SMemoryRec (TensorMemR tensorStack))+ )+ ]
src/Data/Tensort/Utils/Render.hs view
@@ -1,8 +1,34 @@+-- | Module for rendering a sorted list of Bits from a list of TensorStacks+--+-- 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 import Data.Maybe (isNothing) import Data.Tensort.Utils.Compose (createTensor)-import Data.Tensort.Utils.Types (Bit, BitR, Memory (..), MemoryR (..), SBit (..), SMemory (..), STensor (..), STensorStack, SortAlg, Sortable (..), Tensor, TensorR, TensorStack, TensorStackR, fromJust, fromSTensorBit, fromSTensorRec, fromSortBit, fromSortRec)+import Data.Tensort.Utils.Types+ ( Bit,+ BitR,+ Memory (..),+ MemoryR (..),+ SBit (..),+ SMemory (..),+ STensor (..),+ STensorStack,+ SortAlg,+ Sortable (..),+ Tensor,+ TensorR,+ TensorStack,+ TensorStackR,+ fromJust,+ fromSTensorBit,+ fromSTensorRec,+ fromSortBit,+ fromSortRec,+ ) -- | Compile a sorted list of Bits from a list of TensorStacks @@ -13,8 +39,10 @@ -- >>> 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+getSortedBitsFromTensor subAlg (STensorBit tensorRaw) =+ getSortedBitsFromTensorB subAlg tensorRaw+getSortedBitsFromTensor subAlg (STensorRec tensorRaw) =+ getSortedBitsFromTensorR subAlg tensorRaw getSortedBitsFromTensorB :: SortAlg -> TensorStack -> [SBit] getSortedBitsFromTensorB subAlg tensorRaw = acc tensorRaw []@@ -56,7 +84,16 @@ let (topBit, memory') = removeBitFromMemory subAlg memory topAddress if isNothing memory' then (topBit, Nothing)- else (topBit, Just (fromSTensorBit (createTensor subAlg (SMemoryBit (fromJust memory')))))+ else+ ( topBit,+ Just+ ( fromSTensorBit+ ( createTensor+ subAlg+ (SMemoryBit (fromJust memory'))+ )+ )+ ) removeTopBitFromTensorR :: SortAlg -> TensorR -> (BitR, Maybe TensorR) removeTopBitFromTensorR subAlg (register, memory) = do@@ -65,7 +102,16 @@ let (topBit, memory') = removeBitFromMemoryR subAlg memory topAddress if isNothing memory' then (topBit, Nothing)- else (topBit, Just (fromSTensorRec (createTensor subAlg (SMemoryRec (fromJust memory')))))+ else+ ( topBit,+ Just+ ( fromSTensorRec+ ( createTensor+ subAlg+ (SMemoryRec (fromJust memory'))+ )+ )+ ) removeBitFromMemory :: SortAlg -> Memory -> Int -> (Bit, Maybe Memory) removeBitFromMemory subAlg (ByteMem bytes) i = do@@ -95,7 +141,8 @@ then (topBit, Nothing) else (topBit, Just (TensorMem tensors')) else do- let tensors' = take i tensors ++ [fromJust topTensor'] ++ drop (i + 1) tensors+ let tensors' =+ take i tensors ++ [fromJust topTensor'] ++ drop (i + 1) tensors (topBit, Just (TensorMem tensors')) removeBitFromMemoryR :: SortAlg -> MemoryR -> Int -> (BitR, Maybe MemoryR)@@ -126,5 +173,6 @@ then (topBitR, Nothing) else (topBitR, Just (TensorMemR tensorsR')) else do- let tensorsR' = take i tensorsR ++ [fromJust topTensorR'] ++ drop (i + 1) tensorsR+ let tensorsR' =+ take i tensorsR ++ [fromJust topTensorR'] ++ drop (i + 1) tensorsR (topBitR, Just (TensorMemR tensorsR'))
src/Data/Tensort/Utils/SimplifyRegister.hs view
@@ -11,13 +11,15 @@ simplifyRegister = map (Data.Bifunctor.second snd) 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'+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/Types.hs view
@@ -16,6 +16,96 @@ -- The definition of a Bit may be expanded in the future to include any Ord type Bit = Int +-- | 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]++-- | 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++-- | A Record is an element in a Tensor's Register+-- containing an Address pointer and a TopBit value++-- A Record's Address is an index number pointing to a Byte or Tensor in+-- the Tensor's Memory++-- 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)++-- | A Register is a list of Records allowing for easy access to data in a+-- Tensor's Memory+type Register = [Record]++-- | A Memory contains the data to be sorted, either in the form of Bytes or+-- Tensors.+data Memory+ = ByteMem [Byte]+ | TensorMem [Tensor]+ deriving (Show, Eq, Ord)++-- | A Tensor contains data to be sorted in a structure allowing for+-- easy access. It consists of a Register and its Memory.++-- The Memory is a list of the Bytes or other Tensors that this Tensor+-- contains.++-- The Register is a list of Records referencing the top Bits in Memory.+type Tensor = (Register, Memory)++-- | 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 Bits and 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"++-- | A sorting algorithm is a function that takes a Sortable and returns a+-- sorted Sortable+type SortAlg = Sortable -> Sortable++-- | SupersortProps consist of three sorting algorithms to adjuditcate between+-- and a SupersortStrat that does the adjudication+type SupersortProps = (SortAlg, SortAlg, SortAlg, SupersortStrat)++-- | A SupersortStrat takes three Sortables and determines which of the three+-- is most likely to be in the correct order+type SupersortStrat = (Sortable, Sortable, Sortable) -> Sortable++-- | Convers 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@@ -30,44 +120,54 @@ -- | Converts an SBit to a Bit fromSBitBit :: SBit -> Bit fromSBitBit (SBitBit bit) = bit-fromSBitBit (SBitRec _) = error "From fromSBitBit: This is for sorting Bits - you gave me Records"+fromSBitBit (SBitRec _) =+ error+ "From fromSBitBit: This is for sorting Bits - you gave me Records" -- | Converts an SBit to a Record fromSBitRec :: SBit -> Record fromSBitRec (SBitRec record) = record-fromSBitRec (SBitBit _) = error "From fromSBitRec: This is for sorting Records - you gave me Bits"+fromSBitRec (SBitBit _) =+ error+ "From fromSBitRec: This is for sorting Records - you gave me Bits" --- | A Byte is a list of Bits standardized to a fixed maximum length (Bytesize)+-- | Converts a list of Bits to a Sortable+fromSBitBits :: [SBit] -> Sortable+fromSBitBits = SortBit . map fromSBitBit --- | The length should be set either in or upstream of any function that uses--- Bytes-type Byte = [Bit]+-- | Converts a list of Records to 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] --- | An Address is a index number pointing to data stored in Memory-type Address = Int+-- | 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) --- | A TopBit contains a copy of the last (i.e. highest) Bit in a Byte or--- Tensor-type TopBit = Bit+-- | Converts an SBytes list to 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 to 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 --- | A Record is an element in a Tensor's Register--- containing an Address pointer and a TopBit value---- | A Record's Address is an index number pointing to a Byte or Tensor in--- the Tensor's Memory---- | 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)- -- | This is a `Record` type that is used when sorting Records in a recursive -- Tensort variant type RecordR = (Address, TopBitR)@@ -82,12 +182,16 @@ -- | Converts an SRecord to a Record fromSRecordBit :: SRecord -> Record fromSRecordBit (SRecordBit record) = record-fromSRecordBit (SRecordRec _) = error "From fromSRecordBit: This is for sorting Records - you gave me Bits"+fromSRecordBit (SRecordRec _) =+ error+ "From fromSRecordBit: This is for sorting Records - you gave me Bits" -- | Converts an SRecord to a RecordR fromSRecordRec :: SRecord -> RecordR fromSRecordRec (SRecordRec record) = record-fromSRecordRec (SRecordBit _) = error "From fromSRecordRec: This is for sorting Bits - you gave me Records"+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@@ -96,15 +200,19 @@ | SRecordsRec [RecordR] deriving (Show, Eq, Ord) --- | Converts an SRecords to a list of Records+-- | Converts an SRecords list to 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"+fromSRecordsBit (SRecordsRec _) =+ error+ "From fromSRecordsBit: This is for sorting Records - you gave me Bits" --- | Converts an SRecords to a list of RecordRs+-- | Converts an SRecords list to 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"+fromSRecordsRec (SRecordsBit _) =+ error+ "From fromSRecordsRec: This is for sorting Bits - you gave me Records" -- | Converts a list of SRecords to a list of Records fromSRecordArrayBit :: [SRecord] -> [Record]@@ -114,55 +222,42 @@ fromSRecordArrayRec :: [SRecord] -> [RecordR] fromSRecordArrayRec = map fromSRecordRec --- | A Register is a list of Records allowing for easy access to data in a--- Tensor's Memory-type Register = [Record]- -- | This is a `Register` type that is used when sorting Records in a recursive -- Tensort variant type RegisterR = [RecordR] --- | We use a Sortable type to sort Bits and Records-data Sortable- = SortBit [Bit]- | SortRec [Record]+-- | 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) --- | 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"---- | Converts a list of Bits to a Sortable-fromSBitBits :: [SBit] -> Sortable-fromSBitBits = SortBit . map fromSBitBit---- | Converts a list of Records to a Sortable-fromSBitRecs :: [SBit] -> Sortable-fromSBitRecs = SortRec . map fromSBitRec- -- | 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]+data SMemory+ = SMemoryBit Memory+ | SMemoryRec MemoryR deriving (Show, Eq, Ord) --- | Converts an SBytes list to 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 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 SBytes list to 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"+-- | 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@@ -170,13 +265,6 @@ | STensorRec 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 STensors- = STensorsBit [Tensor]- | STensorsRec [TensorR]- deriving (Show, Eq, Ord)- -- | Converts an STensor to a Tensor fromSTensorBit :: STensor -> Tensor fromSTensorBit (STensorBit tensor) = tensor@@ -191,6 +279,13 @@ 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 to a list of Tensors fromSTensorsBit :: STensors -> [Tensor] fromSTensorsBit (STensorsBit tensors) = tensors@@ -205,81 +300,14 @@ error "From fromSTensorsRec: This is for sorting Records - you gave me Tensors" --- | A sorting algorithm is a function that takes a Sortable and returns a--- sorted Sortable-type SortAlg = Sortable -> Sortable---- | SupersortProps consist of three sorting algorithms to adjuditcate between--- and a SupersortStrat that does the adjudication-type SupersortProps = (SortAlg, SortAlg, SortAlg, SupersortStrat)---- | A SupersortStrat takes three Sortables and determines which of the three--- is most likely to be in the correct order-type SupersortStrat = (Sortable, Sortable, Sortable) -> Sortable---- | A Memory contains the data to be sorted, either in the form of Bytes or--- Tensors.-data Memory- = ByteMem [Byte]- | TensorMem [Tensor]- deriving (Show, Eq, Ord)---- | 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"---- | A Tensor contains data to be sorted in a structure allowing for--- easy access. It consists of a Register and its Memory.---- | The Memory is a list of the Bytes or other Tensors that this Tensor--- contains.---- | The Register is a list of Records referencing the top Bits in Memory.-type Tensor = (Register, Memory)---- | This is a `Tensor` type that is used when sorting Records in a recursive--- Tensort variant-type TensorR = (RegisterR, MemoryR)---- | 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---- | This is a `TensorStack` type that is used when sorting Records in a recursive--- Tensort variant+-- | 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+-- | 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+-- | This is a conversion type that allows for sorting both Tensors and+-- Records. It is useful in recursive Tensort variants type STensorStacks = STensors---- | Convers 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"
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.0.0+version: 1.0.1.0 tested-with: GHC==9.8.2, GHC==9.6.4, @@ -108,6 +108,7 @@ Data.Tensort.OtherSorts.Mergesort, Data.Tensort.OtherSorts.Quicksort, Data.Tensort.Utils.Check,+ Data.Tensort.Utils.LogNat, Data.Tensort.Utils.MkTsProps, Data.Tensort.Utils.RandomizeList, Data.Tensort.Utils.Types,@@ -154,7 +155,6 @@ build-depends: base, tensort,- time >= 1.2.0.3 && < 1.15, -- Directories containing source files. hs-source-dirs: app