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