Add unsafeBackpermute
[darcs-mirrors/vector.git] / Data / Vector / Storable.hs
1 {-# LANGUAGE MultiParamTypeClasses, FlexibleInstances, TypeFamilies #-}
2
3 -- |
4 -- Module : Data.Vector.Storable
5 -- Copyright : (c) Roman Leshchinskiy 2009
6 -- License : BSD-style
7 --
8 -- Maintainer : Roman Leshchinskiy <rl@cse.unsw.edu.au>
9 -- Stability : experimental
10 -- Portability : non-portable
11 --
12 -- 'Storable'-based vectors.
13 --
14
15 module Data.Vector.Storable (
16 Vector, MVector(..), Storable,
17
18 -- * Length information
19 length, null,
20
21 -- * Construction
22 empty, singleton, cons, snoc, replicate, generate, (++), copy,
23
24 -- * Accessing individual elements
25 (!), head, last, indexM, headM, lastM,
26 unsafeIndex, unsafeHead, unsafeLast,
27 unsafeIndexM, unsafeHeadM, unsafeLastM,
28
29 -- * Subvectors
30 slice, init, tail, take, drop,
31 unsafeSlice, unsafeInit, unsafeTail, unsafeTake, unsafeDrop,
32
33 -- * Permutations
34 accum, accumulate_, (//), update_, backpermute, reverse,
35 unsafeAccum, unsafeAccumulate_,
36 unsafeUpd, unsafeUpdate_,
37 unsafeBackpermute,
38
39 -- * Mapping
40 map, imap, concatMap,
41
42 -- * Zipping and unzipping
43 zipWith, zipWith3, zipWith4, zipWith5, zipWith6,
44 izipWith, izipWith3, izipWith4, izipWith5, izipWith6,
45
46 -- * Filtering
47 filter, ifilter, takeWhile, dropWhile,
48 unstablePartition, span, break,
49
50 -- * Searching
51 elem, notElem, find, findIndex, findIndices, elemIndex, elemIndices,
52
53 -- * Folding
54 foldl, foldl1, foldl', foldl1', foldr, foldr1,
55 ifoldl, ifoldl', ifoldr,
56
57 -- * Specialised folds
58 all, any, and, or,
59 sum, product,
60 maximum, maximumBy, minimum, minimumBy,
61 minIndex, minIndexBy, maxIndex, maxIndexBy,
62
63 -- * Unfolding
64 unfoldr,
65
66 -- * Scans
67 prescanl, prescanl',
68 postscanl, postscanl',
69 scanl, scanl', scanl1, scanl1',
70
71 -- * Enumeration
72 enumFromTo, enumFromThenTo,
73
74 -- * Conversion to/from lists
75 toList, fromList
76 ) where
77
78 import qualified Data.Vector.Generic as G
79 import Data.Vector.Storable.Mutable ( MVector(..) )
80 import Data.Vector.Storable.Internal
81
82 import Foreign.Storable
83 import Foreign.ForeignPtr
84 -- import Foreign.Ptr
85 -- import Foreign.C.Types
86
87 import Control.Monad.ST ( ST, runST )
88
89 import Prelude hiding ( length, null,
90 replicate, (++),
91 head, last,
92 init, tail, take, drop, reverse,
93 map, concatMap,
94 zipWith, zipWith3, zip, zip3, unzip, unzip3,
95 filter, takeWhile, dropWhile, span, break,
96 elem, notElem,
97 foldl, foldl1, foldr, foldr1,
98 all, any, and, or, sum, product, minimum, maximum,
99 scanl, scanl1,
100 enumFromTo, enumFromThenTo )
101
102 import qualified Prelude
103
104 #include "vector.h"
105
106 -- | 'Storable'-based vectors
107 data Vector a = Vector {-# UNPACK #-} !Int
108 {-# UNPACK #-} !Int
109 {-# UNPACK #-} !(ForeignPtr a)
110
111 instance (Show a, Storable a) => Show (Vector a) where
112 show = (Prelude.++ " :: Data.Vector.Storable.Vector")
113 . ("fromList " Prelude.++)
114 . show
115 . toList
116
117 type instance G.Mutable Vector = MVector
118
119 instance Storable a => G.Vector Vector a where
120 {-# INLINE unsafeFreeze #-}
121 unsafeFreeze (MVector i n p) = return $ Vector i n p
122
123 {-# INLINE basicLength #-}
124 basicLength (Vector _ n _) = n
125
126 {-# INLINE basicUnsafeSlice #-}
127 basicUnsafeSlice j n (Vector i _ p) = Vector (i+j) n p
128
129 {-# INLINE basicUnsafeIndexM #-}
130 basicUnsafeIndexM (Vector i _ p) j = return
131 . inlinePerformIO
132 $ withForeignPtr p (`peekElemOff` (i+j))
133
134 {-# INLINE elemseq #-}
135 elemseq _ = seq
136
137 instance (Storable a, Eq a) => Eq (Vector a) where
138 {-# INLINE (==) #-}
139 (==) = G.eq
140
141 {-
142 eq_memcmp :: forall a. Storable a => Vector a -> Vector a -> Bool
143 {-# INLINE_STREAM eq_memcmp #-}
144 eq_memcmp (Vector i m p) (Vector j n q)
145 = m == n && inlinePerformIO
146 (withForeignPtr p $ \p' ->
147 withForeignPtr q $ \q' ->
148 return $
149 memcmp (p' `plusPtr` i) (q' `plusPtr` j)
150 (fromIntegral $ sizeOf (undefined :: a) * m) == 0)
151
152 foreign import ccall unsafe "string.h memcmp" memcmp
153 :: Ptr a -> Ptr a -> CSize -> CInt
154
155 {-# RULES
156
157 "(==) [Vector.Storable Int]"
158 G.eq = eq_memcmp :: Vector Int -> Vector Int -> Bool
159 #-}
160 -}
161
162 instance (Storable a, Ord a) => Ord (Vector a) where
163 {-# INLINE compare #-}
164 compare = G.cmp
165
166 -- Length
167 -- ------
168
169 length :: Storable a => Vector a -> Int
170 {-# INLINE length #-}
171 length = G.length
172
173 null :: Storable a => Vector a -> Bool
174 {-# INLINE null #-}
175 null = G.null
176
177 -- Construction
178 -- ------------
179
180 -- | Empty vector
181 empty :: Storable a => Vector a
182 {-# INLINE empty #-}
183 empty = G.empty
184
185 -- | Vector with exaclty one element
186 singleton :: Storable a => a -> Vector a
187 {-# INLINE singleton #-}
188 singleton = G.singleton
189
190 -- | Vector of the given length with the given value in each position
191 replicate :: Storable a => Int -> a -> Vector a
192 {-# INLINE replicate #-}
193 replicate = G.replicate
194
195 -- | Generate a vector of the given length by applying the function to each
196 -- index
197 generate :: Storable a => Int -> (Int -> a) -> Vector a
198 {-# INLINE generate #-}
199 generate = G.generate
200
201 -- | Prepend an element
202 cons :: Storable a => a -> Vector a -> Vector a
203 {-# INLINE cons #-}
204 cons = G.cons
205
206 -- | Append an element
207 snoc :: Storable a => Vector a -> a -> Vector a
208 {-# INLINE snoc #-}
209 snoc = G.snoc
210
211 infixr 5 ++
212 -- | Concatenate two vectors
213 (++) :: Storable a => Vector a -> Vector a -> Vector a
214 {-# INLINE (++) #-}
215 (++) = (G.++)
216
217 -- | Create a copy of a vector. Useful when dealing with slices.
218 copy :: Storable a => Vector a -> Vector a
219 {-# INLINE copy #-}
220 copy = G.copy
221
222 -- Accessing individual elements
223 -- -----------------------------
224
225 -- | Indexing
226 (!) :: Storable a => Vector a -> Int -> a
227 {-# INLINE (!) #-}
228 (!) = (G.!)
229
230 -- | First element
231 head :: Storable a => Vector a -> a
232 {-# INLINE head #-}
233 head = G.head
234
235 -- | Last element
236 last :: Storable a => Vector a -> a
237 {-# INLINE last #-}
238 last = G.last
239
240 -- | Unsafe indexing without bounds checking
241 unsafeIndex :: Storable a => Vector a -> Int -> a
242 {-# INLINE unsafeIndex #-}
243 unsafeIndex = G.unsafeIndex
244
245 -- | Yield the first element of a vector without checking if the vector is
246 -- empty
247 unsafeHead :: Storable a => Vector a -> a
248 {-# INLINE unsafeHead #-}
249 unsafeHead = G.unsafeHead
250
251 -- | Yield the last element of a vector without checking if the vector is
252 -- empty
253 unsafeLast :: Storable a => Vector a -> a
254 {-# INLINE unsafeLast #-}
255 unsafeLast = G.unsafeLast
256
257 -- | Monadic indexing which can be strict in the vector while remaining lazy in
258 -- the element
259 indexM :: (Storable a, Monad m) => Vector a -> Int -> m a
260 {-# INLINE indexM #-}
261 indexM = G.indexM
262
263 headM :: (Storable a, Monad m) => Vector a -> m a
264 {-# INLINE headM #-}
265 headM = G.headM
266
267 lastM :: (Storable a, Monad m) => Vector a -> m a
268 {-# INLINE lastM #-}
269 lastM = G.lastM
270
271 -- | Unsafe monadic indexing without bounds checks
272 unsafeIndexM :: (Storable a, Monad m) => Vector a -> Int -> m a
273 {-# INLINE unsafeIndexM #-}
274 unsafeIndexM = G.unsafeIndexM
275
276 unsafeHeadM :: (Storable a, Monad m) => Vector a -> m a
277 {-# INLINE unsafeHeadM #-}
278 unsafeHeadM = G.unsafeHeadM
279
280 unsafeLastM :: (Storable a, Monad m) => Vector a -> m a
281 {-# INLINE unsafeLastM #-}
282 unsafeLastM = G.unsafeLastM
283
284 -- Subarrays
285 -- ---------
286
287 -- | Yield a part of the vector without copying it. Safer version of
288 -- 'basicUnsafeSlice'.
289 slice :: Storable a => Int -- ^ starting index
290 -> Int -- ^ length
291 -> Vector a
292 -> Vector a
293 {-# INLINE slice #-}
294 slice = G.slice
295
296 -- | Yield all but the last element without copying.
297 init :: Storable a => Vector a -> Vector a
298 {-# INLINE init #-}
299 init = G.init
300
301 -- | All but the first element (without copying).
302 tail :: Storable a => Vector a -> Vector a
303 {-# INLINE tail #-}
304 tail = G.tail
305
306 -- | Yield the first @n@ elements without copying.
307 take :: Storable a => Int -> Vector a -> Vector a
308 {-# INLINE take #-}
309 take = G.take
310
311 -- | Yield all but the first @n@ elements without copying.
312 drop :: Storable a => Int -> Vector a -> Vector a
313 {-# INLINE drop #-}
314 drop = G.drop
315
316 -- | Unsafely yield a part of the vector without copying it and without
317 -- performing bounds checks.
318 unsafeSlice :: Storable a => Int -- ^ starting index
319 -> Int -- ^ length
320 -> Vector a
321 -> Vector a
322 {-# INLINE unsafeSlice #-}
323 unsafeSlice = G.unsafeSlice
324
325 unsafeInit :: Storable a => Vector a -> Vector a
326 {-# INLINE unsafeInit #-}
327 unsafeInit = G.unsafeInit
328
329 unsafeTail :: Storable a => Vector a -> Vector a
330 {-# INLINE unsafeTail #-}
331 unsafeTail = G.unsafeTail
332
333 unsafeTake :: Storable a => Int -> Vector a -> Vector a
334 {-# INLINE unsafeTake #-}
335 unsafeTake = G.unsafeTake
336
337 unsafeDrop :: Storable a => Int -> Vector a -> Vector a
338 {-# INLINE unsafeDrop #-}
339 unsafeDrop = G.unsafeDrop
340
341 -- Permutations
342 -- ------------
343
344 unsafeAccum :: Storable a => (a -> b -> a) -> Vector a -> [(Int,b)] -> Vector a
345 {-# INLINE unsafeAccum #-}
346 unsafeAccum = G.unsafeAccum
347
348 unsafeAccumulate_ :: (Storable a, Storable b) =>
349 (a -> b -> a) -> Vector a -> Vector Int -> Vector b -> Vector a
350 {-# INLINE unsafeAccumulate_ #-}
351 unsafeAccumulate_ = G.unsafeAccumulate_
352
353 accum :: Storable a => (a -> b -> a) -> Vector a -> [(Int,b)] -> Vector a
354 {-# INLINE accum #-}
355 accum = G.accum
356
357 accumulate_ :: (Storable a, Storable b) =>
358 (a -> b -> a) -> Vector a -> Vector Int -> Vector b -> Vector a
359 {-# INLINE accumulate_ #-}
360 accumulate_ = G.accumulate_
361
362 unsafeUpd :: Storable a => Vector a -> [(Int, a)] -> Vector a
363 {-# INLINE unsafeUpd #-}
364 unsafeUpd = G.unsafeUpd
365
366 unsafeUpdate_ :: Storable a => Vector a -> Vector Int -> Vector a -> Vector a
367 {-# INLINE unsafeUpdate_ #-}
368 unsafeUpdate_ = G.unsafeUpdate_
369
370 (//) :: Storable a => Vector a -> [(Int, a)] -> Vector a
371 {-# INLINE (//) #-}
372 (//) = (G.//)
373
374 update_ :: Storable a => Vector a -> Vector Int -> Vector a -> Vector a
375 {-# INLINE update_ #-}
376 update_ = G.update_
377
378 backpermute :: Storable a => Vector a -> Vector Int -> Vector a
379 {-# INLINE backpermute #-}
380 backpermute = G.backpermute
381
382 unsafeBackpermute :: Storable a => Vector a -> Vector Int -> Vector a
383 {-# INLINE unsafeBackpermute #-}
384 unsafeBackpermute = G.unsafeBackpermute
385
386 reverse :: Storable a => Vector a -> Vector a
387 {-# INLINE reverse #-}
388 reverse = G.reverse
389
390 -- Mapping
391 -- -------
392
393 -- | Map a function over a vector
394 map :: (Storable a, Storable b) => (a -> b) -> Vector a -> Vector b
395 {-# INLINE map #-}
396 map = G.map
397
398 -- | Apply a function to every index/value pair
399 imap :: (Storable a, Storable b) => (Int -> a -> b) -> Vector a -> Vector b
400 {-# INLINE imap #-}
401 imap = G.imap
402
403 concatMap :: (Storable a, Storable b) => (a -> Vector b) -> Vector a -> Vector b
404 {-# INLINE concatMap #-}
405 concatMap = G.concatMap
406
407 -- Zipping/unzipping
408 -- -----------------
409
410 -- | Zip two vectors with the given function.
411 zipWith :: (Storable a, Storable b, Storable c)
412 => (a -> b -> c) -> Vector a -> Vector b -> Vector c
413 {-# INLINE zipWith #-}
414 zipWith = G.zipWith
415
416 -- | Zip three vectors with the given function.
417 zipWith3 :: (Storable a, Storable b, Storable c, Storable d)
418 => (a -> b -> c -> d) -> Vector a -> Vector b -> Vector c -> Vector d
419 {-# INLINE zipWith3 #-}
420 zipWith3 = G.zipWith3
421
422 zipWith4 :: (Storable a, Storable b, Storable c, Storable d, Storable e)
423 => (a -> b -> c -> d -> e)
424 -> Vector a -> Vector b -> Vector c -> Vector d -> Vector e
425 {-# INLINE zipWith4 #-}
426 zipWith4 = G.zipWith4
427
428 zipWith5 :: (Storable a, Storable b, Storable c, Storable d, Storable e,
429 Storable f)
430 => (a -> b -> c -> d -> e -> f)
431 -> Vector a -> Vector b -> Vector c -> Vector d -> Vector e
432 -> Vector f
433 {-# INLINE zipWith5 #-}
434 zipWith5 = G.zipWith5
435
436 zipWith6 :: (Storable a, Storable b, Storable c, Storable d, Storable e,
437 Storable f, Storable g)
438 => (a -> b -> c -> d -> e -> f -> g)
439 -> Vector a -> Vector b -> Vector c -> Vector d -> Vector e
440 -> Vector f -> Vector g
441 {-# INLINE zipWith6 #-}
442 zipWith6 = G.zipWith6
443
444 -- | Zip two vectors and their indices with the given function.
445 izipWith :: (Storable a, Storable b, Storable c)
446 => (Int -> a -> b -> c) -> Vector a -> Vector b -> Vector c
447 {-# INLINE izipWith #-}
448 izipWith = G.izipWith
449
450 -- | Zip three vectors and their indices with the given function.
451 izipWith3 :: (Storable a, Storable b, Storable c, Storable d)
452 => (Int -> a -> b -> c -> d)
453 -> Vector a -> Vector b -> Vector c -> Vector d
454 {-# INLINE izipWith3 #-}
455 izipWith3 = G.izipWith3
456
457 izipWith4 :: (Storable a, Storable b, Storable c, Storable d, Storable e)
458 => (Int -> a -> b -> c -> d -> e)
459 -> Vector a -> Vector b -> Vector c -> Vector d -> Vector e
460 {-# INLINE izipWith4 #-}
461 izipWith4 = G.izipWith4
462
463 izipWith5 :: (Storable a, Storable b, Storable c, Storable d, Storable e,
464 Storable f)
465 => (Int -> a -> b -> c -> d -> e -> f)
466 -> Vector a -> Vector b -> Vector c -> Vector d -> Vector e
467 -> Vector f
468 {-# INLINE izipWith5 #-}
469 izipWith5 = G.izipWith5
470
471 izipWith6 :: (Storable a, Storable b, Storable c, Storable d, Storable e,
472 Storable f, Storable g)
473 => (Int -> a -> b -> c -> d -> e -> f -> g)
474 -> Vector a -> Vector b -> Vector c -> Vector d -> Vector e
475 -> Vector f -> Vector g
476 {-# INLINE izipWith6 #-}
477 izipWith6 = G.izipWith6
478
479 -- Filtering
480 -- ---------
481
482 -- | Drop elements which do not satisfy the predicate
483 filter :: Storable a => (a -> Bool) -> Vector a -> Vector a
484 {-# INLINE filter #-}
485 filter = G.filter
486
487 -- | Drop elements that do not satisfy the predicate (applied to values and
488 -- their indices)
489 ifilter :: Storable a => (Int -> a -> Bool) -> Vector a -> Vector a
490 {-# INLINE ifilter #-}
491 ifilter = G.ifilter
492
493 -- | Yield the longest prefix of elements satisfying the predicate.
494 takeWhile :: Storable a => (a -> Bool) -> Vector a -> Vector a
495 {-# INLINE takeWhile #-}
496 takeWhile = G.takeWhile
497
498 -- | Drop the longest prefix of elements that satisfy the predicate.
499 dropWhile :: Storable a => (a -> Bool) -> Vector a -> Vector a
500 {-# INLINE dropWhile #-}
501 dropWhile = G.dropWhile
502
503 -- | Split the vector in two parts, the first one containing those elements
504 -- that satisfy the predicate and the second one those that don't. The order
505 -- of the elements is not preserved.
506 unstablePartition
507 :: Storable a => (a -> Bool) -> Vector a -> (Vector a, Vector a)
508 {-# INLINE unstablePartition #-}
509 unstablePartition = G.unstablePartition
510
511 -- | Split the vector into the longest prefix of elements that satisfy the
512 -- predicate and the rest.
513 span :: Storable a => (a -> Bool) -> Vector a -> (Vector a, Vector a)
514 {-# INLINE span #-}
515 span = G.span
516
517 -- | Split the vector into the longest prefix of elements that do not satisfy
518 -- the predicate and the rest.
519 break :: Storable a => (a -> Bool) -> Vector a -> (Vector a, Vector a)
520 {-# INLINE break #-}
521 break = G.break
522
523 -- Searching
524 -- ---------
525
526 infix 4 `elem`
527 -- | Check whether the vector contains an element
528 elem :: (Storable a, Eq a) => a -> Vector a -> Bool
529 {-# INLINE elem #-}
530 elem = G.elem
531
532 infix 4 `notElem`
533 -- | Inverse of `elem`
534 notElem :: (Storable a, Eq a) => a -> Vector a -> Bool
535 {-# INLINE notElem #-}
536 notElem = G.notElem
537
538 -- | Yield 'Just' the first element matching the predicate or 'Nothing' if no
539 -- such element exists.
540 find :: Storable a => (a -> Bool) -> Vector a -> Maybe a
541 {-# INLINE find #-}
542 find = G.find
543
544 -- | Yield 'Just' the index of the first element matching the predicate or
545 -- 'Nothing' if no such element exists.
546 findIndex :: Storable a => (a -> Bool) -> Vector a -> Maybe Int
547 {-# INLINE findIndex #-}
548 findIndex = G.findIndex
549
550 -- | Yield the indices of elements satisfying the predicate
551 findIndices :: Storable a => (a -> Bool) -> Vector a -> Vector Int
552 {-# INLINE findIndices #-}
553 findIndices = G.findIndices
554
555 -- | Yield 'Just' the index of the first occurence of the given element or
556 -- 'Nothing' if the vector does not contain the element
557 elemIndex :: (Storable a, Eq a) => a -> Vector a -> Maybe Int
558 {-# INLINE elemIndex #-}
559 elemIndex = G.elemIndex
560
561 -- | Yield the indices of all occurences of the given element
562 elemIndices :: (Storable a, Eq a) => a -> Vector a -> Vector Int
563 {-# INLINE elemIndices #-}
564 elemIndices = G.elemIndices
565
566 -- Folding
567 -- -------
568
569 -- | Left fold
570 foldl :: Storable b => (a -> b -> a) -> a -> Vector b -> a
571 {-# INLINE foldl #-}
572 foldl = G.foldl
573
574 -- | Lefgt fold on non-empty vectors
575 foldl1 :: Storable a => (a -> a -> a) -> Vector a -> a
576 {-# INLINE foldl1 #-}
577 foldl1 = G.foldl1
578
579 -- | Left fold with strict accumulator
580 foldl' :: Storable b => (a -> b -> a) -> a -> Vector b -> a
581 {-# INLINE foldl' #-}
582 foldl' = G.foldl'
583
584 -- | Left fold on non-empty vectors with strict accumulator
585 foldl1' :: Storable a => (a -> a -> a) -> Vector a -> a
586 {-# INLINE foldl1' #-}
587 foldl1' = G.foldl1'
588
589 -- | Right fold
590 foldr :: Storable a => (a -> b -> b) -> b -> Vector a -> b
591 {-# INLINE foldr #-}
592 foldr = G.foldr
593
594 -- | Right fold on non-empty vectors
595 foldr1 :: Storable a => (a -> a -> a) -> Vector a -> a
596 {-# INLINE foldr1 #-}
597 foldr1 = G.foldr1
598
599 -- | Left fold (function applied to each element and its index)
600 ifoldl :: Storable b => (a -> Int -> b -> a) -> a -> Vector b -> a
601 {-# INLINE ifoldl #-}
602 ifoldl = G.ifoldl
603
604 -- | Left fold with strict accumulator (function applied to each element and
605 -- its index)
606 ifoldl' :: Storable b => (a -> Int -> b -> a) -> a -> Vector b -> a
607 {-# INLINE ifoldl' #-}
608 ifoldl' = G.ifoldl'
609
610 -- | Right fold (function applied to each element and its index)
611 ifoldr :: Storable a => (Int -> a -> b -> b) -> b -> Vector a -> b
612 {-# INLINE ifoldr #-}
613 ifoldr = G.ifoldr
614
615 -- Specialised folds
616 -- -----------------
617
618 all :: Storable a => (a -> Bool) -> Vector a -> Bool
619 {-# INLINE all #-}
620 all = G.all
621
622 any :: Storable a => (a -> Bool) -> Vector a -> Bool
623 {-# INLINE any #-}
624 any = G.any
625
626 and :: Vector Bool -> Bool
627 {-# INLINE and #-}
628 and = G.and
629
630 or :: Vector Bool -> Bool
631 {-# INLINE or #-}
632 or = G.or
633
634 sum :: (Storable a, Num a) => Vector a -> a
635 {-# INLINE sum #-}
636 sum = G.sum
637
638 product :: (Storable a, Num a) => Vector a -> a
639 {-# INLINE product #-}
640 product = G.product
641
642 maximum :: (Storable a, Ord a) => Vector a -> a
643 {-# INLINE maximum #-}
644 maximum = G.maximum
645
646 maximumBy :: Storable a => (a -> a -> Ordering) -> Vector a -> a
647 {-# INLINE maximumBy #-}
648 maximumBy = G.maximumBy
649
650 minimum :: (Storable a, Ord a) => Vector a -> a
651 {-# INLINE minimum #-}
652 minimum = G.minimum
653
654 minimumBy :: Storable a => (a -> a -> Ordering) -> Vector a -> a
655 {-# INLINE minimumBy #-}
656 minimumBy = G.minimumBy
657
658 maxIndex :: (Storable a, Ord a) => Vector a -> Int
659 {-# INLINE maxIndex #-}
660 maxIndex = G.maxIndex
661
662 maxIndexBy :: Storable a => (a -> a -> Ordering) -> Vector a -> Int
663 {-# INLINE maxIndexBy #-}
664 maxIndexBy = G.maxIndexBy
665
666 minIndex :: (Storable a, Ord a) => Vector a -> Int
667 {-# INLINE minIndex #-}
668 minIndex = G.minIndex
669
670 minIndexBy :: Storable a => (a -> a -> Ordering) -> Vector a -> Int
671 {-# INLINE minIndexBy #-}
672 minIndexBy = G.minIndexBy
673
674 -- Unfolding
675 -- ---------
676
677 unfoldr :: Storable a => (b -> Maybe (a, b)) -> b -> Vector a
678 {-# INLINE unfoldr #-}
679 unfoldr = G.unfoldr
680
681 -- Scans
682 -- -----
683
684 -- | Prefix scan
685 prescanl :: (Storable a, Storable b) => (a -> b -> a) -> a -> Vector b -> Vector a
686 {-# INLINE prescanl #-}
687 prescanl = G.prescanl
688
689 -- | Prefix scan with strict accumulator
690 prescanl' :: (Storable a, Storable b) => (a -> b -> a) -> a -> Vector b -> Vector a
691 {-# INLINE prescanl' #-}
692 prescanl' = G.prescanl'
693
694 -- | Suffix scan
695 postscanl :: (Storable a, Storable b) => (a -> b -> a) -> a -> Vector b -> Vector a
696 {-# INLINE postscanl #-}
697 postscanl = G.postscanl
698
699 -- | Suffix scan with strict accumulator
700 postscanl' :: (Storable a, Storable b) => (a -> b -> a) -> a -> Vector b -> Vector a
701 {-# INLINE postscanl' #-}
702 postscanl' = G.postscanl'
703
704 -- | Haskell-style scan
705 scanl :: (Storable a, Storable b) => (a -> b -> a) -> a -> Vector b -> Vector a
706 {-# INLINE scanl #-}
707 scanl = G.scanl
708
709 -- | Haskell-style scan with strict accumulator
710 scanl' :: (Storable a, Storable b) => (a -> b -> a) -> a -> Vector b -> Vector a
711 {-# INLINE scanl' #-}
712 scanl' = G.scanl'
713
714 -- | Scan over a non-empty 'Vector'
715 scanl1 :: Storable a => (a -> a -> a) -> Vector a -> Vector a
716 {-# INLINE scanl1 #-}
717 scanl1 = G.scanl1
718
719 -- | Scan over a non-empty 'Vector' with a strict accumulator
720 scanl1' :: Storable a => (a -> a -> a) -> Vector a -> Vector a
721 {-# INLINE scanl1' #-}
722 scanl1' = G.scanl1'
723
724 -- Enumeration
725 -- -----------
726
727 enumFromTo :: (Storable a, Enum a) => a -> a -> Vector a
728 {-# INLINE enumFromTo #-}
729 enumFromTo = G.enumFromTo
730
731 enumFromThenTo :: (Storable a, Enum a) => a -> a -> a -> Vector a
732 {-# INLINE enumFromThenTo #-}
733 enumFromThenTo = G.enumFromThenTo
734
735 -- Conversion to/from lists
736 -- ------------------------
737
738 -- | Convert a vector to a list
739 toList :: Storable a => Vector a -> [a]
740 {-# INLINE toList #-}
741 toList = G.toList
742
743 -- | Convert a list to a vector
744 fromList :: Storable a => [a] -> Vector a
745 {-# INLINE fromList #-}
746 fromList = G.fromList
747