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