Repository : ssh://darcs.haskell.org//srv/darcs/packages/vector On branch : master
http://hackage.haskell.org/trac/ghc/changeset/655851f7a764885d56debfb4a1ca8bc2fc539c5c >--------------------------------------------------------------- commit 655851f7a764885d56debfb4a1ca8bc2fc539c5c Author: Khudyakov Alexey <[email protected]> Date: Thu Mar 10 18:19:37 2011 +0000 Add 'indexed' function >--------------------------------------------------------------- Data/Vector.hs | 11 +++++++++++ Data/Vector/Generic.hs | 11 +++++++++++ Data/Vector/Unboxed.hs | 11 +++++++++++ 3 files changed, 33 insertions(+), 0 deletions(-) diff --git a/Data/Vector.hs b/Data/Vector.hs index bccf383..48a0e7f 100644 --- a/Data/Vector.hs +++ b/Data/Vector.hs @@ -81,6 +81,9 @@ module Data.Vector ( -- * Elementwise operations + -- ** Indexing + indexed, + -- ** Mapping map, imap, concatMap, @@ -728,6 +731,14 @@ modify :: (forall s. MVector s a -> ST s ()) -> Vector a -> Vector a {-# INLINE modify #-} modify p = G.modify p +-- Indexing +-- -------- + +-- | /O(n)/ Pair each element in a vector with its index +indexed :: Vector a -> Vector (Int,a) +{-# INLINE indexed #-} +indexed = G.indexed + -- Mapping -- ------- diff --git a/Data/Vector/Generic.hs b/Data/Vector/Generic.hs index 3a7836e..dab9163 100644 --- a/Data/Vector/Generic.hs +++ b/Data/Vector/Generic.hs @@ -71,6 +71,9 @@ module Data.Vector.Generic ( -- * Elementwise operations + -- ** Indexing + indexed, + -- ** Mapping map, imap, concatMap, @@ -874,6 +877,14 @@ modifyWithStream :: Vector v a {-# INLINE modifyWithStream #-} modifyWithStream p v s = new (New.modifyWithStream p (clone v) s) +-- Indexing +-- -------- + +-- | /O(n)/ Pair each element in a vector with its index +indexed :: (Vector v a, Vector v (Int,a)) => v a -> v (Int,a) +{-# INLINE indexed #-} +indexed = unstream . inplace MStream.indexed . stream + -- Mapping -- ------- diff --git a/Data/Vector/Unboxed.hs b/Data/Vector/Unboxed.hs index 7906d71..95afb0d 100644 --- a/Data/Vector/Unboxed.hs +++ b/Data/Vector/Unboxed.hs @@ -94,6 +94,9 @@ module Data.Vector.Unboxed ( -- * Elementwise operations + -- ** Indexing + indexed, + -- ** Mapping map, imap, concatMap, @@ -708,6 +711,14 @@ modify :: Unbox a => (forall s. MVector s a -> ST s ()) -> Vector a -> Vector a {-# INLINE modify #-} modify p = G.modify p +-- Indexing +-- -------- + +-- | /O(n)/ Pair each element in a vector with its index +indexed :: Unbox a => Vector a -> Vector (Int,a) +{-# INLINE indexed #-} +indexed = G.indexed + -- Mapping -- ------- _______________________________________________ Cvs-libraries mailing list [email protected] http://www.haskell.org/mailman/listinfo/cvs-libraries
