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