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