Skip to content

Commit

Permalink
Merge pull request #488 from Shimuuar/strict-vector
Browse files Browse the repository at this point in the history
Add strict vector
  • Loading branch information
Shimuuar authored Apr 14, 2024
2 parents 655b5d6 + 96b0cc0 commit 219b33f
Show file tree
Hide file tree
Showing 13 changed files with 3,512 additions and 78 deletions.
32 changes: 32 additions & 0 deletions vector-bench-papi/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
Copyright (c) 2008-2012, Roman Leshchinskiy
2020-2022, Alexey Kuleshevich
2020-2022, Aleksey Khudyakov
2020-2022, Andrew Lelechenko
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

- Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.

- Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

- Neither name of the University nor the names of its contributors may be
used to endorse or promote products derived from this software without
specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY COURT OF THE UNIVERSITY OF
GLASGOW AND THE CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
UNIVERSITY COURT OF THE UNIVERSITY OF GLASGOW OR THE CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
DAMAGE.
66 changes: 33 additions & 33 deletions vector/src/Data/Vector/Generic.hs
Original file line number Diff line number Diff line change
Expand Up @@ -898,7 +898,7 @@ unsafeUpdate_stream = modifyWithBundle M.unsafeUpdate
--
-- ==== __Examples__
--
-- >>> import qualified Data.Vector as V
-- >>> import qualified Data.Vector.Strict as V
-- >>> V.accum (+) (V.fromList [1000,2000,3000]) [(2,4),(1,6),(0,3),(1,10)]
-- [1003,2016,3004]
accum :: Vector v a
Expand All @@ -914,7 +914,7 @@ accum f v us = accum_stream f v (Bundle.fromList us)
--
-- ==== __Examples__
--
-- >>> import qualified Data.Vector as V
-- >>> import qualified Data.Vector.Strict as V
-- >>> V.accumulate (+) (V.fromList [1000,2000,3000]) (V.fromList [(2,4),(1,6),(0,3),(1,10)])
-- [1003,2016,3004]
accumulate :: (Vector v a, Vector v (Int, b))
Expand Down Expand Up @@ -1039,8 +1039,8 @@ unsafeBackpermute v is = seq v
--
-- ==== __Examples__
--
-- >>> import qualified Data.Vector as V
-- >>> import qualified Data.Vector.Mutable as MV
-- >>> import qualified Data.Vector.Strict as V
-- >>> import qualified Data.Vector.Strict.Mutable as MV
-- >>> V.modify (\v -> MV.write v 0 'x') $ V.replicate 4 'a'
-- "xaaa"
modify :: Vector v a => (forall s. Mutable v s a -> ST s ()) -> v a -> v a
Expand Down Expand Up @@ -1399,7 +1399,7 @@ ifilter f = unstream
--
-- ==== __Examples__
--
-- >>> import qualified Data.Vector as V
-- >>> import qualified Data.Vector.Strict as V
-- >>> V.uniq $ V.fromList [1,3,3,200,3]
-- [1,3,200,3]
-- >>> import Data.Semigroup
Expand Down Expand Up @@ -1559,7 +1559,7 @@ unstablePartition_new f (New.New p) = runST (
--
-- ==== __Examples__
--
-- >>> import qualified Data.Vector as V
-- >>> import qualified Data.Vector.Strict as V
-- >>> V.span (<4) $ V.generate 10 id
-- ([0,1,2,3],[4,5,6,7,8,9])
span :: Vector v a => (a -> Bool) -> v a -> (v a, v a)
Expand All @@ -1573,7 +1573,7 @@ span f = break (not . f)
--
-- ==== __Examples__
--
-- >>> import qualified Data.Vector as V
-- >>> import qualified Data.Vector.Strict as V
-- >>> V.break (>4) $ V.generate 10 id
-- ([0,1,2,3,4],[5,6,7,8,9])
break :: Vector v a => (a -> Bool) -> v a -> (v a, v a)
Expand All @@ -1589,7 +1589,7 @@ break f xs = case findIndex f xs of
--
-- ==== __Examples__
--
-- >>> import qualified Data.Vector as V
-- >>> import qualified Data.Vector.Strict as V
-- >>> V.spanR (>4) $ V.generate 10 id
-- ([5,6,7,8,9],[0,1,2,3,4])
spanR :: Vector v a => (a -> Bool) -> v a -> (v a, v a)
Expand All @@ -1605,7 +1605,7 @@ spanR f = breakR (not . f)
--
-- ==== __Examples__
--
-- >>> import qualified Data.Vector as V
-- >>> import qualified Data.Vector.Strict as V
-- >>> V.breakR (<5) $ V.generate 10 id
-- ([5,6,7,8,9],[0,1,2,3,4])
breakR :: Vector v a => (a -> Bool) -> v a -> (v a, v a)
Expand All @@ -1624,7 +1624,7 @@ breakR f xs = case findIndexR f xs of
-- and each slice contains only equal elements, as determined by the equality
-- predicate function.
--
-- >>> import qualified Data.Vector as V
-- >>> import qualified Data.Vector.Strict as V
-- >>> import Data.Char (isUpper)
-- >>> V.groupBy (\a b -> isUpper a == isUpper b) (V.fromList "Mississippi River")
-- ["M","ississippi ","R","iver"]
Expand All @@ -1649,7 +1649,7 @@ groupBy f v =
--
-- This is the equivalent of 'groupBy (==)'.
--
-- >>> import qualified Data.Vector as V
-- >>> import qualified Data.Vector.Strict as V
-- >>> V.group (V.fromList "Mississippi")
-- ["M","i","ss","i","ss","i","pp","i"]
--
Expand Down Expand Up @@ -1813,7 +1813,7 @@ foldMap' f = foldl' (\acc a -> acc `mappend` f a) mempty
--
-- ==== __Examples__
--
-- >>> import qualified Data.Vector as V
-- >>> import qualified Data.Vector.Strict as V
-- >>> V.all even $ V.fromList [2, 4, 12]
-- True
-- >>> V.all even $ V.fromList [2, 4, 13]
Expand All @@ -1828,7 +1828,7 @@ all f = Bundle.and . Bundle.map f . stream
--
-- ==== __Examples__
--
-- >>> import qualified Data.Vector as V
-- >>> import qualified Data.Vector.Strict as V
-- >>> V.any even $ V.fromList [1, 3, 7]
-- False
-- >>> V.any even $ V.fromList [3, 2, 13]
Expand All @@ -1843,7 +1843,7 @@ any f = Bundle.or . Bundle.map f . stream
--
-- ==== __Examples__
--
-- >>> import qualified Data.Vector as V
-- >>> import qualified Data.Vector.Strict as V
-- >>> V.and $ V.fromList [True, False]
-- False
-- >>> V.and V.empty
Expand All @@ -1856,7 +1856,7 @@ and = Bundle.and . stream
--
-- ==== __Examples__
--
-- >>> import qualified Data.Vector as V
-- >>> import qualified Data.Vector.Strict as V
-- >>> V.or $ V.fromList [True, False]
-- True
-- >>> V.or V.empty
Expand All @@ -1869,7 +1869,7 @@ or = Bundle.or . stream
--
-- ==== __Examples__
--
-- >>> import qualified Data.Vector as V
-- >>> import qualified Data.Vector.Strict as V
-- >>> V.sum $ V.fromList [300,20,1]
-- 321
-- >>> V.sum (V.empty :: V.Vector Int)
Expand All @@ -1882,7 +1882,7 @@ sum = Bundle.foldl' (+) 0 . stream
--
-- ==== __Examples__
--
-- >>> import qualified Data.Vector as V
-- >>> import qualified Data.Vector.Strict as V
-- >>> V.product $ V.fromList [1,2,3,4]
-- 24
-- >>> V.product (V.empty :: V.Vector Int)
Expand All @@ -1896,7 +1896,7 @@ product = Bundle.foldl' (*) 1 . stream
--
-- ==== __Examples__
--
-- >>> import qualified Data.Vector as V
-- >>> import qualified Data.Vector.Strict as V
-- >>> V.maximum $ V.fromList [2, 1]
-- 2
-- >>> import Data.Semigroup
Expand All @@ -1916,7 +1916,7 @@ maximum = Bundle.foldl1' max . stream
-- ==== __Examples__
--
-- >>> import Data.Ord
-- >>> import qualified Data.Vector as V
-- >>> import qualified Data.Vector.Strict as V
-- >>> V.maximumBy (comparing fst) $ V.fromList [(2,'a'), (1,'b')]
-- (2,'a')
-- >>> V.maximumBy (comparing fst) $ V.fromList [(1,'a'), (1,'b')]
Expand All @@ -1936,7 +1936,7 @@ maximumBy cmpr = Bundle.foldl1' maxBy . stream
--
-- ==== __Examples__
--
-- >>> import qualified Data.Vector as V
-- >>> import qualified Data.Vector.Strict as V
-- >>> V.maximumOn fst $ V.fromList [(2,'a'), (1,'b')]
-- (2,'a')
-- >>> V.maximumOn fst $ V.fromList [(1,'a'), (1,'b')]
Expand All @@ -1957,7 +1957,7 @@ maximumOn f = fst . Bundle.foldl1' maxBy . Bundle.map (\a -> (a, f a)) . stream
--
-- ==== __Examples__
--
-- >>> import qualified Data.Vector as V
-- >>> import qualified Data.Vector.Strict as V
-- >>> V.minimum $ V.fromList [2, 1]
-- 1
-- >>> import Data.Semigroup
Expand All @@ -1976,7 +1976,7 @@ minimum = Bundle.foldl1' min . stream
-- ==== __Examples__
--
-- >>> import Data.Ord
-- >>> import qualified Data.Vector as V
-- >>> import qualified Data.Vector.Strict as V
-- >>> V.minimumBy (comparing fst) $ V.fromList [(2,'a'), (1,'b')]
-- (1,'b')
-- >>> V.minimumBy (comparing fst) $ V.fromList [(1,'a'), (1,'b')]
Expand All @@ -1996,7 +1996,7 @@ minimumBy cmpr = Bundle.foldl1' minBy . stream
--
-- ==== __Examples__
--
-- >>> import qualified Data.Vector as V
-- >>> import qualified Data.Vector.Strict as V
-- >>> V.minimumOn fst $ V.fromList [(2,'a'), (1,'b')]
-- (1,'b')
-- >>> V.minimumOn fst $ V.fromList [(1,'a'), (1,'b')]
Expand Down Expand Up @@ -2025,7 +2025,7 @@ maxIndex = maxIndexBy compare
-- ==== __Examples__
--
-- >>> import Data.Ord
-- >>> import qualified Data.Vector as V
-- >>> import qualified Data.Vector.Strict as V
-- >>> V.maxIndexBy (comparing fst) $ V.fromList [(2,'a'), (1,'b')]
-- 0
-- >>> V.maxIndexBy (comparing fst) $ V.fromList [(1,'a'), (1,'b')]
Expand All @@ -2051,7 +2051,7 @@ minIndex = minIndexBy compare
-- ==== __Examples__
--
-- >>> import Data.Ord
-- >>> import qualified Data.Vector as V
-- >>> import qualified Data.Vector.Strict as V
-- >>> V.minIndexBy (comparing fst) $ V.fromList [(2,'a'), (1,'b')]
-- 1
-- >>> V.minIndexBy (comparing fst) $ V.fromList [(1,'a'), (1,'b')]
Expand Down Expand Up @@ -2160,7 +2160,7 @@ sequence_ = mapM_ id
--
-- ==== __Examples__
--
-- >>> import qualified Data.Vector as V
-- >>> import qualified Data.Vector.Strict as V
-- >>> V.prescanl (+) 0 (V.fromList [1,2,3,4])
-- [0,1,3,6]
prescanl :: (Vector v a, Vector v b) => (a -> b -> a) -> a -> v b -> v a
Expand All @@ -2180,7 +2180,7 @@ prescanl' f z = unstream . inplace (S.prescanl' f z) id . stream
--
-- ==== __Examples__
--
-- >>> import qualified Data.Vector as V
-- >>> import qualified Data.Vector.Strict as V
-- >>> V.postscanl (+) 0 (V.fromList [1,2,3,4])
-- [1,3,6,10]
postscanl :: (Vector v a, Vector v b) => (a -> b -> a) -> a -> v b -> v a
Expand All @@ -2200,7 +2200,7 @@ postscanl' f z = unstream . inplace (S.postscanl' f z) id . stream
--
-- ==== __Examples__
--
-- >>> import qualified Data.Vector as V
-- >>> import qualified Data.Vector.Strict as V
-- >>> V.scanl (+) 0 (V.fromList [1,2,3,4])
-- [0,1,3,6,10]
scanl :: (Vector v a, Vector v b) => (a -> b -> a) -> a -> v b -> v a
Expand Down Expand Up @@ -2239,7 +2239,7 @@ iscanl' f z =
-- results in an error; instead it produces an empty vector.
--
-- ==== __Examples__
-- >>> import qualified Data.Vector as V
-- >>> import qualified Data.Vector.Strict as V
-- >>> V.scanl1 min $ V.fromListN 5 [4,2,4,1,3]
-- [4,2,2,1,1]
-- >>> V.scanl1 max $ V.fromListN 5 [1,3,2,5,4]
Expand All @@ -2256,7 +2256,7 @@ scanl1 f = unstream . inplace (S.scanl1 f) id . stream
-- results in an error; instead it produces an empty vector.
--
-- ==== __Examples__
-- >>> import qualified Data.Vector as V
-- >>> import qualified Data.Vector.Strict as V
-- >>> V.scanl1' min $ V.fromListN 5 [4,2,4,1,3]
-- [4,2,2,1,1]
-- >>> V.scanl1' max $ V.fromListN 5 [1,3,2,5,4]
Expand Down Expand Up @@ -2327,7 +2327,7 @@ iscanr' f z v =
-- results in an error; instead it produces an empty vector.
--
-- ==== __Examples__
-- >>> import qualified Data.Vector as V
-- >>> import qualified Data.Vector.Strict as V
-- >>> V.scanr1 min $ V.fromListN 5 [3,1,4,2,4]
-- [1,1,2,2,4]
-- >>> V.scanr1 max $ V.fromListN 5 [4,5,2,3,1]
Expand All @@ -2345,7 +2345,7 @@ scanr1 f = unstreamR . inplace (S.scanl1 (flip f)) id . streamR
-- results in an error; instead it produces an empty vector.
--
-- ==== __Examples__
-- >>> import qualified Data.Vector as V
-- >>> import qualified Data.Vector.Strict as V
-- >>> V.scanr1' min $ V.fromListN 5 [3,1,4,2,4]
-- [1,1,2,2,4]
-- >>> V.scanr1' max $ V.fromListN 5 [4,5,2,3,1]
Expand Down Expand Up @@ -2381,7 +2381,7 @@ fromList = unstream . Bundle.fromList
--
-- ==== __Examples__
--
-- >>> import qualified Data.Vector as V
-- >>> import qualified Data.Vector.Strict as V
-- >>> V.fromListN 3 [1,2,3,4,5]
-- [1,2,3]
-- >>> V.fromListN 3 [1]
Expand Down
4 changes: 2 additions & 2 deletions vector/src/Data/Vector/Generic/Mutable.hs
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,7 @@ clear = stToPrim . basicClear
--
-- ==== __Examples__
--
-- >>> import qualified Data.Vector.Mutable as MV
-- >>> import qualified Data.Vector.Strict.Mutable as MV
-- >>> v <- MV.generate 10 (\x -> x*x)
-- >>> MV.read v 3
-- 9
Expand All @@ -655,7 +655,7 @@ read v i = checkIndex Bounds i (length v)
--
-- ==== __Examples__
--
-- >>> import qualified Data.Vector.Mutable as MV
-- >>> import qualified Data.Vector.Strict.Mutable as MV
-- >>> v <- MV.generate 10 (\x -> x*x)
-- >>> MV.readMaybe v 3
-- Just 9
Expand Down
Loading

0 comments on commit 219b33f

Please sign in to comment.