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