Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions vector/src/Data/Vector.hs
Original file line number Diff line number Diff line change
Expand Up @@ -305,10 +305,12 @@ instance Ord a => Ord (Vector a) where
xs >= ys = Bundle.cmp (G.stream xs) (G.stream ys) /= LT

instance Eq1 Vector where
liftEq eq xs ys = Bundle.eqBy eq (G.stream xs) (G.stream ys)
{-# INLINE liftEq #-}
liftEq = eqBy

instance Ord1 Vector where
liftCompare cmp xs ys = Bundle.cmpBy cmp (G.stream xs) (G.stream ys)
{-# INLINE liftCompare #-}
liftCompare = cmpBy

instance Semigroup (Vector a) where
{-# INLINE (<>) #-}
Expand Down Expand Up @@ -2166,6 +2168,7 @@ eqBy = G.eqBy
--
-- @since 0.12.2.0
cmpBy :: (a -> b -> Ordering) -> Vector a -> Vector b -> Ordering
{-# INLINE cmpBy #-}
cmpBy = G.cmpBy

-- Conversions - Lists
Expand Down
3 changes: 3 additions & 0 deletions vector/src/Data/Vector/Generic.hs
Original file line number Diff line number Diff line change
Expand Up @@ -757,6 +757,7 @@ concat vs = unstream (Bundle.flatten mk step (Exact n) (Bundle.fromList vs))

-- | /O(n)/ Concatenate all vectors in the non-empty list.
concatNE :: Vector v a => NonEmpty.NonEmpty (v a) -> v a
{-# INLINE concatNE #-}
concatNE = concat . NonEmpty.toList

-- Monadic initialisation
Expand Down Expand Up @@ -1135,6 +1136,7 @@ mapM f = unstreamM . Bundle.mapM f . stream
-- index, yielding a vector of results.
imapM :: (Monad m, Vector v a, Vector v b)
=> (Int -> a -> m b) -> v a -> m (v b)
{-# INLINE imapM #-}
imapM f = unstreamM . Bundle.mapM (uncurry f) . Bundle.indexed . stream

-- | /O(n)/ Apply the monadic action to all elements of a vector and ignore the
Expand Down Expand Up @@ -2681,6 +2683,7 @@ cmp xs ys = compare (stream xs) (stream ys)
--
-- > cmpBy compare == cmp
cmpBy :: (Vector v a, Vector v b) => (a -> b -> Ordering) -> v a -> v b -> Ordering
{-# INLINE cmpBy #-}
cmpBy c xs ys = Bundle.cmpBy c (stream xs) (stream ys)

-- Show
Expand Down
7 changes: 4 additions & 3 deletions vector/src/Data/Vector/Mutable.hs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ module Data.Vector.Mutable (
) where

import Control.Monad (when, liftM)
import Control.Monad.ST (ST)
import qualified Data.Vector.Generic.Mutable as G
import Data.Vector.Internal.Check
import Data.Primitive.Array
Expand Down Expand Up @@ -171,14 +172,14 @@ instance G.MVector MVector a where
basicClear v = G.set v uninitialised

{-# INLINE moveBackwards #-}
moveBackwards :: PrimMonad m => MutableArray (PrimState m) a -> Int -> Int -> Int -> m ()
moveBackwards :: MutableArray s a -> Int -> Int -> Int -> ST s ()
moveBackwards !arr !dstOff !srcOff !len =
check Internal "not a backwards move" (dstOff < srcOff)
$ loopM len $ \ i -> readArray arr (srcOff + i) >>= writeArray arr (dstOff + i)

{-# INLINE moveForwardsSmallOverlap #-}
-- Performs a move when dstOff > srcOff, optimized for when the overlap of the intervals is small.
moveForwardsSmallOverlap :: PrimMonad m => MutableArray (PrimState m) a -> Int -> Int -> Int -> m ()
moveForwardsSmallOverlap :: MutableArray s a -> Int -> Int -> Int -> ST s ()
moveForwardsSmallOverlap !arr !dstOff !srcOff !len =
check Internal "not a forward move" (dstOff > srcOff)
$ do
Expand All @@ -189,7 +190,7 @@ moveForwardsSmallOverlap !arr !dstOff !srcOff !len =
where nonOverlap = dstOff - srcOff; overlap = len - nonOverlap

-- Performs a move when dstOff > srcOff, optimized for when the overlap of the intervals is large.
moveForwardsLargeOverlap :: PrimMonad m => MutableArray (PrimState m) a -> Int -> Int -> Int -> m ()
moveForwardsLargeOverlap :: MutableArray s a -> Int -> Int -> Int -> ST s ()
moveForwardsLargeOverlap !arr !dstOff !srcOff !len =
check Internal "not a forward move" (dstOff > srcOff)
$ do
Expand Down
1 change: 1 addition & 0 deletions vector/src/Data/Vector/Primitive.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1830,6 +1830,7 @@ eqBy = G.eqBy
--
-- @since 0.12.2.0
cmpBy :: (Prim a, Prim b) => (a -> b -> Ordering) -> Vector a -> Vector b -> Ordering
{-# INLINE cmpBy #-}
cmpBy = G.cmpBy

-- Conversions - Lists
Expand Down
8 changes: 5 additions & 3 deletions vector/src/Data/Vector/Strict.hs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,6 @@ module Data.Vector.Strict (
import Data.Coerce
import Data.Vector.Strict.Mutable ( MVector(..) )
import Data.Primitive.Array
import qualified Data.Vector.Fusion.Bundle as Bundle
import qualified Data.Vector.Generic as G
import qualified Data.Vector as V

Expand Down Expand Up @@ -310,10 +309,12 @@ instance Ord a => Ord (Vector a) where
(>=) = coerce ((>=) @(V.Vector a))

instance Eq1 Vector where
liftEq eq xs ys = Bundle.eqBy eq (G.stream xs) (G.stream ys)
{-# INLINE liftEq #-}
liftEq = eqBy

instance Ord1 Vector where
liftCompare cmp xs ys = Bundle.cmpBy cmp (G.stream xs) (G.stream ys)
{-# INLINE liftCompare #-}
liftCompare = cmpBy

instance Functor Vector where
{-# INLINE fmap #-}
Expand Down Expand Up @@ -2435,6 +2436,7 @@ eqBy = G.eqBy
--
-- @since 0.13.2.0
cmpBy :: (a -> b -> Ordering) -> Vector a -> Vector b -> Ordering
{-# INLINE cmpBy #-}
cmpBy = G.cmpBy

-- Conversions - Lists
Expand Down
3 changes: 3 additions & 0 deletions vector/src/Data/Vector/Unboxed.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1289,6 +1289,7 @@ breakR = G.breakR
--
-- @since 0.13.0.1
groupBy :: Unbox a => (a -> a -> Bool) -> Vector a -> [Vector a]
{-# INLINE groupBy #-}
groupBy = G.groupBy

-- | /O(n)/ Split a vector into a list of slices of the input vector.
Expand All @@ -1308,6 +1309,7 @@ groupBy = G.groupBy
--
-- @since 0.13.0.1
group :: (Unbox a, Eq a) => Vector a -> [Vector a]
{-# INLINE group #-}
group = G.groupBy (==)

-- Searching
Expand Down Expand Up @@ -1965,6 +1967,7 @@ eqBy = G.eqBy
--
-- @since 0.12.2.0
cmpBy :: (Unbox a, Unbox b) => (a -> b -> Ordering) -> Vector a -> Vector b -> Ordering
{-# INLINE cmpBy #-}
cmpBy = G.cmpBy

-- Conversions - Lists
Expand Down
Loading