hw-balancedparens 0.4.1.0 → 0.4.1.1
raw patch · 55 files changed
+1252/−317 lines, 55 filesdep ~bytestringdep ~doctestdep ~generic-lensPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
Dependency ranges changed: bytestring, doctest, generic-lens, hw-bits, lens, transformers
API changes (from Hackage documentation)
- HaskellWorks.Data.BalancedParens.Internal.Broadword.FindUnmatchedCloseFar.Word16: findClose :: Word16 -> Count -> Maybe Count
- HaskellWorks.Data.BalancedParens.Internal.Broadword.FindUnmatchedCloseFar.Word32: findClose :: Word32 -> Count -> Maybe Count
- HaskellWorks.Data.BalancedParens.Internal.Broadword.FindUnmatchedCloseFar.Word64: findClose :: Word64 -> Count -> Maybe Count
- HaskellWorks.Data.BalancedParens.Internal.Broadword.FindUnmatchedCloseFar.Word8: findClose :: Word8 -> Count -> Maybe Count
+ HaskellWorks.Data.BalancedParens.Internal.Broadword.FindClose.Word16: findClose :: Word16 -> Count -> Maybe Count
+ HaskellWorks.Data.BalancedParens.Internal.Broadword.FindClose.Word32: findClose :: Word32 -> Count -> Maybe Count
+ HaskellWorks.Data.BalancedParens.Internal.Broadword.FindClose.Word64: findClose :: Word64 -> Count -> Maybe Count
+ HaskellWorks.Data.BalancedParens.Internal.Broadword.FindClose.Word8: findClose :: Word8 -> Count -> Maybe Count
+ HaskellWorks.Data.BalancedParens.Internal.Broadword.FindUnmatchedCloseFar.Vector16: findUnmatchedCloseFar :: Word64 -> Word64 -> Vector Word16 -> Count
+ HaskellWorks.Data.BalancedParens.Internal.Broadword.FindUnmatchedCloseFar.Vector32: findUnmatchedCloseFar :: Word64 -> Word64 -> Vector Word32 -> Count
+ HaskellWorks.Data.BalancedParens.Internal.Broadword.FindUnmatchedCloseFar.Vector64: findUnmatchedCloseFar :: Word64 -> Word64 -> Vector Word64 -> Count
+ HaskellWorks.Data.BalancedParens.Internal.Broadword.FindUnmatchedCloseFar.Vector8: findUnmatchedCloseFar :: Word64 -> Word64 -> Vector Word8 -> Count
+ HaskellWorks.Data.BalancedParens.Internal.Slow.FindUnmatchedCloseFar.Vector16: findUnmatchedCloseFar :: Word64 -> Word64 -> Vector Word16 -> Word64
+ HaskellWorks.Data.BalancedParens.Internal.Slow.FindUnmatchedCloseFar.Vector32: findUnmatchedCloseFar :: Word64 -> Word64 -> Vector Word32 -> Word64
+ HaskellWorks.Data.BalancedParens.Internal.Slow.FindUnmatchedCloseFar.Vector64: findUnmatchedCloseFar :: Word64 -> Word64 -> Vector Word64 -> Word64
+ HaskellWorks.Data.BalancedParens.Internal.Slow.FindUnmatchedCloseFar.Vector8: findUnmatchedCloseFar :: Word64 -> Word64 -> Vector Word8 -> Word64
Files
- app/App/Commands.hs +2/−0
- app/App/Commands/BitsToParens.hs +0/−3
- app/App/Commands/ParensToBits.hs +2/−2
- app/App/Commands/Positions.hs +2/−2
- bench/Main.hs +5/−5
- gen/HaskellWorks/Data/BalancedParens/Gen.hs +2/−1
- gen/HaskellWorks/Data/BalancedParens/Internal/IO.hs +12/−0
- hw-balancedparens.cabal +24/−7
- src/HaskellWorks/Data/BalancedParens/FindCloseN.hs +5/−0
- src/HaskellWorks/Data/BalancedParens/Internal/Broadword/FindClose/Vector16.hs +43/−35
- src/HaskellWorks/Data/BalancedParens/Internal/Broadword/FindClose/Vector32.hs +43/−35
- src/HaskellWorks/Data/BalancedParens/Internal/Broadword/FindClose/Vector64.hs +43/−35
- src/HaskellWorks/Data/BalancedParens/Internal/Broadword/FindClose/Vector8.hs +43/−35
- src/HaskellWorks/Data/BalancedParens/Internal/Broadword/FindClose/Word16.hs +53/−0
- src/HaskellWorks/Data/BalancedParens/Internal/Broadword/FindClose/Word32.hs +53/−0
- src/HaskellWorks/Data/BalancedParens/Internal/Broadword/FindClose/Word64.hs +53/−0
- src/HaskellWorks/Data/BalancedParens/Internal/Broadword/FindClose/Word8.hs +53/−0
- src/HaskellWorks/Data/BalancedParens/Internal/Broadword/FindUnmatchedCloseFar/Vector16.hs +42/−0
- src/HaskellWorks/Data/BalancedParens/Internal/Broadword/FindUnmatchedCloseFar/Vector32.hs +42/−0
- src/HaskellWorks/Data/BalancedParens/Internal/Broadword/FindUnmatchedCloseFar/Vector64.hs +42/−0
- src/HaskellWorks/Data/BalancedParens/Internal/Broadword/FindUnmatchedCloseFar/Vector8.hs +42/−0
- src/HaskellWorks/Data/BalancedParens/Internal/Broadword/FindUnmatchedCloseFar/Word16.hs +0/−18
- src/HaskellWorks/Data/BalancedParens/Internal/Broadword/FindUnmatchedCloseFar/Word32.hs +0/−18
- src/HaskellWorks/Data/BalancedParens/Internal/Broadword/FindUnmatchedCloseFar/Word64.hs +0/−18
- src/HaskellWorks/Data/BalancedParens/Internal/Broadword/FindUnmatchedCloseFar/Word8.hs +0/−48
- src/HaskellWorks/Data/BalancedParens/Internal/Broadword/Word64.hs +0/−1
- src/HaskellWorks/Data/BalancedParens/Internal/List.hs +1/−1
- src/HaskellWorks/Data/BalancedParens/Internal/ParensSeq.hs +0/−1
- src/HaskellWorks/Data/BalancedParens/Internal/Slow/FindCloseN/Generic.hs +18/−0
- src/HaskellWorks/Data/BalancedParens/Internal/Slow/FindUnmatchedCloseFar/Vector16.hs +82/−0
- src/HaskellWorks/Data/BalancedParens/Internal/Slow/FindUnmatchedCloseFar/Vector32.hs +82/−0
- src/HaskellWorks/Data/BalancedParens/Internal/Slow/FindUnmatchedCloseFar/Vector64.hs +82/−0
- src/HaskellWorks/Data/BalancedParens/Internal/Slow/FindUnmatchedCloseFar/Vector8.hs +82/−0
- src/HaskellWorks/Data/BalancedParens/Internal/Slow/FindUnmatchedCloseFar/Word16.hs +0/−2
- src/HaskellWorks/Data/BalancedParens/Internal/Slow/FindUnmatchedCloseFar/Word32.hs +0/−2
- src/HaskellWorks/Data/BalancedParens/Internal/Slow/FindUnmatchedCloseFar/Word64.hs +0/−2
- src/HaskellWorks/Data/BalancedParens/Internal/Slow/FindUnmatchedCloseFar/Word8.hs +0/−2
- test/HaskellWorks/Data/BalancedParens/FindCloseNSpec.hs +3/−2
- test/HaskellWorks/Data/BalancedParens/Internal/Broadword/FindClose/Vector16Spec.hs +4/−3
- test/HaskellWorks/Data/BalancedParens/Internal/Broadword/FindClose/Vector32Spec.hs +4/−3
- test/HaskellWorks/Data/BalancedParens/Internal/Broadword/FindClose/Vector64Spec.hs +4/−3
- test/HaskellWorks/Data/BalancedParens/Internal/Broadword/FindClose/Vector8Spec.hs +7/−6
- test/HaskellWorks/Data/BalancedParens/Internal/Broadword/FindUnmatchedCloseFar/Vector16Spec.hs +63/−0
- test/HaskellWorks/Data/BalancedParens/Internal/Broadword/FindUnmatchedCloseFar/Vector32Spec.hs +63/−0
- test/HaskellWorks/Data/BalancedParens/Internal/Broadword/FindUnmatchedCloseFar/Vector64Spec.hs +49/−0
- test/HaskellWorks/Data/BalancedParens/Internal/Broadword/FindUnmatchedCloseFar/Vector8Spec.hs +63/−0
- test/HaskellWorks/Data/BalancedParens/Internal/Broadword/FindUnmatchedCloseFar/Word16Spec.hs +5/−3
- test/HaskellWorks/Data/BalancedParens/Internal/Broadword/FindUnmatchedCloseFar/Word32Spec.hs +5/−2
- test/HaskellWorks/Data/BalancedParens/Internal/Broadword/FindUnmatchedCloseFar/Word64Spec.hs +3/−2
- test/HaskellWorks/Data/BalancedParens/Internal/Broadword/FindUnmatchedCloseFar/Word8Spec.hs +5/−2
- test/HaskellWorks/Data/BalancedParens/Internal/BroadwordSpec.hs +3/−2
- test/HaskellWorks/Data/BalancedParens/Internal/ParensSeqSpec.hs +8/−8
- test/HaskellWorks/Data/BalancedParens/RangeMin2Spec.hs +3/−2
- test/HaskellWorks/Data/BalancedParens/RangeMinSpec.hs +3/−2
- test/HaskellWorks/Data/BalancedParens/SimpleSpec.hs +4/−4
app/App/Commands.hs view
@@ -5,6 +5,8 @@ import App.Commands.Positions import Options.Applicative +{- HLINT ignore "Monoid law, left identity" -}+ cmdOpts :: Parser (IO ()) cmdOpts = subparser $ mempty <> cmdParensToBits
app/App/Commands/BitsToParens.hs view
@@ -17,9 +17,6 @@ import qualified Data.ByteString.Builder as B import qualified Data.ByteString.Lazy as LBS -{-# ANN module ("HLint: ignore Redundant do" :: String) #-}-{-# ANN module ("HLint: ignore Redundant return" :: String) #-}- bitString :: Word8 -> B.Builder bitString w = go ((w .>. 0) .&. 1) <>
app/App/Commands/ParensToBits.hs view
@@ -18,8 +18,8 @@ import qualified App.IO as IO import qualified Data.ByteString.Lazy as LBS -{-# ANN module ("HLint: ignore Redundant do" :: String) #-}-{-# ANN module ("HLint: ignore Redundant return" :: String) #-}+{- HLINT ignore "Redundant do" -}+{- HLINT ignore "Redundant return" -} unparens :: LBS.ByteString -> LBS.ByteString unparens = LBS.unfoldr go . (0, 0, )
app/App/Commands/Positions.hs view
@@ -20,8 +20,8 @@ import qualified HaskellWorks.Data.FromForeignRegion as IO import qualified System.IO as IO -{-# ANN module ("HLint: ignore Redundant do" :: String) #-}-{-# ANN module ("HLint: ignore Redundant return" :: String) #-}+{- HLINT ignore "Redundant do" -}+{- HLINT ignore "Redundant return" -} openCloses :: (FindClose v, OpenAt v) => v -> [(Count, Count)] openCloses v = go 1 v []
bench/Main.hs view
@@ -29,6 +29,7 @@ import qualified HaskellWorks.Data.BalancedParens.Gen as G import qualified HaskellWorks.Data.BalancedParens.Internal.Broadword.FindClose.Vector64 as BWV64 import qualified HaskellWorks.Data.BalancedParens.Internal.Broadword.FindUnmatchedCloseFar.Word64 as BW64+import qualified HaskellWorks.Data.BalancedParens.Internal.IO as IO import qualified HaskellWorks.Data.BalancedParens.Internal.Slow.FindUnmatchedCloseFar.Word64 as SW64 import qualified HaskellWorks.Data.BalancedParens.ParensSeq as PS import qualified HaskellWorks.Data.BalancedParens.RangeMin as RM@@ -37,9 +38,8 @@ import qualified HaskellWorks.Data.Length as HW import qualified Hedgehog.Gen as G import qualified Hedgehog.Range as R-import qualified System.Directory as IO -{-# ANN module ("HLint: ignore Monoid law, left identity" :: String) #-}+{- HLINT ignore "Monoid law, left identity" -} setupEnvVector :: Int -> IO (DVS.Vector Word64) setupEnvVector n = return $ DVS.fromList (take n (cycle [maxBound, 0]))@@ -144,7 +144,7 @@ , bench "nextSibling" (nf (map (PS.nextSibling ps)) [1,101..100000]) , bench "(<|)" (nf (<| ps) True) , bench "(|>)" (nf (ps |>) True)- , bench "drop" (nf (fmap (flip PS.drop ps)) [1,101..100000])+ , bench "drop" (nf (fmap (`PS.drop` ps)) [1,101..100000]) ] , env (G.sample (G.vec2 (G.bpParensSeq (R.singleton 100000)))) $ \ ~(ps1, ps2) -> bgroup "ParensSeq" [ bench "(<>)" (nf (ps1 <>) ps2)@@ -163,7 +163,7 @@ mkEnvCorpusVector :: FilePath -> IO EnvCorpusVector mkEnvCorpusVector file = do myVector <- IO.mmapFromForeignRegion file- myRmm2 <- pure $ RM2.mkRangeMin2 myVector+ let myRmm2 = RM2.mkRangeMin2 myVector return EnvCorpusVector { vector = myVector , rmm2 = myRmm2@@ -171,7 +171,7 @@ mkBenchCorpusVector :: IO [Benchmark] mkBenchCorpusVector = do- entries <- IO.listDirectory "data/bench"+ entries <- IO.safeListDirectory "data/bench" let files = L.sort (("data/bench/" ++) <$> (".ib.idx" `L.isSuffixOf`) `filter` entries) benchmarks <- forM files $ \file -> return [ env (mkEnvCorpusVector file) $ \e -> bgroup "Loading lazy byte string into Word64s" $ mempty
gen/HaskellWorks/Data/BalancedParens/Gen.hs view
@@ -1,5 +1,4 @@ {-# LANGUAGE DeriveGeneric #-}-{-# LANGUAGE TupleSections #-} module HaskellWorks.Data.BalancedParens.Gen ( BP(..)@@ -28,6 +27,8 @@ import qualified HaskellWorks.Data.BalancedParens.RangeMin2 as RM2 import qualified Hedgehog.Gen as G import qualified Hedgehog.Range as R++{- HLINT ignore "Use guards" -} count :: MonadGen m => Range Count -> m Count count r = coerce <$> G.word64 (coerce <$> r)
+ gen/HaskellWorks/Data/BalancedParens/Internal/IO.hs view
@@ -0,0 +1,12 @@+module HaskellWorks.Data.BalancedParens.Internal.IO+ ( safeListDirectory+ ) where++import qualified System.Directory as IO++safeListDirectory :: FilePath -> IO [FilePath]+safeListDirectory fp = do+ exists <- IO.doesDirectoryExist fp+ if exists+ then IO.listDirectory fp+ else return []
hw-balancedparens.cabal view
@@ -1,7 +1,7 @@ cabal-version: 2.2 name: hw-balancedparens-version: 0.4.1.0+version: 0.4.1.1 synopsis: Balanced parentheses description: Balanced parentheses. category: Data, Bit, Succinct Data Structures, Data Structures@@ -12,7 +12,7 @@ copyright: 2016-2020 John Ky license: BSD-3-Clause license-file: LICENSE-tested-with: GHC == 8.10.1, GHC == 8.8.3, GHC == 8.6.5, GHC == 8.4.4+tested-with: GHC == 8.10.2, GHC == 8.8.3, GHC == 8.6.5, GHC == 8.4.4 build-type: Simple extra-source-files: README.md @@ -32,7 +32,7 @@ common hedgehog { build-depends: hedgehog >= 1.0 && < 1.1 } common hspec { build-depends: hspec >= 2.2 && < 3.0 } common hw-hspec-hedgehog { build-depends: hw-hspec-hedgehog >= 0.1 && < 0.2 }-common hw-bits { build-depends: hw-bits >= 0.7.1.5 && < 0.8 }+common hw-bits { build-depends: hw-bits >= 0.7.2.1 && < 0.8 } common hw-excess { build-depends: hw-excess >= 0.2.2.0 && < 0.3 } common hw-fingertree { build-depends: hw-fingertree >= 0.1.1.0 && < 0.2 } common hw-int { build-depends: hw-int >= 0.0.2 && < 0.0.3 }@@ -40,7 +40,7 @@ common hw-rankselect-base { build-depends: hw-rankselect-base >= 0.3.2.1 && < 0.4 } common lens { build-depends: lens >= 4 && < 5 } common mmap { build-depends: mmap >= 0.5.9 && < 0.6 }-common optparse-applicative { build-depends: optparse-applicative >= 0.14 && < 0.16 }+common optparse-applicative { build-depends: optparse-applicative >= 0.14 && < 0.17 } common transformers { build-depends: transformers >= 0.5.2 && < 0.6 } common vector { build-depends: vector >= 0.12 && < 0.13 } @@ -76,6 +76,14 @@ HaskellWorks.Data.BalancedParens.Internal.Broadword.FindClose.Vector32 HaskellWorks.Data.BalancedParens.Internal.Broadword.FindClose.Vector64 HaskellWorks.Data.BalancedParens.Internal.Broadword.FindClose.Vector8+ HaskellWorks.Data.BalancedParens.Internal.Broadword.FindClose.Word16+ HaskellWorks.Data.BalancedParens.Internal.Broadword.FindClose.Word32+ HaskellWorks.Data.BalancedParens.Internal.Broadword.FindClose.Word64+ HaskellWorks.Data.BalancedParens.Internal.Broadword.FindClose.Word8+ HaskellWorks.Data.BalancedParens.Internal.Broadword.FindUnmatchedCloseFar.Vector16+ HaskellWorks.Data.BalancedParens.Internal.Broadword.FindUnmatchedCloseFar.Vector32+ HaskellWorks.Data.BalancedParens.Internal.Broadword.FindUnmatchedCloseFar.Vector64+ HaskellWorks.Data.BalancedParens.Internal.Broadword.FindUnmatchedCloseFar.Vector8 HaskellWorks.Data.BalancedParens.Internal.Broadword.FindUnmatchedCloseFar.Word16 HaskellWorks.Data.BalancedParens.Internal.Broadword.FindUnmatchedCloseFar.Word32 HaskellWorks.Data.BalancedParens.Internal.Broadword.FindUnmatchedCloseFar.Word64@@ -87,6 +95,10 @@ HaskellWorks.Data.BalancedParens.Internal.Show HaskellWorks.Data.BalancedParens.Internal.Slow.FindCloseC.Generic HaskellWorks.Data.BalancedParens.Internal.Slow.FindCloseN.Generic+ HaskellWorks.Data.BalancedParens.Internal.Slow.FindUnmatchedCloseFar.Vector16+ HaskellWorks.Data.BalancedParens.Internal.Slow.FindUnmatchedCloseFar.Vector32+ HaskellWorks.Data.BalancedParens.Internal.Slow.FindUnmatchedCloseFar.Vector64+ HaskellWorks.Data.BalancedParens.Internal.Slow.FindUnmatchedCloseFar.Vector8 HaskellWorks.Data.BalancedParens.Internal.Slow.FindUnmatchedCloseFar.Word16 HaskellWorks.Data.BalancedParens.Internal.Slow.FindUnmatchedCloseFar.Word32 HaskellWorks.Data.BalancedParens.Internal.Slow.FindUnmatchedCloseFar.Word64@@ -113,12 +125,14 @@ library hw-balancedparens-gen import: base, config , deepseq+ , directory , hedgehog , hspec , hw-balancedparens , hw-prim , vector exposed-modules: HaskellWorks.Data.BalancedParens.Gen+ HaskellWorks.Data.BalancedParens.Internal.IO hs-source-dirs: gen executable hw-balancedparens@@ -159,7 +173,11 @@ , vector type: exitcode-stdio-1.0 main-is: Spec.hs- other-modules: HaskellWorks.Data.BalancedParens.Internal.Broadword.FindClose.Vector8Spec+ other-modules: HaskellWorks.Data.BalancedParens.Internal.Broadword.FindUnmatchedCloseFar.Vector8Spec+ HaskellWorks.Data.BalancedParens.Internal.Broadword.FindUnmatchedCloseFar.Vector16Spec+ HaskellWorks.Data.BalancedParens.Internal.Broadword.FindUnmatchedCloseFar.Vector32Spec+ HaskellWorks.Data.BalancedParens.Internal.Broadword.FindUnmatchedCloseFar.Vector64Spec+ HaskellWorks.Data.BalancedParens.Internal.Broadword.FindClose.Vector8Spec HaskellWorks.Data.BalancedParens.Internal.Broadword.FindClose.Vector16Spec HaskellWorks.Data.BalancedParens.Internal.Broadword.FindClose.Vector32Spec HaskellWorks.Data.BalancedParens.Internal.Broadword.FindClose.Vector64Spec@@ -185,15 +203,14 @@ , generic-lens , hedgehog , hw-balancedparens+ , hw-balancedparens-gen , hw-bits , hw-prim , lens , vector- other-modules: HaskellWorks.Data.BalancedParens.Gen type: exitcode-stdio-1.0 main-is: Main.hs hs-source-dirs: bench- , gen test-suite doctest import: base, config
src/HaskellWorks/Data/BalancedParens/FindCloseN.hs view
@@ -16,6 +16,11 @@ import qualified HaskellWorks.Data.BalancedParens.Internal.Slow.FindCloseN.Generic as G class FindCloseN v where+ -- | Find the position of the corresponding close parenthesis carrying in a number of open parentheses starting from a given position.+ --+ -- All positions are one based.+ --+ -- See the reference implementation 'G.findCloseN' for details findCloseN :: v -> Count -> Count -> Maybe Count instance (CloseAt a, TestBit a, BitLength a) => FindCloseN (BitShown a) where
src/HaskellWorks/Data/BalancedParens/Internal/Broadword/FindClose/Vector16.hs view
@@ -2,45 +2,53 @@ ( findClose ) where -import Data.Int import Data.Word-import HaskellWorks.Data.AtIndex import HaskellWorks.Data.BalancedParens.CloseAt-import HaskellWorks.Data.Bits.BitLength-import HaskellWorks.Data.Int.Unsigned import HaskellWorks.Data.Positioning -import qualified Data.Vector.Storable as DVS-import qualified HaskellWorks.Data.BalancedParens.Internal.Broadword.FindUnmatchedCloseFar.Word16 as BW16-import qualified HaskellWorks.Data.Drop as HW-import qualified HaskellWorks.Data.Length as HW--findCloseCont :: DVS.Vector Word16 -> Int64 -> Count -> Maybe Count-findCloseCont v i c = if i < HW.end v- then case BW16.findUnmatchedCloseFar c 0 w of- q -> if q >= bitLength w- then findCloseCont v (i + 1) (q - bitLength w)- else Just (b + q + 1)- else Just (b + c + 1)- where b = unsigned i * bitLength w -- base- w = v !!! fromIntegral i-{-# INLINE findCloseCont #-}+import qualified Data.Vector.Storable as DVS+import qualified HaskellWorks.Data.BalancedParens.Internal.Broadword.FindUnmatchedCloseFar.Vector16 as BWV16 +-- | Find the position of the matching close parenthesis.+--+-- The position argument and return value is one-based.+--+-- If the parenthesis at the input position is an a close, then that is considered the+-- matching close parenthesis.+--+-- >>> import HaskellWorks.Data.Bits.BitRead+-- >>> import Data.Maybe+--+-- The following scans for the matching close parenthesis for the open parenthesis at position 1:+--+-- >>> findClose (fromJust $ bitRead "10000000") 1+-- Just 2+--+-- >>> findClose (fromJust $ bitRead "11000000") 1+-- Just 4+--+-- >>> findClose (fromJust $ bitRead "11010000") 1+-- Just 6+--+-- The following scans for the matching close parenthesis for the open parenthesis at position 2:+--+-- >>> findClose (fromJust $ bitRead "11010000") 2+-- Just 3+--+-- If the input position has a close parenthesis, then that position is returned:+--+-- >>> findClose (fromJust $ bitRead "11010000") 3+-- Just 3+--+-- The scan can continue past the end of the input word because every bit after then end of the+-- word is considered to be zero, which is a closing parenthesis:+--+-- >>> findClose (fromJust $ bitRead "11111110") 1+-- Just 14 findClose :: DVS.Vector Word16 -> Count -> Maybe Count-findClose _ 0 = Nothing-findClose v p = fmap (+ vd) (findClose' (HW.drop vi v) (p - vd))- where vi = (p - 1) `div` elemBitLength v- vd = vi * elemBitLength v+findClose v p = if p > 0+ then if closeAt v p+ then Just p+ else Just (BWV16.findUnmatchedCloseFar 0 p v + 1)+ else Just (BWV16.findUnmatchedCloseFar 1 p v) {-# INLINE findClose #-}--findClose' :: DVS.Vector Word16 -> Count -> Maybe Count-findClose' v p = if DVS.length v > 0- then if closeAt w p- then Just p- else case BW16.findUnmatchedCloseFar 0 p w of- q -> if q >= bitLength w- then findCloseCont v 1 (q - bitLength w)- else Just (q + 1)- else Just (p * 2)- where w = v !!! 0-{-# INLINE findClose' #-}
src/HaskellWorks/Data/BalancedParens/Internal/Broadword/FindClose/Vector32.hs view
@@ -2,45 +2,53 @@ ( findClose ) where -import Data.Int import Data.Word-import HaskellWorks.Data.AtIndex import HaskellWorks.Data.BalancedParens.CloseAt-import HaskellWorks.Data.Bits.BitLength-import HaskellWorks.Data.Int.Unsigned import HaskellWorks.Data.Positioning -import qualified Data.Vector.Storable as DVS-import qualified HaskellWorks.Data.BalancedParens.Internal.Broadword.FindUnmatchedCloseFar.Word32 as BW32-import qualified HaskellWorks.Data.Drop as HW-import qualified HaskellWorks.Data.Length as HW--findCloseCont :: DVS.Vector Word32 -> Int64 -> Count -> Maybe Count-findCloseCont v i c = if i < HW.end v- then case BW32.findUnmatchedCloseFar c 0 w of- q -> if q >= bitLength w- then findCloseCont v (i + 1) (q - bitLength w)- else Just (b + q + 1)- else Just (b + c + 1)- where b = unsigned i * bitLength w -- base- w = v !!! fromIntegral i-{-# INLINE findCloseCont #-}+import qualified Data.Vector.Storable as DVS+import qualified HaskellWorks.Data.BalancedParens.Internal.Broadword.FindUnmatchedCloseFar.Vector32 as BWV32 +-- | Find the position of the matching close parenthesis.+--+-- The position argument and return value is one-based.+--+-- If the parenthesis at the input position is an a close, then that is considered the+-- matching close parenthesis.+--+-- >>> import HaskellWorks.Data.Bits.BitRead+-- >>> import Data.Maybe+--+-- The following scans for the matching close parenthesis for the open parenthesis at position 1:+--+-- >>> findClose (fromJust $ bitRead "10000000") 1+-- Just 2+--+-- >>> findClose (fromJust $ bitRead "11000000") 1+-- Just 4+--+-- >>> findClose (fromJust $ bitRead "11010000") 1+-- Just 6+--+-- The following scans for the matching close parenthesis for the open parenthesis at position 2:+--+-- >>> findClose (fromJust $ bitRead "11010000") 2+-- Just 3+--+-- If the input position has a close parenthesis, then that position is returned:+--+-- >>> findClose (fromJust $ bitRead "11010000") 3+-- Just 3+--+-- The scan can continue past the end of the input word because every bit after then end of the+-- word is considered to be zero, which is a closing parenthesis:+--+-- >>> findClose (fromJust $ bitRead "11111110") 1+-- Just 14 findClose :: DVS.Vector Word32 -> Count -> Maybe Count-findClose _ 0 = Nothing-findClose v p = fmap (+ vd) (findClose' (HW.drop vi v) (p - vd))- where vi = (p - 1) `div` elemBitLength v- vd = vi * elemBitLength v+findClose v p = if p > 0+ then if closeAt v p+ then Just p+ else Just (BWV32.findUnmatchedCloseFar 0 p v + 1)+ else Just (BWV32.findUnmatchedCloseFar 1 p v) {-# INLINE findClose #-}--findClose' :: DVS.Vector Word32 -> Count -> Maybe Count-findClose' v p = if DVS.length v > 0- then if closeAt w p- then Just p- else case BW32.findUnmatchedCloseFar 0 p w of- q -> if q >= bitLength w- then findCloseCont v 1 (q - bitLength w)- else Just (q + 1)- else Just (p * 2)- where w = v !!! 0-{-# INLINE findClose' #-}
src/HaskellWorks/Data/BalancedParens/Internal/Broadword/FindClose/Vector64.hs view
@@ -2,45 +2,53 @@ ( findClose ) where -import Data.Int import Data.Word-import HaskellWorks.Data.AtIndex import HaskellWorks.Data.BalancedParens.CloseAt-import HaskellWorks.Data.Bits.BitLength-import HaskellWorks.Data.Int.Unsigned import HaskellWorks.Data.Positioning -import qualified Data.Vector.Storable as DVS-import qualified HaskellWorks.Data.BalancedParens.Internal.Broadword.FindUnmatchedCloseFar.Word64 as BW64-import qualified HaskellWorks.Data.Drop as HW-import qualified HaskellWorks.Data.Length as HW--findCloseCont :: DVS.Vector Word64 -> Int64 -> Count -> Maybe Count-findCloseCont v i c = if i < HW.end v- then case BW64.findUnmatchedCloseFar c 0 w of- q -> if q >= bitLength w- then findCloseCont v (i + 1) (q - bitLength w)- else Just (b + q + 1)- else Just (b + c + 1)- where b = unsigned i * bitLength w -- base- w = v !!! fromIntegral i-{-# INLINE findCloseCont #-}+import qualified Data.Vector.Storable as DVS+import qualified HaskellWorks.Data.BalancedParens.Internal.Broadword.FindUnmatchedCloseFar.Vector64 as BWV64 +-- | Find the position of the matching close parenthesis.+--+-- The position argument and return value is one-based.+--+-- If the parenthesis at the input position is an a close, then that is considered the+-- matching close parenthesis.+--+-- >>> import HaskellWorks.Data.Bits.BitRead+-- >>> import Data.Maybe+--+-- The following scans for the matching close parenthesis for the open parenthesis at position 1:+--+-- >>> findClose (fromJust $ bitRead "10000000") 1+-- Just 2+--+-- >>> findClose (fromJust $ bitRead "11000000") 1+-- Just 4+--+-- >>> findClose (fromJust $ bitRead "11010000") 1+-- Just 6+--+-- The following scans for the matching close parenthesis for the open parenthesis at position 2:+--+-- >>> findClose (fromJust $ bitRead "11010000") 2+-- Just 3+--+-- If the input position has a close parenthesis, then that position is returned:+--+-- >>> findClose (fromJust $ bitRead "11010000") 3+-- Just 3+--+-- The scan can continue past the end of the input word because every bit after then end of the+-- word is considered to be zero, which is a closing parenthesis:+--+-- >>> findClose (fromJust $ bitRead "11111110") 1+-- Just 14 findClose :: DVS.Vector Word64 -> Count -> Maybe Count-findClose _ 0 = Nothing-findClose v p = fmap (+ vd) (findClose' (HW.drop vi v) (p - vd))- where vi = (p - 1) `div` elemBitLength v- vd = vi * elemBitLength v+findClose v p = if p > 0+ then if closeAt v p+ then Just p+ else Just (BWV64.findUnmatchedCloseFar 0 p v + 1)+ else Just (BWV64.findUnmatchedCloseFar 1 p v) {-# INLINE findClose #-}--findClose' :: DVS.Vector Word64 -> Count -> Maybe Count-findClose' v p = if DVS.length v > 0- then if closeAt w p- then Just p- else case BW64.findUnmatchedCloseFar 0 p w of- q -> if q >= bitLength w- then findCloseCont v 1 (q - bitLength w)- else Just (q + 1)- else Just (p * 2)- where w = v !!! 0-{-# INLINE findClose' #-}
src/HaskellWorks/Data/BalancedParens/Internal/Broadword/FindClose/Vector8.hs view
@@ -2,45 +2,53 @@ ( findClose ) where -import Data.Int import Data.Word-import HaskellWorks.Data.AtIndex import HaskellWorks.Data.BalancedParens.CloseAt-import HaskellWorks.Data.Bits.BitLength-import HaskellWorks.Data.Int.Unsigned import HaskellWorks.Data.Positioning -import qualified Data.Vector.Storable as DVS-import qualified HaskellWorks.Data.BalancedParens.Internal.Broadword.FindUnmatchedCloseFar.Word8 as BW32-import qualified HaskellWorks.Data.Drop as HW-import qualified HaskellWorks.Data.Length as HW--findCloseCont :: DVS.Vector Word8 -> Int64 -> Count -> Maybe Count-findCloseCont v i c = if i < HW.end v- then case BW32.findUnmatchedCloseFar c 0 w of- q -> if q >= bitLength w- then findCloseCont v (i + 1) (q - bitLength w)- else Just (b + q + 1)- else Just (b + c + 1)- where b = unsigned i * bitLength w -- base- w = v !!! fromIntegral i-{-# INLINE findCloseCont #-}+import qualified Data.Vector.Storable as DVS+import qualified HaskellWorks.Data.BalancedParens.Internal.Broadword.FindUnmatchedCloseFar.Vector8 as BWV8 +-- | Find the position of the matching close parenthesis.+--+-- The position argument and return value is one-based.+--+-- If the parenthesis at the input position is an a close, then that is considered the+-- matching close parenthesis.+--+-- >>> import HaskellWorks.Data.Bits.BitRead+-- >>> import Data.Maybe+--+-- The following scans for the matching close parenthesis for the open parenthesis at position 1:+--+-- >>> findClose (fromJust $ bitRead "10000000") 1+-- Just 2+--+-- >>> findClose (fromJust $ bitRead "11000000") 1+-- Just 4+--+-- >>> findClose (fromJust $ bitRead "11010000") 1+-- Just 6+--+-- The following scans for the matching close parenthesis for the open parenthesis at position 2:+--+-- >>> findClose (fromJust $ bitRead "11010000") 2+-- Just 3+--+-- If the input position has a close parenthesis, then that position is returned:+--+-- >>> findClose (fromJust $ bitRead "11010000") 3+-- Just 3+--+-- The scan can continue past the end of the input word because every bit after then end of the+-- word is considered to be zero, which is a closing parenthesis:+--+-- >>> findClose (fromJust $ bitRead "11111110") 1+-- Just 14 findClose :: DVS.Vector Word8 -> Count -> Maybe Count-findClose _ 0 = Nothing-findClose v p = fmap (+ vd) (findClose' (HW.drop vi v) (p - vd))- where vi = (p - 1) `div` elemBitLength v- vd = vi * elemBitLength v+findClose v p = if p > 0+ then if closeAt v p+ then Just p+ else Just (BWV8.findUnmatchedCloseFar 0 p v + 1)+ else Just (BWV8.findUnmatchedCloseFar 1 p v) {-# INLINE findClose #-}--findClose' :: DVS.Vector Word8 -> Count -> Maybe Count-findClose' v p = if DVS.length v > 0- then if closeAt w p- then Just p- else case BW32.findUnmatchedCloseFar 0 p w of- q -> if q >= bitLength w- then findCloseCont v 1 (q - bitLength w)- else Just (q + 1)- else Just (p * 2)- where w = v !!! 0-{-# INLINE findClose' #-}
+ src/HaskellWorks/Data/BalancedParens/Internal/Broadword/FindClose/Word16.hs view
@@ -0,0 +1,53 @@+module HaskellWorks.Data.BalancedParens.Internal.Broadword.FindClose.Word16+ ( findClose+ ) where++import Data.Word+import HaskellWorks.Data.BalancedParens.CloseAt+import HaskellWorks.Data.Positioning++import qualified HaskellWorks.Data.BalancedParens.Internal.Broadword.FindUnmatchedCloseFar.Word16 as W16++-- | Find the position of the matching close parenthesis.+--+-- The position argument and return value is one-based.+--+-- If the parenthesis at the input position is an a close, then that is considered the+-- matching close parenthesis.+--+-- >>> import HaskellWorks.Data.Bits.BitRead+-- >>> import Data.Maybe+--+-- The following scans for the matching close parenthesis for the open parenthesis at position 1:+--+-- >>> findClose (fromJust $ bitRead "10000000") 1+-- Just 2+--+-- >>> findClose (fromJust $ bitRead "11000000") 1+-- Just 4+--+-- >>> findClose (fromJust $ bitRead "11010000") 1+-- Just 6+--+-- The following scans for the matching close parenthesis for the open parenthesis at position 2:+--+-- >>> findClose (fromJust $ bitRead "11010000") 2+-- Just 3+--+-- If the input position has a close parenthesis, then that position is returned:+--+-- >>> findClose (fromJust $ bitRead "11010000") 3+-- Just 3+--+-- The scan can continue past the end of the input word because every bit after then end of the+-- word is considered to be zero, which is a closing parenthesis:+--+-- >>> findClose (fromJust $ bitRead "11111110") 1+-- Just 14+findClose :: Word16 -> Count -> Maybe Count+findClose v p = if p > 0+ then if closeAt v p+ then Just p+ else Just (W16.findUnmatchedCloseFar 0 p v + 1)+ else Just (W16.findUnmatchedCloseFar 1 p v)+{-# INLINE findClose #-}
+ src/HaskellWorks/Data/BalancedParens/Internal/Broadword/FindClose/Word32.hs view
@@ -0,0 +1,53 @@+module HaskellWorks.Data.BalancedParens.Internal.Broadword.FindClose.Word32+ ( findClose+ ) where++import Data.Word+import HaskellWorks.Data.BalancedParens.CloseAt+import HaskellWorks.Data.Positioning++import qualified HaskellWorks.Data.BalancedParens.Internal.Broadword.FindUnmatchedCloseFar.Word32 as W32++-- | Find the position of the matching close parenthesis.+--+-- The position argument and return value is one-based.+--+-- If the parenthesis at the input position is an a close, then that is considered the+-- matching close parenthesis.+--+-- >>> import HaskellWorks.Data.Bits.BitRead+-- >>> import Data.Maybe+--+-- The following scans for the matching close parenthesis for the open parenthesis at position 1:+--+-- >>> findClose (fromJust $ bitRead "10000000") 1+-- Just 2+--+-- >>> findClose (fromJust $ bitRead "11000000") 1+-- Just 4+--+-- >>> findClose (fromJust $ bitRead "11010000") 1+-- Just 6+--+-- The following scans for the matching close parenthesis for the open parenthesis at position 2:+--+-- >>> findClose (fromJust $ bitRead "11010000") 2+-- Just 3+--+-- If the input position has a close parenthesis, then that position is returned:+--+-- >>> findClose (fromJust $ bitRead "11010000") 3+-- Just 3+--+-- The scan can continue past the end of the input word because every bit after then end of the+-- word is considered to be zero, which is a closing parenthesis:+--+-- >>> findClose (fromJust $ bitRead "11111110") 1+-- Just 14+findClose :: Word32 -> Count -> Maybe Count+findClose v p = if p > 0+ then if closeAt v p+ then Just p+ else Just (W32.findUnmatchedCloseFar 0 p v + 1)+ else Just (W32.findUnmatchedCloseFar 1 p v)+{-# INLINE findClose #-}
+ src/HaskellWorks/Data/BalancedParens/Internal/Broadword/FindClose/Word64.hs view
@@ -0,0 +1,53 @@+module HaskellWorks.Data.BalancedParens.Internal.Broadword.FindClose.Word64+ ( findClose+ ) where++import Data.Word+import HaskellWorks.Data.BalancedParens.CloseAt+import HaskellWorks.Data.Positioning++import qualified HaskellWorks.Data.BalancedParens.Internal.Broadword.FindUnmatchedCloseFar.Word64 as W64++-- | Find the position of the matching close parenthesis.+--+-- The position argument and return value is one-based.+--+-- If the parenthesis at the input position is an a close, then that is considered the+-- matching close parenthesis.+--+-- >>> import HaskellWorks.Data.Bits.BitRead+-- >>> import Data.Maybe+--+-- The following scans for the matching close parenthesis for the open parenthesis at position 1:+--+-- >>> findClose (fromJust $ bitRead "10000000") 1+-- Just 2+--+-- >>> findClose (fromJust $ bitRead "11000000") 1+-- Just 4+--+-- >>> findClose (fromJust $ bitRead "11010000") 1+-- Just 6+--+-- The following scans for the matching close parenthesis for the open parenthesis at position 2:+--+-- >>> findClose (fromJust $ bitRead "11010000") 2+-- Just 3+--+-- If the input position has a close parenthesis, then that position is returned:+--+-- >>> findClose (fromJust $ bitRead "11010000") 3+-- Just 3+--+-- The scan can continue past the end of the input word because every bit after then end of the+-- word is considered to be zero, which is a closing parenthesis:+--+-- >>> findClose (fromJust $ bitRead "11111110") 1+-- Just 14+findClose :: Word64 -> Count -> Maybe Count+findClose v p = if p > 0+ then if closeAt v p+ then Just p+ else Just (W64.findUnmatchedCloseFar 0 p v + 1)+ else Just (W64.findUnmatchedCloseFar 1 p v)+{-# INLINE findClose #-}
+ src/HaskellWorks/Data/BalancedParens/Internal/Broadword/FindClose/Word8.hs view
@@ -0,0 +1,53 @@+module HaskellWorks.Data.BalancedParens.Internal.Broadword.FindClose.Word8+ ( findClose+ ) where++import Data.Word+import HaskellWorks.Data.BalancedParens.CloseAt+import HaskellWorks.Data.Positioning++import qualified HaskellWorks.Data.BalancedParens.Internal.Broadword.FindUnmatchedCloseFar.Word8 as W8++-- | Find the position of the matching close parenthesis.+--+-- The position argument and return value is one-based.+--+-- If the parenthesis at the input position is an a close, then that is considered the+-- matching close parenthesis.+--+-- >>> import HaskellWorks.Data.Bits.BitRead+-- >>> import Data.Maybe+--+-- The following scans for the matching close parenthesis for the open parenthesis at position 1:+--+-- >>> findClose (fromJust $ bitRead "10000000") 1+-- Just 2+--+-- >>> findClose (fromJust $ bitRead "11000000") 1+-- Just 4+--+-- >>> findClose (fromJust $ bitRead "11010000") 1+-- Just 6+--+-- The following scans for the matching close parenthesis for the open parenthesis at position 2:+--+-- >>> findClose (fromJust $ bitRead "11010000") 2+-- Just 3+--+-- If the input position has a close parenthesis, then that position is returned:+--+-- >>> findClose (fromJust $ bitRead "11010000") 3+-- Just 3+--+-- The scan can continue past the end of the input word because every bit after then end of the+-- word is considered to be zero, which is a closing parenthesis:+--+-- >>> findClose (fromJust $ bitRead "11111110") 1+-- Just 14+findClose :: Word8 -> Count -> Maybe Count+findClose v p = if p > 0+ then if closeAt v p+ then Just p+ else Just (W8.findUnmatchedCloseFar 0 p v + 1)+ else Just (W8.findUnmatchedCloseFar 1 p v)+{-# INLINE findClose #-}
+ src/HaskellWorks/Data/BalancedParens/Internal/Broadword/FindUnmatchedCloseFar/Vector16.hs view
@@ -0,0 +1,42 @@+module HaskellWorks.Data.BalancedParens.Internal.Broadword.FindUnmatchedCloseFar.Vector16+ ( findUnmatchedCloseFar+ ) where++import Data.Int+import Data.Word+import HaskellWorks.Data.AtIndex+import HaskellWorks.Data.Bits.BitLength+import HaskellWorks.Data.Int.Unsigned+import HaskellWorks.Data.Positioning++import qualified Data.Vector.Storable as DVS+import qualified HaskellWorks.Data.BalancedParens.Internal.Broadword.FindUnmatchedCloseFar.Word16 as BWW16+import qualified HaskellWorks.Data.Drop as HW+import qualified HaskellWorks.Data.Length as HW++findUnmatchedCloseCont :: Int64 -> Count -> DVS.Vector Word16 -> Count+findUnmatchedCloseCont i c v = if i < HW.end v+ then case BWW16.findUnmatchedCloseFar c 0 w of+ q -> if q >= bitLength w+ then findUnmatchedCloseCont (i + 1) (q - bitLength w) v+ else b + q+ else b + c+ where b = unsigned i * bitLength w -- base+ w = v !!! fromIntegral i+{-# INLINE findUnmatchedCloseCont #-}++findUnmatchedClose' :: Word64 -> Word64 -> DVS.Vector Word16 -> Count+findUnmatchedClose' c p v = if DVS.length v > 0+ then case BWW16.findUnmatchedCloseFar c p w of+ q -> if q >= bitLength w+ then findUnmatchedCloseCont 1 (q - bitLength w) v+ else q+ else p * 2 + c+ where w = v !!! 0+{-# INLINE findUnmatchedClose' #-}++findUnmatchedCloseFar :: Word64 -> Word64 -> DVS.Vector Word16 -> Count+findUnmatchedCloseFar c p v = findUnmatchedClose' c (p - vd) (HW.drop vi v) + vd+ where vi = p `div` elemBitLength v+ vd = vi * elemBitLength v+{-# INLINE findUnmatchedCloseFar #-}
+ src/HaskellWorks/Data/BalancedParens/Internal/Broadword/FindUnmatchedCloseFar/Vector32.hs view
@@ -0,0 +1,42 @@+module HaskellWorks.Data.BalancedParens.Internal.Broadword.FindUnmatchedCloseFar.Vector32+ ( findUnmatchedCloseFar+ ) where++import Data.Int+import Data.Word+import HaskellWorks.Data.AtIndex+import HaskellWorks.Data.Bits.BitLength+import HaskellWorks.Data.Int.Unsigned+import HaskellWorks.Data.Positioning++import qualified Data.Vector.Storable as DVS+import qualified HaskellWorks.Data.BalancedParens.Internal.Broadword.FindUnmatchedCloseFar.Word32 as BWW32+import qualified HaskellWorks.Data.Drop as HW+import qualified HaskellWorks.Data.Length as HW++findUnmatchedCloseCont :: Int64 -> Count -> DVS.Vector Word32 -> Count+findUnmatchedCloseCont i c v = if i < HW.end v+ then case BWW32.findUnmatchedCloseFar c 0 w of+ q -> if q >= bitLength w+ then findUnmatchedCloseCont (i + 1) (q - bitLength w) v+ else b + q+ else b + c+ where b = unsigned i * bitLength w -- base+ w = v !!! fromIntegral i+{-# INLINE findUnmatchedCloseCont #-}++findUnmatchedClose' :: Word64 -> Word64 -> DVS.Vector Word32 -> Count+findUnmatchedClose' c p v = if DVS.length v > 0+ then case BWW32.findUnmatchedCloseFar c p w of+ q -> if q >= bitLength w+ then findUnmatchedCloseCont 1 (q - bitLength w) v+ else q+ else p * 2 + c+ where w = v !!! 0+{-# INLINE findUnmatchedClose' #-}++findUnmatchedCloseFar :: Word64 -> Word64 -> DVS.Vector Word32 -> Count+findUnmatchedCloseFar c p v = findUnmatchedClose' c (p - vd) (HW.drop vi v) + vd+ where vi = p `div` elemBitLength v+ vd = vi * elemBitLength v+{-# INLINE findUnmatchedCloseFar #-}
+ src/HaskellWorks/Data/BalancedParens/Internal/Broadword/FindUnmatchedCloseFar/Vector64.hs view
@@ -0,0 +1,42 @@+module HaskellWorks.Data.BalancedParens.Internal.Broadword.FindUnmatchedCloseFar.Vector64+ ( findUnmatchedCloseFar+ ) where++import Data.Int+import Data.Word+import HaskellWorks.Data.AtIndex+import HaskellWorks.Data.Bits.BitLength+import HaskellWorks.Data.Int.Unsigned+import HaskellWorks.Data.Positioning++import qualified Data.Vector.Storable as DVS+import qualified HaskellWorks.Data.BalancedParens.Internal.Broadword.FindUnmatchedCloseFar.Word64 as BWW64+import qualified HaskellWorks.Data.Drop as HW+import qualified HaskellWorks.Data.Length as HW++findUnmatchedCloseCont :: Int64 -> Count -> DVS.Vector Word64 -> Count+findUnmatchedCloseCont i c v = if i < HW.end v+ then case BWW64.findUnmatchedCloseFar c 0 w of+ q -> if q >= bitLength w+ then findUnmatchedCloseCont (i + 1) (q - bitLength w) v+ else b + q+ else b + c+ where b = unsigned i * bitLength w -- base+ w = v !!! fromIntegral i+{-# INLINE findUnmatchedCloseCont #-}++findUnmatchedClose' :: Word64 -> Word64 -> DVS.Vector Word64 -> Count+findUnmatchedClose' c p v = if DVS.length v > 0+ then case BWW64.findUnmatchedCloseFar c p w of+ q -> if q >= bitLength w+ then findUnmatchedCloseCont 1 (q - bitLength w) v+ else q+ else p * 2 + c+ where w = v !!! 0+{-# INLINE findUnmatchedClose' #-}++findUnmatchedCloseFar :: Word64 -> Word64 -> DVS.Vector Word64 -> Count+findUnmatchedCloseFar c p v = findUnmatchedClose' c (p - vd) (HW.drop vi v) + vd+ where vi = p `div` elemBitLength v+ vd = vi * elemBitLength v+{-# INLINE findUnmatchedCloseFar #-}
+ src/HaskellWorks/Data/BalancedParens/Internal/Broadword/FindUnmatchedCloseFar/Vector8.hs view
@@ -0,0 +1,42 @@+module HaskellWorks.Data.BalancedParens.Internal.Broadword.FindUnmatchedCloseFar.Vector8+ ( findUnmatchedCloseFar+ ) where++import Data.Int+import Data.Word+import HaskellWorks.Data.AtIndex+import HaskellWorks.Data.Bits.BitLength+import HaskellWorks.Data.Int.Unsigned+import HaskellWorks.Data.Positioning++import qualified Data.Vector.Storable as DVS+import qualified HaskellWorks.Data.BalancedParens.Internal.Broadword.FindUnmatchedCloseFar.Word8 as BWW8+import qualified HaskellWorks.Data.Drop as HW+import qualified HaskellWorks.Data.Length as HW++findUnmatchedCloseCont :: Int64 -> Count -> DVS.Vector Word8 -> Count+findUnmatchedCloseCont i c v = if i < HW.end v+ then case BWW8.findUnmatchedCloseFar c 0 w of+ q -> if q >= bitLength w+ then findUnmatchedCloseCont (i + 1) (q - bitLength w) v+ else b + q+ else b + c+ where b = unsigned i * bitLength w -- base+ w = v !!! fromIntegral i+{-# INLINE findUnmatchedCloseCont #-}++findUnmatchedClose' :: Word64 -> Word64 -> DVS.Vector Word8 -> Count+findUnmatchedClose' c p v = if DVS.length v > 0+ then case BWW8.findUnmatchedCloseFar c p w of+ q -> if q >= bitLength w+ then findUnmatchedCloseCont 1 (q - bitLength w) v+ else q+ else p * 2 + c+ where w = v !!! 0+{-# INLINE findUnmatchedClose' #-}++findUnmatchedCloseFar :: Word64 -> Word64 -> DVS.Vector Word8 -> Count+findUnmatchedCloseFar c p v = findUnmatchedClose' c (p - vd) (HW.drop vi v) + vd+ where vi = p `div` elemBitLength v+ vd = vi * elemBitLength v+{-# INLINE findUnmatchedCloseFar #-}
src/HaskellWorks/Data/BalancedParens/Internal/Broadword/FindUnmatchedCloseFar/Word16.hs view
@@ -1,21 +1,17 @@ {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE FlexibleInstances #-}-{-# LANGUAGE InstanceSigs #-} {-# LANGUAGE ScopedTypeVariables #-} module HaskellWorks.Data.BalancedParens.Internal.Broadword.FindUnmatchedCloseFar.Word16 ( findUnmatchedCloseFar- , findClose ) where import Data.Int import Data.Word-import HaskellWorks.Data.BalancedParens.CloseAt import HaskellWorks.Data.Bits.BitWise import HaskellWorks.Data.Bits.Broadword.Word16 import HaskellWorks.Data.Int.Narrow import HaskellWorks.Data.Int.Widen-import HaskellWorks.Data.Positioning muk1 :: Word16 muk1 = 0x3333@@ -143,17 +139,3 @@ rrr + p {-# INLINE findUnmatchedCloseFar #-}---- | Find the position of the matching close parenthesis.------ The position argument and return value is one-based.------ If the parenthesis at the input position is an a close, then that is considered the--- matching close parenthesis.-findClose :: Word16 -> Count -> Maybe Count-findClose v p = if p > 0- then if closeAt v p- then Just p- else let q = findUnmatchedCloseFar 0 p v in Just (q + 1)- else Just 0-{-# INLINE findClose #-}
src/HaskellWorks/Data/BalancedParens/Internal/Broadword/FindUnmatchedCloseFar/Word32.hs view
@@ -1,21 +1,17 @@ {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE FlexibleInstances #-}-{-# LANGUAGE InstanceSigs #-} {-# LANGUAGE ScopedTypeVariables #-} module HaskellWorks.Data.BalancedParens.Internal.Broadword.FindUnmatchedCloseFar.Word32 ( findUnmatchedCloseFar- , findClose ) where import Data.Int import Data.Word-import HaskellWorks.Data.BalancedParens.CloseAt import HaskellWorks.Data.Bits.BitWise import HaskellWorks.Data.Bits.Broadword.Word32 import HaskellWorks.Data.Int.Narrow import HaskellWorks.Data.Int.Widen-import HaskellWorks.Data.Positioning muk1 :: Word32 muk1 = 0x33333333@@ -169,17 +165,3 @@ rrr + p {-# INLINE findUnmatchedCloseFar #-}---- | Find the position of the matching close parenthesis.------ The position argument and return value is one-based.------ If the parenthesis at the input position is an a close, then that is considered the--- matching close parenthesis.-findClose :: Word32 -> Count -> Maybe Count-findClose v p = if p > 0- then if closeAt v p- then Just p- else let q = findUnmatchedCloseFar 0 p v in Just (q + 1)- else Just 0-{-# INLINE findClose #-}
src/HaskellWorks/Data/BalancedParens/Internal/Broadword/FindUnmatchedCloseFar/Word64.hs view
@@ -1,19 +1,15 @@ {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE FlexibleInstances #-}-{-# LANGUAGE InstanceSigs #-} {-# LANGUAGE ScopedTypeVariables #-} module HaskellWorks.Data.BalancedParens.Internal.Broadword.FindUnmatchedCloseFar.Word64 ( findUnmatchedCloseFar- , findClose ) where import Data.Int import Data.Word-import HaskellWorks.Data.BalancedParens.CloseAt import HaskellWorks.Data.Bits.BitWise import HaskellWorks.Data.Bits.Broadword.Word64-import HaskellWorks.Data.Positioning muk1 :: Word64 muk1 = 0x3333333333333333@@ -193,17 +189,3 @@ rrr + p {-# INLINE findUnmatchedCloseFar #-}---- | Find the position of the matching close parenthesis.------ The position argument and return value is one-based.------ If the parenthesis at the input position is an a close, then that is considered the--- matching close parenthesis.-findClose :: Word64 -> Count -> Maybe Count-findClose v p = if p > 0- then if closeAt v p- then Just p- else let q = findUnmatchedCloseFar 0 p v in Just (q + 1)- else Just 0-{-# INLINE findClose #-}
src/HaskellWorks/Data/BalancedParens/Internal/Broadword/FindUnmatchedCloseFar/Word8.hs view
@@ -1,21 +1,17 @@ {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE FlexibleInstances #-}-{-# LANGUAGE InstanceSigs #-} {-# LANGUAGE ScopedTypeVariables #-} module HaskellWorks.Data.BalancedParens.Internal.Broadword.FindUnmatchedCloseFar.Word8 ( findUnmatchedCloseFar- , findClose ) where import Data.Int import Data.Word-import HaskellWorks.Data.BalancedParens.CloseAt import HaskellWorks.Data.Bits.BitWise import HaskellWorks.Data.Bits.Broadword.Word8 import HaskellWorks.Data.Int.Narrow import HaskellWorks.Data.Int.Widen-import HaskellWorks.Data.Positioning muk1 :: Word8 muk1 = 0x33@@ -118,47 +114,3 @@ rrr + p {-# INLINE findUnmatchedCloseFar #-}---- | Find the position of the matching close parenthesis.------ The position argument and return value is one-based.------ If the parenthesis at the input position is an a close, then that is considered the--- matching close parenthesis.------ >>> import HaskellWorks.Data.Bits.BitRead--- >>> import Data.Maybe------ The following scans for the matching close parenthesis for the open parenthesis at position 1:------ >>> findClose (fromJust $ bitRead "10000000") 1--- Just 2------ >>> findClose (fromJust $ bitRead "11000000") 1--- Just 4------ >>> findClose (fromJust $ bitRead "11010000") 1--- Just 6------ The following scans for the matching close parenthesis for the open parenthesis at position 2:------ >>> findClose (fromJust $ bitRead "11010000") 2--- Just 3------ If the input position has a close parenthesis, then that position is returned:------ >>> findClose (fromJust $ bitRead "11010000") 3--- Just 3------ The scan can continue past the end of the input word because every bit after then end of the--- word is considered to be zero, which is a closing parenthesis:------ >>> findClose (fromJust $ bitRead "11111110") 1--- Just 14-findClose :: Word8 -> Count -> Maybe Count-findClose v p = if p > 0- then if closeAt v p- then Just p- else let q = findUnmatchedCloseFar 0 p v in Just (q + 1)- else Just (findUnmatchedCloseFar 1 p v)-{-# INLINE findClose #-}
src/HaskellWorks/Data/BalancedParens/Internal/Broadword/Word64.hs view
@@ -1,7 +1,6 @@ {-# LANGUAGE BangPatterns #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE FlexibleInstances #-}-{-# LANGUAGE InstanceSigs #-} {-# LANGUAGE ScopedTypeVariables #-} module HaskellWorks.Data.BalancedParens.Internal.Broadword.Word64
src/HaskellWorks/Data/BalancedParens/Internal/List.hs view
@@ -9,7 +9,7 @@ import qualified HaskellWorks.Data.BalancedParens.Internal.Word as W chunkBy :: Int -> [a] -> [[a]]-chunkBy n bs = case (take n bs, drop n bs) of+chunkBy n bs = case splitAt n bs of (as, zs) -> if null zs then [as] else as:chunkBy n zs toBoolsDiff :: [Word64] -> [Bool] -> [Bool]
src/HaskellWorks/Data/BalancedParens/Internal/ParensSeq.hs view
@@ -5,7 +5,6 @@ {-# LANGUAGE GeneralizedNewtypeDeriving #-} {-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE NamedFieldPuns #-}-{-# LANGUAGE StandaloneDeriving #-} {-# LANGUAGE TypeFamilies #-} module HaskellWorks.Data.BalancedParens.Internal.ParensSeq
src/HaskellWorks/Data/BalancedParens/Internal/Slow/FindCloseN/Generic.hs view
@@ -7,6 +7,24 @@ import HaskellWorks.Data.Bits.BitWise import HaskellWorks.Data.Positioning +-- | Find the position of the corresponding close parenthesis carrying in a number of open parentheses starting from a given position.+--+-- All positions are one based.+--+-- This is a reference implementation.+--+-- >>> :set -XTypeApplications+-- >>> import HaskellWorks.Data.Bits.BitRead+-- >>> import Data.Maybe+-- >>> import Data.Word+-- >>> findCloseN (fromJust (bitRead @Word64 "1100000")) 0 1+-- Just 4+-- >>> findCloseN (fromJust (bitRead @Word64 "1100000")) 0 2+-- Just 3+-- >>> findCloseN (fromJust (bitRead @Word64 "1100000")) 1 1+-- Just 5+-- >>> findCloseN (fromJust (bitRead @Word64 "1100000")) 1 2+-- Just 4 findCloseN :: (BitLength a, CloseAt a, TestBit a) => a -> Count -> Count -> Maybe Count findCloseN v c p = if 0 < p then if v `closeAt` p
+ src/HaskellWorks/Data/BalancedParens/Internal/Slow/FindUnmatchedCloseFar/Vector16.hs view
@@ -0,0 +1,82 @@++module HaskellWorks.Data.BalancedParens.Internal.Slow.FindUnmatchedCloseFar.Vector16+ ( findUnmatchedCloseFar+ ) where++import Data.Word+import HaskellWorks.Data.Bits.BitLength+import HaskellWorks.Data.Bits.BitWise+import HaskellWorks.Data.Int.Signed++import qualified Data.Vector.Storable as DVS++-- | Find the position of the first unmatch parenthesis.+--+-- The digits 1 and 0 are treated as an open parenthesis and closing parenthesis respectively.+--+-- All positions are indexed from zero. If the search runs out of bits, then continue as if there remain an infinite+-- string of zeros.+--+-- >>> import HaskellWorks.Data.Bits.BitRead+-- >>> import Data.Maybe+--+-- The following scans for the first unmatched closing parenthesis from the beginning of the bit string:+--+-- >>> findUnmatchedCloseFar 0 0 $ fromJust $ bitRead "00000000"+-- 0+--+-- The following scans for the first unmatched closing parenthesis after skipping one bit from the beginning of the+-- bit string:+--+-- >>> findUnmatchedCloseFar 0 1 $ fromJust $ bitRead "00000000"+-- 1+--+-- The following scans for the first unmatched closing parenthesis from the beginning of the bit string. To find+-- unmatched parenthesis, the scan passes over the first parent of matching parentheses:+--+-- >>> findUnmatchedCloseFar 0 0 $ fromJust $ bitRead "10000000"+-- 2+--+-- The following scans for the first unmatched closing parenthesis from the beginning of the bit string, but runs+-- out of bits. The scan continues as if there an inifinite string of zero bits follows, the first of which is at+-- position 64, which also happens to be the position of the unmatched parenthesis.+--+-- >>> findUnmatchedCloseFar 0 0 $ fromJust $ bitRead "11110000"+-- 8+--+-- The following scans for the first unmatched closing parenthesis from the beginning of the bit string, but runs+-- out of bits. The scan continues as if there an inifinite string of zero bits follows and we don't get to the+-- unmatched parenthesis until position 128.+--+-- >>> findUnmatchedCloseFar 0 0 $ fromJust $ bitRead "11111111"+-- 16+--+-- Following are some more examples:+--+-- >>> findUnmatchedCloseFar 0 0 $ fromJust $ bitRead "11110000"+-- 8+-- >>> findUnmatchedCloseFar 0 1 $ fromJust $ bitRead "11110000"+-- 7+-- >>> findUnmatchedCloseFar 0 2 $ fromJust $ bitRead "11110000"+-- 6+-- >>> findUnmatchedCloseFar 0 3 $ fromJust $ bitRead "11110000"+-- 5+-- >>> findUnmatchedCloseFar 0 4 $ fromJust $ bitRead "11110000"+-- 4+-- >>> findUnmatchedCloseFar 0 5 $ fromJust $ bitRead "11110000"+-- 5+-- >>> findUnmatchedCloseFar 0 6 $ fromJust $ bitRead "11110000"+-- 6+-- >>> findUnmatchedCloseFar 0 7 $ fromJust $ bitRead "11110000"+-- 7+-- >>> findUnmatchedCloseFar 0 8 $ fromJust $ bitRead "11110000"+-- 8+findUnmatchedCloseFar :: Word64 -> Word64 -> DVS.Vector Word16 -> Word64+findUnmatchedCloseFar d i v = if i < bitLength v+ then if v .?. signed i+ then findUnmatchedCloseFar (d + 1) (i + 1) v+ else if d == 0+ then i+ else findUnmatchedCloseFar (d - 1) (i + 1) v+ else bitLength v + d+{-# INLINE findUnmatchedCloseFar #-}
+ src/HaskellWorks/Data/BalancedParens/Internal/Slow/FindUnmatchedCloseFar/Vector32.hs view
@@ -0,0 +1,82 @@++module HaskellWorks.Data.BalancedParens.Internal.Slow.FindUnmatchedCloseFar.Vector32+ ( findUnmatchedCloseFar+ ) where++import Data.Word+import HaskellWorks.Data.Bits.BitLength+import HaskellWorks.Data.Bits.BitWise+import HaskellWorks.Data.Int.Signed++import qualified Data.Vector.Storable as DVS++-- | Find the position of the first unmatch parenthesis.+--+-- The digits 1 and 0 are treated as an open parenthesis and closing parenthesis respectively.+--+-- All positions are indexed from zero. If the search runs out of bits, then continue as if there remain an infinite+-- string of zeros.+--+-- >>> import HaskellWorks.Data.Bits.BitRead+-- >>> import Data.Maybe+--+-- The following scans for the first unmatched closing parenthesis from the beginning of the bit string:+--+-- >>> findUnmatchedCloseFar 0 0 $ fromJust $ bitRead "00000000"+-- 0+--+-- The following scans for the first unmatched closing parenthesis after skipping one bit from the beginning of the+-- bit string:+--+-- >>> findUnmatchedCloseFar 0 1 $ fromJust $ bitRead "00000000"+-- 1+--+-- The following scans for the first unmatched closing parenthesis from the beginning of the bit string. To find+-- unmatched parenthesis, the scan passes over the first parent of matching parentheses:+--+-- >>> findUnmatchedCloseFar 0 0 $ fromJust $ bitRead "10000000"+-- 2+--+-- The following scans for the first unmatched closing parenthesis from the beginning of the bit string, but runs+-- out of bits. The scan continues as if there an inifinite string of zero bits follows, the first of which is at+-- position 64, which also happens to be the position of the unmatched parenthesis.+--+-- >>> findUnmatchedCloseFar 0 0 $ fromJust $ bitRead "11110000"+-- 8+--+-- The following scans for the first unmatched closing parenthesis from the beginning of the bit string, but runs+-- out of bits. The scan continues as if there an inifinite string of zero bits follows and we don't get to the+-- unmatched parenthesis until position 128.+--+-- >>> findUnmatchedCloseFar 0 0 $ fromJust $ bitRead "11111111"+-- 16+--+-- Following are some more examples:+--+-- >>> findUnmatchedCloseFar 0 0 $ fromJust $ bitRead "11110000"+-- 8+-- >>> findUnmatchedCloseFar 0 1 $ fromJust $ bitRead "11110000"+-- 7+-- >>> findUnmatchedCloseFar 0 2 $ fromJust $ bitRead "11110000"+-- 6+-- >>> findUnmatchedCloseFar 0 3 $ fromJust $ bitRead "11110000"+-- 5+-- >>> findUnmatchedCloseFar 0 4 $ fromJust $ bitRead "11110000"+-- 4+-- >>> findUnmatchedCloseFar 0 5 $ fromJust $ bitRead "11110000"+-- 5+-- >>> findUnmatchedCloseFar 0 6 $ fromJust $ bitRead "11110000"+-- 6+-- >>> findUnmatchedCloseFar 0 7 $ fromJust $ bitRead "11110000"+-- 7+-- >>> findUnmatchedCloseFar 0 8 $ fromJust $ bitRead "11110000"+-- 8+findUnmatchedCloseFar :: Word64 -> Word64 -> DVS.Vector Word32 -> Word64+findUnmatchedCloseFar d i v = if i < bitLength v+ then if v .?. signed i+ then findUnmatchedCloseFar (d + 1) (i + 1) v+ else if d == 0+ then i+ else findUnmatchedCloseFar (d - 1) (i + 1) v+ else bitLength v + d+{-# INLINE findUnmatchedCloseFar #-}
+ src/HaskellWorks/Data/BalancedParens/Internal/Slow/FindUnmatchedCloseFar/Vector64.hs view
@@ -0,0 +1,82 @@++module HaskellWorks.Data.BalancedParens.Internal.Slow.FindUnmatchedCloseFar.Vector64+ ( findUnmatchedCloseFar+ ) where++import Data.Word+import HaskellWorks.Data.Bits.BitLength+import HaskellWorks.Data.Bits.BitWise+import HaskellWorks.Data.Int.Signed++import qualified Data.Vector.Storable as DVS++-- | Find the position of the first unmatch parenthesis.+--+-- The digits 1 and 0 are treated as an open parenthesis and closing parenthesis respectively.+--+-- All positions are indexed from zero. If the search runs out of bits, then continue as if there remain an infinite+-- string of zeros.+--+-- >>> import HaskellWorks.Data.Bits.BitRead+-- >>> import Data.Maybe+--+-- The following scans for the first unmatched closing parenthesis from the beginning of the bit string:+--+-- >>> findUnmatchedCloseFar 0 0 $ fromJust $ bitRead "00000000"+-- 0+--+-- The following scans for the first unmatched closing parenthesis after skipping one bit from the beginning of the+-- bit string:+--+-- >>> findUnmatchedCloseFar 0 1 $ fromJust $ bitRead "00000000"+-- 1+--+-- The following scans for the first unmatched closing parenthesis from the beginning of the bit string. To find+-- unmatched parenthesis, the scan passes over the first parent of matching parentheses:+--+-- >>> findUnmatchedCloseFar 0 0 $ fromJust $ bitRead "10000000"+-- 2+--+-- The following scans for the first unmatched closing parenthesis from the beginning of the bit string, but runs+-- out of bits. The scan continues as if there an inifinite string of zero bits follows, the first of which is at+-- position 64, which also happens to be the position of the unmatched parenthesis.+--+-- >>> findUnmatchedCloseFar 0 0 $ fromJust $ bitRead "11110000"+-- 8+--+-- The following scans for the first unmatched closing parenthesis from the beginning of the bit string, but runs+-- out of bits. The scan continues as if there an inifinite string of zero bits follows and we don't get to the+-- unmatched parenthesis until position 128.+--+-- >>> findUnmatchedCloseFar 0 0 $ fromJust $ bitRead "11111111"+-- 16+--+-- Following are some more examples:+--+-- >>> findUnmatchedCloseFar 0 0 $ fromJust $ bitRead "11110000"+-- 8+-- >>> findUnmatchedCloseFar 0 1 $ fromJust $ bitRead "11110000"+-- 7+-- >>> findUnmatchedCloseFar 0 2 $ fromJust $ bitRead "11110000"+-- 6+-- >>> findUnmatchedCloseFar 0 3 $ fromJust $ bitRead "11110000"+-- 5+-- >>> findUnmatchedCloseFar 0 4 $ fromJust $ bitRead "11110000"+-- 4+-- >>> findUnmatchedCloseFar 0 5 $ fromJust $ bitRead "11110000"+-- 5+-- >>> findUnmatchedCloseFar 0 6 $ fromJust $ bitRead "11110000"+-- 6+-- >>> findUnmatchedCloseFar 0 7 $ fromJust $ bitRead "11110000"+-- 7+-- >>> findUnmatchedCloseFar 0 8 $ fromJust $ bitRead "11110000"+-- 8+findUnmatchedCloseFar :: Word64 -> Word64 -> DVS.Vector Word64 -> Word64+findUnmatchedCloseFar d i v = if i < bitLength v+ then if v .?. signed i+ then findUnmatchedCloseFar (d + 1) (i + 1) v+ else if d == 0+ then i+ else findUnmatchedCloseFar (d - 1) (i + 1) v+ else bitLength v + d+{-# INLINE findUnmatchedCloseFar #-}
+ src/HaskellWorks/Data/BalancedParens/Internal/Slow/FindUnmatchedCloseFar/Vector8.hs view
@@ -0,0 +1,82 @@++module HaskellWorks.Data.BalancedParens.Internal.Slow.FindUnmatchedCloseFar.Vector8+ ( findUnmatchedCloseFar+ ) where++import Data.Word+import HaskellWorks.Data.Bits.BitLength+import HaskellWorks.Data.Bits.BitWise+import HaskellWorks.Data.Int.Signed++import qualified Data.Vector.Storable as DVS++-- | Find the position of the first unmatch parenthesis.+--+-- The digits 1 and 0 are treated as an open parenthesis and closing parenthesis respectively.+--+-- All positions are indexed from zero. If the search runs out of bits, then continue as if there remain an infinite+-- string of zeros.+--+-- >>> import HaskellWorks.Data.Bits.BitRead+-- >>> import Data.Maybe+--+-- The following scans for the first unmatched closing parenthesis from the beginning of the bit string:+--+-- >>> findUnmatchedCloseFar 0 0 $ fromJust $ bitRead "00000000"+-- 0+--+-- The following scans for the first unmatched closing parenthesis after skipping one bit from the beginning of the+-- bit string:+--+-- >>> findUnmatchedCloseFar 0 1 $ fromJust $ bitRead "00000000"+-- 1+--+-- The following scans for the first unmatched closing parenthesis from the beginning of the bit string. To find+-- unmatched parenthesis, the scan passes over the first parent of matching parentheses:+--+-- >>> findUnmatchedCloseFar 0 0 $ fromJust $ bitRead "10000000"+-- 2+--+-- The following scans for the first unmatched closing parenthesis from the beginning of the bit string, but runs+-- out of bits. The scan continues as if there an inifinite string of zero bits follows, the first of which is at+-- position 64, which also happens to be the position of the unmatched parenthesis.+--+-- >>> findUnmatchedCloseFar 0 0 $ fromJust $ bitRead "11110000"+-- 8+--+-- The following scans for the first unmatched closing parenthesis from the beginning of the bit string, but runs+-- out of bits. The scan continues as if there an inifinite string of zero bits follows and we don't get to the+-- unmatched parenthesis until position 128.+--+-- >>> findUnmatchedCloseFar 0 0 $ fromJust $ bitRead "11111111"+-- 16+--+-- Following are some more examples:+--+-- >>> findUnmatchedCloseFar 0 0 $ fromJust $ bitRead "11110000"+-- 8+-- >>> findUnmatchedCloseFar 0 1 $ fromJust $ bitRead "11110000"+-- 7+-- >>> findUnmatchedCloseFar 0 2 $ fromJust $ bitRead "11110000"+-- 6+-- >>> findUnmatchedCloseFar 0 3 $ fromJust $ bitRead "11110000"+-- 5+-- >>> findUnmatchedCloseFar 0 4 $ fromJust $ bitRead "11110000"+-- 4+-- >>> findUnmatchedCloseFar 0 5 $ fromJust $ bitRead "11110000"+-- 5+-- >>> findUnmatchedCloseFar 0 6 $ fromJust $ bitRead "11110000"+-- 6+-- >>> findUnmatchedCloseFar 0 7 $ fromJust $ bitRead "11110000"+-- 7+-- >>> findUnmatchedCloseFar 0 8 $ fromJust $ bitRead "11110000"+-- 8+findUnmatchedCloseFar :: Word64 -> Word64 -> DVS.Vector Word8 -> Word64+findUnmatchedCloseFar d i v = if i < bitLength v+ then if v .?. signed i+ then findUnmatchedCloseFar (d + 1) (i + 1) v+ else if d == 0+ then i+ else findUnmatchedCloseFar (d - 1) (i + 1) v+ else bitLength v + d+{-# INLINE findUnmatchedCloseFar #-}
src/HaskellWorks/Data/BalancedParens/Internal/Slow/FindUnmatchedCloseFar/Word16.hs view
@@ -1,5 +1,3 @@-{-# LANGUAGE LambdaCase #-}- module HaskellWorks.Data.BalancedParens.Internal.Slow.FindUnmatchedCloseFar.Word16 ( findUnmatchedCloseFar ) where
src/HaskellWorks/Data/BalancedParens/Internal/Slow/FindUnmatchedCloseFar/Word32.hs view
@@ -1,5 +1,3 @@-{-# LANGUAGE LambdaCase #-}- module HaskellWorks.Data.BalancedParens.Internal.Slow.FindUnmatchedCloseFar.Word32 ( findUnmatchedCloseFar ) where
src/HaskellWorks/Data/BalancedParens/Internal/Slow/FindUnmatchedCloseFar/Word64.hs view
@@ -1,5 +1,3 @@-{-# LANGUAGE LambdaCase #-}- module HaskellWorks.Data.BalancedParens.Internal.Slow.FindUnmatchedCloseFar.Word64 ( findUnmatchedCloseFar ) where
src/HaskellWorks/Data/BalancedParens/Internal/Slow/FindUnmatchedCloseFar/Word8.hs view
@@ -1,5 +1,3 @@-{-# LANGUAGE LambdaCase #-}- module HaskellWorks.Data.BalancedParens.Internal.Slow.FindUnmatchedCloseFar.Word8 ( findUnmatchedCloseFar ) where
test/HaskellWorks/Data/BalancedParens/FindCloseNSpec.hs view
@@ -12,8 +12,9 @@ import qualified Hedgehog.Gen as G import qualified Hedgehog.Range as R -{-# ANN module ("HLint: ignore Redundant do" :: String) #-}-{-# ANN module ("HLint: ignore Reduce duplication" :: String) #-}+{- HLINT ignore "Redundant do" -}+{- HLINT ignore "Redundant return" -}+{- HLINT ignore "Reduce duplication" -} spec :: Spec spec = describe "HaskellWorks.Data.BalancedParens.FindCloseNSpec" $ do
test/HaskellWorks/Data/BalancedParens/Internal/Broadword/FindClose/Vector16Spec.hs view
@@ -19,9 +19,10 @@ import qualified Hedgehog.Gen as G import qualified Hedgehog.Range as R -{-# ANN module ("HLint: ignore Evaluate" :: String) #-}-{-# ANN module ("HLint: ignore Reduce duplication" :: String) #-}-{-# ANN module ("HLint: ignore Redundant do" :: String) #-}+{- HLINT ignore "Evaluate" -}+{- HLINT ignore "Redundant do" -}+{- HLINT ignore "Redundant return" -}+{- HLINT ignore "Reduce duplication" -} spec :: Spec spec = describe "HaskellWorks.Data.BalancedParens.Internal.Broadword.FindClose.Vector16Spec" $ do
test/HaskellWorks/Data/BalancedParens/Internal/Broadword/FindClose/Vector32Spec.hs view
@@ -19,9 +19,10 @@ import qualified Hedgehog.Gen as G import qualified Hedgehog.Range as R -{-# ANN module ("HLint: ignore Evaluate" :: String) #-}-{-# ANN module ("HLint: ignore Reduce duplication" :: String) #-}-{-# ANN module ("HLint: ignore Redundant do" :: String) #-}+{- HLINT ignore "Evaluate" -}+{- HLINT ignore "Redundant do" -}+{- HLINT ignore "Redundant return" -}+{- HLINT ignore "Reduce duplication" -} spec :: Spec spec = describe "HaskellWorks.Data.BalancedParens.Internal.Broadword.FindClose.Vector32Spec" $ do
test/HaskellWorks/Data/BalancedParens/Internal/Broadword/FindClose/Vector64Spec.hs view
@@ -14,9 +14,10 @@ import qualified Hedgehog.Gen as G import qualified Hedgehog.Range as R -{-# ANN module ("HLint: ignore Evaluate" :: String) #-}-{-# ANN module ("HLint: ignore Reduce duplication" :: String) #-}-{-# ANN module ("HLint: ignore Redundant do" :: String) #-}+{- HLINT ignore "Evaluate" -}+{- HLINT ignore "Redundant do" -}+{- HLINT ignore "Redundant return" -}+{- HLINT ignore "Reduce duplication" -} spec :: Spec spec = describe "HaskellWorks.Data.BalancedParens.Internal.Broadword.FindClose.Vector64Spec" $ do
test/HaskellWorks/Data/BalancedParens/Internal/Broadword/FindClose/Vector8Spec.hs view
@@ -18,21 +18,22 @@ import qualified Data.Vector.Storable as DVS import qualified HaskellWorks.Data.BalancedParens.FindClose as CLS import qualified HaskellWorks.Data.BalancedParens.Internal.Broadword.FindClose.Vector8 as V8+import qualified HaskellWorks.Data.BalancedParens.Internal.IO as IO import qualified HaskellWorks.Data.BalancedParens.Internal.Slow.FindCloseN.Generic as G import qualified HaskellWorks.Data.BalancedParens.RangeMin2 as RM2 import qualified HaskellWorks.Data.FromForeignRegion as IO import qualified Hedgehog.Gen as G import qualified Hedgehog.Range as R-import qualified System.Directory as IO import qualified System.IO.Unsafe as IO -{-# ANN module ("HLint: ignore Evaluate" :: String) #-}-{-# ANN module ("HLint: ignore Reduce duplication" :: String) #-}-{-# ANN module ("HLint: ignore Redundant do" :: String) #-}+{- HLINT ignore "Evaluate" -}+{- HLINT ignore "Redundant do" -}+{- HLINT ignore "Redundant return" -}+{- HLINT ignore "Reduce duplication" -} testFiles :: [FilePath] testFiles = IO.unsafePerformIO $ do- files <- IO.listDirectory "data/test"+ files <- IO.safeListDirectory "data/test" return $ L.sort (("data/test/" ++) <$> (".ib.idx" `L.isSuffixOf`) `filter` files) {-# NOINLINE testFiles #-} @@ -102,7 +103,7 @@ forM_ testFiles $ \file -> do it ("File " <> file) $ do v <- IO.mmapFromForeignRegion file- rmm2 <- pure $ RM2.mkRangeMin2 (v :: DVS.Vector Word64)+ let rmm2 = RM2.mkRangeMin2 (v :: DVS.Vector Word64) require $ withTests 100000 $ property $ do _ <- forAll $ pure file p <- forAll $ G.word64 (R.linear 1 (bitLength v))
+ test/HaskellWorks/Data/BalancedParens/Internal/Broadword/FindUnmatchedCloseFar/Vector16Spec.hs view
@@ -0,0 +1,63 @@+{-# LANGUAGE OverloadedStrings #-}+{-# LANGUAGE ScopedTypeVariables #-}++module HaskellWorks.Data.BalancedParens.Internal.Broadword.FindUnmatchedCloseFar.Vector16Spec where++import HaskellWorks.Data.Bits.BitLength+import HaskellWorks.Data.Bits.BitShow+import HaskellWorks.Data.Bits.BitWise+import HaskellWorks.Data.Int.Widen+import HaskellWorks.Hspec.Hedgehog+import Hedgehog+import Test.Hspec++import qualified Data.Vector.Storable as DVS+import qualified HaskellWorks.Data.BalancedParens.Gen as G+import qualified HaskellWorks.Data.BalancedParens.Internal.Broadword.FindUnmatchedCloseFar.Vector16 as BWV16+import qualified HaskellWorks.Data.BalancedParens.Internal.Broadword.FindUnmatchedCloseFar.Word32 as BWW32+import qualified HaskellWorks.Data.BalancedParens.Internal.Slow.FindUnmatchedCloseFar.Vector16 as SV16+import qualified Hedgehog.Gen as G+import qualified Hedgehog.Range as R++{- HLINT ignore "Evaluate" -}+{- HLINT ignore "Redundant do" -}+{- HLINT ignore "Redundant return" -}+{- HLINT ignore "Reduce duplication" -}++spec :: Spec+spec = describe "HaskellWorks.Data.BalancedParens.Internal.Broadword.FindUnmatchedCloseFar.Vector16Spec" $ do+ it "findUnmatchedCloseFar against two words" $ require $ withTests 1000 $ property $ do+ c <- forAll $ G.word64 (R.linear 0 64)+ p <- forAll $ G.word64 (R.linear 0 16)+ w0 <- forAll $ G.word16 R.constantBounded+ w1 <- forAll $ G.word16 R.constantBounded+ w <- forAll $ pure $ (widen w1 .<. bitLength w0) .|. widen w0+ v <- forAll $ pure $ DVS.fromList [w0, w1]+ annotateShow $ bitShow w+ actual <- forAll $ pure $ BWV16.findUnmatchedCloseFar c p v+ expected <- forAll $ pure $ BWW32.findUnmatchedCloseFar c p w+ actual === expected+ it "findUnmatchedCloseFar against slow" $ requireTest $ do+ v <- forAll $ pure DVS.empty+ c <- forAll $ pure 0+ p <- forAll $ pure 0+ annotateShow $ bitShow v+ actual <- forAll $ pure $ BWV16.findUnmatchedCloseFar c p v+ expected <- forAll $ pure $ SV16.findUnmatchedCloseFar c p v+ actual === expected+ it "findUnmatchedCloseFar against slow" $ requireTest $ do+ v <- forAll $ pure $ DVS.fromList [0]+ c <- forAll $ pure 1+ p <- forAll $ pure 8+ annotateShow $ bitShow v+ actual <- forAll $ pure $ BWV16.findUnmatchedCloseFar c p v+ expected <- forAll $ pure $ SV16.findUnmatchedCloseFar c p v+ actual === expected+ it "findUnmatchedCloseFar against slow" $ require $ withTests 10000 $ property $ do+ v <- forAll $ G.storableVector (R.linear 0 4) (G.word16 R.constantBounded)+ c <- forAll $ G.word64 (R.linear 0 (bitLength v))+ p <- forAll $ G.word64 (R.linear 0 (bitLength v))+ annotateShow $ bitShow v+ actual <- forAll $ pure $ BWV16.findUnmatchedCloseFar c p v+ expected <- forAll $ pure $ SV16.findUnmatchedCloseFar c p v+ actual === expected
+ test/HaskellWorks/Data/BalancedParens/Internal/Broadword/FindUnmatchedCloseFar/Vector32Spec.hs view
@@ -0,0 +1,63 @@+{-# LANGUAGE OverloadedStrings #-}+{-# LANGUAGE ScopedTypeVariables #-}++module HaskellWorks.Data.BalancedParens.Internal.Broadword.FindUnmatchedCloseFar.Vector32Spec where++import HaskellWorks.Data.Bits.BitLength+import HaskellWorks.Data.Bits.BitShow+import HaskellWorks.Data.Bits.BitWise+import HaskellWorks.Data.Int.Widen+import HaskellWorks.Hspec.Hedgehog+import Hedgehog+import Test.Hspec++import qualified Data.Vector.Storable as DVS+import qualified HaskellWorks.Data.BalancedParens.Gen as G+import qualified HaskellWorks.Data.BalancedParens.Internal.Broadword.FindUnmatchedCloseFar.Vector32 as BWV32+import qualified HaskellWorks.Data.BalancedParens.Internal.Broadword.FindUnmatchedCloseFar.Word64 as BWW64+import qualified HaskellWorks.Data.BalancedParens.Internal.Slow.FindUnmatchedCloseFar.Vector32 as SV32+import qualified Hedgehog.Gen as G+import qualified Hedgehog.Range as R++{- HLINT ignore "Evaluate" -}+{- HLINT ignore "Redundant do" -}+{- HLINT ignore "Redundant return" -}+{- HLINT ignore "Reduce duplication" -}++spec :: Spec+spec = describe "HaskellWorks.Data.BalancedParens.Internal.Broadword.FindUnmatchedCloseFar.Vector32Spec" $ do+ it "findUnmatchedCloseFar against two words" $ require $ withTests 1000 $ property $ do+ c <- forAll $ G.word64 (R.linear 0 64)+ p <- forAll $ G.word64 (R.linear 0 16)+ w0 <- forAll $ G.word32 R.constantBounded+ w1 <- forAll $ G.word32 R.constantBounded+ w <- forAll $ pure $ (widen w1 .<. bitLength w0) .|. widen w0+ v <- forAll $ pure $ DVS.fromList [w0, w1]+ annotateShow $ bitShow w+ actual <- forAll $ pure $ BWV32.findUnmatchedCloseFar c p v+ expected <- forAll $ pure $ BWW64.findUnmatchedCloseFar c p w+ actual === expected+ it "findUnmatchedCloseFar against slow" $ requireTest $ do+ v <- forAll $ pure DVS.empty+ c <- forAll $ pure 0+ p <- forAll $ pure 0+ annotateShow $ bitShow v+ actual <- forAll $ pure $ BWV32.findUnmatchedCloseFar c p v+ expected <- forAll $ pure $ SV32.findUnmatchedCloseFar c p v+ actual === expected+ it "findUnmatchedCloseFar against slow" $ requireTest $ do+ v <- forAll $ pure $ DVS.fromList [0]+ c <- forAll $ pure 1+ p <- forAll $ pure 8+ annotateShow $ bitShow v+ actual <- forAll $ pure $ BWV32.findUnmatchedCloseFar c p v+ expected <- forAll $ pure $ SV32.findUnmatchedCloseFar c p v+ actual === expected+ it "findUnmatchedCloseFar against slow" $ require $ withTests 10000 $ property $ do+ v <- forAll $ G.storableVector (R.linear 0 4) (G.word32 R.constantBounded)+ c <- forAll $ G.word64 (R.linear 0 (bitLength v))+ p <- forAll $ G.word64 (R.linear 0 (bitLength v))+ annotateShow $ bitShow v+ actual <- forAll $ pure $ BWV32.findUnmatchedCloseFar c p v+ expected <- forAll $ pure $ SV32.findUnmatchedCloseFar c p v+ actual === expected
+ test/HaskellWorks/Data/BalancedParens/Internal/Broadword/FindUnmatchedCloseFar/Vector64Spec.hs view
@@ -0,0 +1,49 @@+{-# LANGUAGE OverloadedStrings #-}+{-# LANGUAGE ScopedTypeVariables #-}++module HaskellWorks.Data.BalancedParens.Internal.Broadword.FindUnmatchedCloseFar.Vector64Spec where++import HaskellWorks.Data.Bits.BitLength+import HaskellWorks.Data.Bits.BitShow+import HaskellWorks.Hspec.Hedgehog+import Hedgehog+import Test.Hspec++import qualified Data.Vector.Storable as DVS+import qualified HaskellWorks.Data.BalancedParens.Gen as G+import qualified HaskellWorks.Data.BalancedParens.Internal.Broadword.FindUnmatchedCloseFar.Vector64 as BWV64+import qualified HaskellWorks.Data.BalancedParens.Internal.Slow.FindUnmatchedCloseFar.Vector64 as SV64+import qualified Hedgehog.Gen as G+import qualified Hedgehog.Range as R++{- HLINT ignore "Evaluate" -}+{- HLINT ignore "Redundant do" -}+{- HLINT ignore "Redundant return" -}+{- HLINT ignore "Reduce duplication" -}++spec :: Spec+spec = describe "HaskellWorks.Data.BalancedParens.Internal.Broadword.FindUnmatchedCloseFar.Vector64Spec" $ do+ it "findUnmatchedCloseFar against slow" $ requireTest $ do+ v <- forAll $ pure DVS.empty+ c <- forAll $ pure 0+ p <- forAll $ pure 0+ annotateShow $ bitShow v+ actual <- forAll $ pure $ BWV64.findUnmatchedCloseFar c p v+ expected <- forAll $ pure $ SV64.findUnmatchedCloseFar c p v+ actual === expected+ it "findUnmatchedCloseFar against slow" $ requireTest $ do+ v <- forAll $ pure $ DVS.fromList [0]+ c <- forAll $ pure 1+ p <- forAll $ pure 8+ annotateShow $ bitShow v+ actual <- forAll $ pure $ BWV64.findUnmatchedCloseFar c p v+ expected <- forAll $ pure $ SV64.findUnmatchedCloseFar c p v+ actual === expected+ it "findUnmatchedCloseFar against slow" $ require $ withTests 10000 $ property $ do+ v <- forAll $ G.storableVector (R.linear 0 4) (G.word64 R.constantBounded)+ c <- forAll $ G.word64 (R.linear 0 (bitLength v))+ p <- forAll $ G.word64 (R.linear 0 (bitLength v))+ annotateShow $ bitShow v+ actual <- forAll $ pure $ BWV64.findUnmatchedCloseFar c p v+ expected <- forAll $ pure $ SV64.findUnmatchedCloseFar c p v+ actual === expected
+ test/HaskellWorks/Data/BalancedParens/Internal/Broadword/FindUnmatchedCloseFar/Vector8Spec.hs view
@@ -0,0 +1,63 @@+{-# LANGUAGE OverloadedStrings #-}+{-# LANGUAGE ScopedTypeVariables #-}++module HaskellWorks.Data.BalancedParens.Internal.Broadword.FindUnmatchedCloseFar.Vector8Spec where++import HaskellWorks.Data.Bits.BitLength+import HaskellWorks.Data.Bits.BitShow+import HaskellWorks.Data.Bits.BitWise+import HaskellWorks.Data.Int.Widen+import HaskellWorks.Hspec.Hedgehog+import Hedgehog+import Test.Hspec++import qualified Data.Vector.Storable as DVS+import qualified HaskellWorks.Data.BalancedParens.Gen as G+import qualified HaskellWorks.Data.BalancedParens.Internal.Broadword.FindUnmatchedCloseFar.Vector8 as BWV8+import qualified HaskellWorks.Data.BalancedParens.Internal.Broadword.FindUnmatchedCloseFar.Word16 as BWW16+import qualified HaskellWorks.Data.BalancedParens.Internal.Slow.FindUnmatchedCloseFar.Vector8 as SV8+import qualified Hedgehog.Gen as G+import qualified Hedgehog.Range as R++{- HLINT ignore "Evaluate" -}+{- HLINT ignore "Redundant do" -}+{- HLINT ignore "Redundant return" -}+{- HLINT ignore "Reduce duplication" -}++spec :: Spec+spec = describe "HaskellWorks.Data.BalancedParens.Internal.Broadword.FindUnmatchedCloseFar.Vector8Spec" $ do+ it "findUnmatchedCloseFar against two words" $ require $ withTests 1000 $ property $ do+ c <- forAll $ G.word64 (R.linear 0 64)+ p <- forAll $ G.word64 (R.linear 0 8)+ w0 <- forAll $ G.word8 R.constantBounded+ w1 <- forAll $ G.word8 R.constantBounded+ w <- forAll $ pure $ (widen w1 .<. bitLength w0) .|. widen w0+ v <- forAll $ pure $ DVS.fromList [w0, w1]+ annotateShow $ bitShow w+ actual <- forAll $ pure $ BWV8.findUnmatchedCloseFar c p v+ expected <- forAll $ pure $ BWW16.findUnmatchedCloseFar c p w+ actual === expected+ it "findUnmatchedCloseFar against slow" $ requireTest $ do+ v <- forAll $ pure DVS.empty+ c <- forAll $ pure 0+ p <- forAll $ pure 0+ annotateShow $ bitShow v+ actual <- forAll $ pure $ BWV8.findUnmatchedCloseFar c p v+ expected <- forAll $ pure $ SV8.findUnmatchedCloseFar c p v+ actual === expected+ it "findUnmatchedCloseFar against slow" $ requireTest $ do+ v <- forAll $ pure $ DVS.fromList [0]+ c <- forAll $ pure 1+ p <- forAll $ pure 8+ annotateShow $ bitShow v+ actual <- forAll $ pure $ BWV8.findUnmatchedCloseFar c p v+ expected <- forAll $ pure $ SV8.findUnmatchedCloseFar c p v+ actual === expected+ it "findUnmatchedCloseFar against slow" $ require $ withTests 10000 $ property $ do+ v <- forAll $ G.storableVector (R.linear 0 4) (G.word8 R.constantBounded)+ c <- forAll $ G.word64 (R.linear 0 (bitLength v))+ p <- forAll $ G.word64 (R.linear 0 (bitLength v))+ annotateShow $ bitShow v+ actual <- forAll $ pure $ BWV8.findUnmatchedCloseFar c p v+ expected <- forAll $ pure $ SV8.findUnmatchedCloseFar c p v+ actual === expected
test/HaskellWorks/Data/BalancedParens/Internal/Broadword/FindUnmatchedCloseFar/Word16Spec.hs view
@@ -12,14 +12,16 @@ import Test.Hspec import qualified HaskellWorks.Data.BalancedParens.FindClose as C+import qualified HaskellWorks.Data.BalancedParens.Internal.Broadword.FindClose.Word16 as BW16 import qualified HaskellWorks.Data.BalancedParens.Internal.Broadword.FindUnmatchedCloseFar.Word16 as BW16 import qualified HaskellWorks.Data.BalancedParens.Internal.Slow.FindUnmatchedCloseFar.Word16 as SW16 import qualified Hedgehog.Gen as G import qualified Hedgehog.Range as R --{-# ANN module ("HLint: ignore Redundant do" :: String) #-}-{-# ANN module ("HLint: ignore Reduce duplication" :: String) #-}+{- HLINT ignore "Evaluate" -}+{- HLINT ignore "Redundant do" -}+{- HLINT ignore "Redundant return" -}+{- HLINT ignore "Reduce duplication" -} spec :: Spec spec = describe "HaskellWorks.Data.BalancedParens.Broadword.Word16Spec" $ do
test/HaskellWorks/Data/BalancedParens/Internal/Broadword/FindUnmatchedCloseFar/Word32Spec.hs view
@@ -9,13 +9,16 @@ import Test.Hspec import qualified HaskellWorks.Data.BalancedParens.FindClose as C+import qualified HaskellWorks.Data.BalancedParens.Internal.Broadword.FindClose.Word32 as BW32 import qualified HaskellWorks.Data.BalancedParens.Internal.Broadword.FindUnmatchedCloseFar.Word32 as BW32 import qualified HaskellWorks.Data.BalancedParens.Internal.Slow.FindUnmatchedCloseFar.Word32 as SW32 import qualified Hedgehog.Gen as G import qualified Hedgehog.Range as R -{-# ANN module ("HLint: ignore Redundant do" :: String) #-}-{-# ANN module ("HLint: ignore Reduce duplication" :: String) #-}+{- HLINT ignore "Evaluate" -}+{- HLINT ignore "Redundant do" -}+{- HLINT ignore "Redundant return" -}+{- HLINT ignore "Reduce duplication" -} spec :: Spec spec = describe "HaskellWorks.Data.BalancedParens.Broadword.Word32Spec" $ do
test/HaskellWorks/Data/BalancedParens/Internal/Broadword/FindUnmatchedCloseFar/Word64Spec.hs view
@@ -10,13 +10,14 @@ import Test.Hspec import qualified HaskellWorks.Data.BalancedParens.FindClose as C+import qualified HaskellWorks.Data.BalancedParens.Internal.Broadword.FindClose.Word64 as BW64 import qualified HaskellWorks.Data.BalancedParens.Internal.Broadword.FindUnmatchedCloseFar.Word64 as BW64 import qualified HaskellWorks.Data.BalancedParens.Internal.Slow.FindUnmatchedCloseFar.Word64 as SW64 import qualified Hedgehog.Gen as G import qualified Hedgehog.Range as R -{-# ANN module ("HLint: ignore Redundant do" :: String) #-}-{-# ANN module ("HLint: ignore Reduce duplication" :: String) #-}+{- HLINT ignore "Redundant do" -}+{- HLINT ignore "Redundant return" -} spec :: Spec spec = describe "HaskellWorks.Data.BalancedParens.Broadword.Word64Spec" $ do
test/HaskellWorks/Data/BalancedParens/Internal/Broadword/FindUnmatchedCloseFar/Word8Spec.hs view
@@ -9,13 +9,16 @@ import Test.Hspec import qualified HaskellWorks.Data.BalancedParens.FindClose as C+import qualified HaskellWorks.Data.BalancedParens.Internal.Broadword.FindClose.Word8 as BW8 import qualified HaskellWorks.Data.BalancedParens.Internal.Broadword.FindUnmatchedCloseFar.Word8 as BW8 import qualified HaskellWorks.Data.BalancedParens.Internal.Slow.FindUnmatchedCloseFar.Word8 as SW8 import qualified Hedgehog.Gen as G import qualified Hedgehog.Range as R -{-# ANN module ("HLint: ignore Redundant do" :: String) #-}-{-# ANN module ("HLint: ignore Reduce duplication" :: String) #-}+{- HLINT ignore "Evaluate" -}+{- HLINT ignore "Redundant do" -}+{- HLINT ignore "Redundant return" -}+{- HLINT ignore "Reduce duplication" -} spec :: Spec spec = describe "HaskellWorks.Data.BalancedParens.Broadword.Word8Spec" $ do
test/HaskellWorks/Data/BalancedParens/Internal/BroadwordSpec.hs view
@@ -20,8 +20,9 @@ import qualified Hedgehog.Gen as G import qualified Hedgehog.Range as R -{-# ANN module ("HLint: ignore Redundant do" :: String) #-}-{-# ANN module ("HLint: ignore Reduce duplication" :: String) #-}+{- HLINT ignore "Redundant do" -}+{- HLINT ignore "Redundant return" -}+{- HLINT ignore "Reduce duplication" -} newtype ShowVector a = ShowVector a deriving (Eq, BitShow, Generic)
test/HaskellWorks/Data/BalancedParens/Internal/ParensSeqSpec.hs view
@@ -1,6 +1,5 @@-{-# LANGUAGE GeneralizedNewtypeDeriving #-}-{-# LANGUAGE OverloadedStrings #-}-{-# LANGUAGE ScopedTypeVariables #-}+{-# LANGUAGE OverloadedStrings #-}+{-# LANGUAGE ScopedTypeVariables #-} module HaskellWorks.Data.BalancedParens.Internal.ParensSeqSpec where @@ -17,8 +16,9 @@ import qualified Hedgehog.Gen as G import qualified Hedgehog.Range as R -{-# ANN module ("HLint: ignore Redundant do" :: String) #-}-{-# ANN module ("HLint: ignore Reduce duplication" :: String) #-}+{- HLINT ignore "Redundant do" -}+{- HLINT ignore "Redundant return" -}+{- HLINT ignore "Reduce duplication" -} spec :: Spec spec = describe "HaskellWorks.Data.BalancedParens.Internal.ParensSeqSpec" $ do@@ -88,7 +88,7 @@ PS.firstChild ps pos === BP.firstChild bs pos it "firstChild should select first child" $ requireTest $ do let bps = "((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((()))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))"- let bs = fmap (\c -> if c == '(' then True else False) bps+ let bs = fmap (== '(') bps let ps = PS.fromBools bs PS.firstChild ps 64 === Just 65@@ -114,13 +114,13 @@ PS.toBools (ps1 >< ps2) === PS.toBools ps1 >< PS.toBools ps2 it "(<|) should cons" $ requireTest $ do- b <- forAll $ G.bool+ b <- forAll G.bool bs <- forAll $ G.bpBools (R.linear 1 1000) ps <- forAll $ pure $ PS.fromBools bs PS.toBools (b <| ps) === b:PS.toBools ps it "(|>) should snoc" $ requireTest $ do- b <- forAll $ G.bool+ b <- forAll G.bool bs <- forAll $ G.bpBools (R.linear 1 1000) ps <- forAll $ pure $ PS.fromBools bs
test/HaskellWorks/Data/BalancedParens/RangeMin2Spec.hs view
@@ -19,8 +19,9 @@ import qualified Hedgehog.Gen as G import qualified Hedgehog.Range as R -{-# ANN module ("HLint: ignore Redundant do" :: String) #-}-{-# ANN module ("HLint: ignore Reduce duplication" :: String) #-}+{- HLINT ignore "Redundant do" -}+{- HLINT ignore "Redundant return" -}+{- HLINT ignore "Reduce duplication" -} factor :: Int factor = 16384
test/HaskellWorks/Data/BalancedParens/RangeMinSpec.hs view
@@ -23,8 +23,9 @@ import qualified Hedgehog.Gen as G import qualified Hedgehog.Range as R -{-# ANN module ("ignore Redundant do" :: String) #-}-{-# ANN module ("ignore Reduce duplication" :: String) #-}+{- HLINT ignore "Redundant do" -}+{- HLINT ignore "Redundant return" -}+{- HLINT ignore "Reduce duplication" -} newtype ShowVector a = ShowVector a deriving (Eq, BitShow, Generic)
test/HaskellWorks/Data/BalancedParens/SimpleSpec.hs view
@@ -1,5 +1,4 @@-{-# LANGUAGE GeneralizedNewtypeDeriving #-}-{-# LANGUAGE ScopedTypeVariables #-}+{-# LANGUAGE ScopedTypeVariables #-} module HaskellWorks.Data.BalancedParens.SimpleSpec where @@ -17,8 +16,9 @@ import qualified Hedgehog.Gen as G import qualified Hedgehog.Range as R -{-# ANN module ("HLint: ignore Redundant do" :: String) #-}-{-# ANN module ("HLint: ignore Reduce duplication" :: String) #-}+{- HLINT ignore "Redundant do" -}+{- HLINT ignore "Redundant return" -}+{- HLINT ignore "Reduce duplication" -} spec :: Spec spec = describe "HaskellWorks.Data.BalancedParens.SimpleSpec" $ do