packages feed

rrb-vector 0.2.0.1 → 0.2.1.0

raw patch · 6 files changed

+60/−7 lines, 6 filesdep +containersPVP ok

version bump matches the API change (PVP)

Dependencies added: containers

API changes (from Hackage documentation)

+ Data.RRBVector: findIndexL :: (a -> Bool) -> Vector a -> Maybe Int
+ Data.RRBVector: findIndexR :: (a -> Bool) -> Vector a -> Maybe Int
+ Data.RRBVector: findIndicesL :: (a -> Bool) -> Vector a -> [Int]
+ Data.RRBVector: findIndicesR :: (a -> Bool) -> Vector a -> [Int]

Files

CHANGELOG.md view
@@ -1,3 +1,8 @@+# 0.2.1.0 - December 2023++* Add `findIndexL`, `findIndexR`, `findIndicesL`, `findIndicesR`+* Fix bug in `|>` & `<|` ([#10](https://github.com/konsumlamm/rrb-vector/issues/10))+ # 0.2.0.1 - October 2023  * Support `primitive-0.9` and `deepseq-1.5`
rrb-vector.cabal view
@@ -1,5 +1,5 @@ name:               rrb-vector-version:            0.2.0.1+version:            0.2.1.0 synopsis:           Efficient RRB-Vectors description:   An RRB-Vector is an efficient sequence data structure.@@ -29,8 +29,9 @@   GHC == 8.10.7   GHC == 9.0.2   GHC == 9.2.8-  GHC == 9.4.7+  GHC == 9.4.8   GHC == 9.6.3+  GHC == 9.8.1  source-repository head   type:     git@@ -59,7 +60,7 @@     Strictness   type:                 exitcode-stdio-1.0   ghc-options:          -Wall -Wno-orphans -Wno-type-defaults-  build-depends:        base, deepseq, quickcheck-classes-base, rrb-vector, tasty, tasty-quickcheck+  build-depends:        base, containers, deepseq, quickcheck-classes-base, rrb-vector, tasty, tasty-quickcheck   if impl(ghc >= 8.6)     build-depends:      nothunks   default-language:     Haskell2010
src/Data/RRBVector.hs view
@@ -33,6 +33,7 @@     , adjust, adjust'     , take, drop, splitAt     , insertAt, deleteAt+    , findIndexL, findIndexR, findIndicesL, findIndicesR     -- * With Index     --     -- | Reexported from [indexed-traversable](https://hackage.haskell.org/package/indexed-traversable).
src/Data/RRBVector/Internal.hs view
@@ -24,6 +24,7 @@     , adjust, adjust'     , take, drop, splitAt     , insertAt, deleteAt+    , findIndexL, findIndexR, findIndicesL, findIndicesR     -- * Transformations     , map, map', reverse     -- * Zipping and unzipping@@ -650,6 +651,22 @@ -- If the index is out of range, return the original vector. deleteAt :: Int -> Vector a -> Vector a deleteAt i v = let (left, right) = splitAt (i + 1) v in take i left >< right++-- | \(O(n)\). Find the first index from the left that satisfies the predicate.+findIndexL :: (a -> Bool) -> Vector a -> Maybe Int+findIndexL f = ifoldr (\i x acc -> if f x then Just i else acc) Nothing++-- | \(O(n)\). Find the first index from the right that satisfies the predicate.+findIndexR :: (a -> Bool) -> Vector a -> Maybe Int+findIndexR f = ifoldl (\i acc x -> if f x then Just i else acc) Nothing++-- | \(O(n)\). Find the indices that satisfy the predicate, starting from the left.+findIndicesL :: (a -> Bool) -> Vector a -> [Int]+findIndicesL f = ifoldr (\i x acc -> if f x then i : acc else acc) []++-- | \(O(n)\). Find the indices that satisfy the predicate, starting from the right.+findIndicesR :: (a -> Bool) -> Vector a -> [Int]+findIndicesR f = ifoldl (\i acc x -> if f x then i : acc else acc) []  -- concatenation 
src/Data/RRBVector/Internal/Array.hs view
@@ -173,17 +173,17 @@ last arr = index arr (length arr - 1)  snoc :: Array a -> a -> Array a-snoc (Array _ len arr) x = Array 0 len' $ runSmallArray $ do+snoc (Array start len arr) x = Array 0 len' $ runSmallArray $ do     sma <- newSmallArray len' x-    copySmallArray sma 0 arr 0 len+    copySmallArray sma 0 arr start len     pure sma   where     !len' = len + 1  cons :: Array a -> a -> Array a-cons (Array _ len arr) x = Array 0 len' $ runSmallArray $ do+cons (Array start len arr) x = Array 0 len' $ runSmallArray $ do     sma <- newSmallArray len' x-    copySmallArray sma 1 arr 0 len+    copySmallArray sma 1 arr start len     pure sma   where     !len' = len + 1
test/Properties.hs view
@@ -1,5 +1,7 @@ {-# LANGUAGE CPP #-} +{-# OPTIONS_GHC -Wno-incomplete-uni-patterns #-}+ module Properties     ( properties     ) where@@ -12,6 +14,7 @@ import Data.Proxy (Proxy(..)) import Prelude hiding ((==)) -- use @===@ instead +import qualified Data.Sequence as Seq import qualified Data.RRBVector as V import Test.QuickCheck.Classes.Base import Test.Tasty@@ -135,6 +138,22 @@         , testProperty "satisfies `deleteAt 0 v = drop 1 v`" $ \v -> V.deleteAt 0 v === V.drop 1 v         , testProperty "satisfies `deleteAt (length v - 1) v = take (length v - 1) v`" $ \v -> V.deleteAt (length v - 1) v === V.take (length v - 1) v         ]+    , testGroup "findIndexL"+        [ testProperty "finds the first index" $ \v (Fn f) -> V.findIndexL f v === Seq.findIndexL f (Seq.fromList (toList v))+        , testProperty "returns Nothing for the empty vector" $ \(Fn f) -> V.findIndexL f V.empty === Nothing+        ]+    , testGroup "findIndexR"+        [ testProperty "finds the last index" $ \v (Fn f) -> V.findIndexR f v === Seq.findIndexR f (Seq.fromList (toList v))+        , testProperty "returns Nothing for the empty vector" $ \(Fn f) -> V.findIndexR f V.empty === Nothing+        ]+    , localOption (QuickCheckMaxSize 1000) $ testGroup "findIndicesL"+        [ testProperty "finds the indices starting from the left" $ \v (Fn f) -> V.findIndicesL f v === Seq.findIndicesL f (Seq.fromList (toList v))+        , testProperty "returns [] for the empty vector" $ \(Fn f) -> V.findIndicesL f V.empty === []+        ]+    , localOption (QuickCheckMaxSize 1000) $ testGroup "findIndicesR"+        [ testProperty "finds the indices starting from the right" $ \v (Fn f) -> V.findIndicesR f v === Seq.findIndicesR f (Seq.fromList (toList v))+        , testProperty "returns [] for the empty vector" $ \(Fn f) -> V.findIndicesR f V.empty === []+        ]     , testGroup "reverse"         [ testProperty "reverses the vector" $ \v -> toList (V.reverse v) === reverse (toList v)         ]@@ -150,6 +169,7 @@         ]     , instances     , laws+    , issues     ]  instances :: TestTree@@ -218,4 +238,13 @@     , testLaws $ monadPlusLaws proxyV     , localOption (QuickCheckTests 500) . localOption (QuickCheckMaxSize 5000) . testLaws $ monadZipLaws proxyV     , localOption (QuickCheckMaxSize 100) . testLaws $ traversableLaws proxyV+    ]++-- old issues, to avoid regressions+issues :: TestTree+issues = testGroup "issues"+    -- https://github.com/konsumlamm/rrb-vector/issues/10+    [ testProperty "#10" $ \x v -> case V.viewl v of+            Nothing -> property True+            Just (_, v') -> x V.<| v' === V.update 0 x v     ]