| Safe Haskell | None |
|---|---|
| Language | GHC2021 |
Data.Vector.Mutable.Linear.Borrow
Synopsis
- data Vector a
- empty :: Linearly %1 -> Vector a
- constant :: Int -> a -> Linearly %1 -> Vector a
- fromList :: [a] %1 -> Linearly %1 -> Vector a
- fromVector :: Vector a -> Linearly %1 -> Vector a
- unsafeFromVector :: Vector a %1 -> Linearly %1 -> Vector a
- fromMutable :: MVector s a %1 -> Linearly %1 -> Vector a
- unsafeFromMutable :: MVector s a %1 -> Linearly %1 -> Vector a
- toVector :: Copyable a => Vector a %1 -> Ur (Vector a)
- toList :: Copyable a => Vector a %1 -> Ur [a]
- size :: forall (bk :: BorrowKind) (α :: Lifetime) a. Borrow bk α (Vector a) %1 -> (Ur Int, Borrow bk α (Vector a))
- get :: forall (α :: Lifetime) (β :: Lifetime) (bk :: BorrowKind) a. (HasCallStack, α >= β) => Int -> Borrow bk α (Vector a) %1 -> BO β (Borrow bk α a)
- unsafeGet :: forall (α :: Lifetime) (β :: Lifetime) (bk :: BorrowKind) a. α >= β => Int -> Borrow bk α (Vector a) %1 -> BO β (Borrow bk α a)
- set :: forall (α :: Lifetime) (β :: Lifetime) a. (HasCallStack, α >= β) => Int -> a %1 -> Mut α (Vector a) %1 -> BO β (a, Mut α (Vector a))
- unsafeSet :: forall (α :: Lifetime) (β :: Lifetime) a. α >= β => Int -> a %1 -> Mut α (Vector a) %1 -> BO β (a, Mut α (Vector a))
- update :: forall (α :: Lifetime) (β :: Lifetime) a b. α >= β => Int -> (a %1 -> BO β (b, a)) %1 -> Mut α (Vector a) %1 -> BO β (b, Mut α (Vector a))
- unsafeUpdate :: forall (α :: Lifetime) (β :: Lifetime) a b. α >= β => Int -> (a %1 -> BO β (b, a)) %1 -> Mut α (Vector a) %1 -> BO β (b, Mut α (Vector a))
- modify :: forall (α :: Lifetime) (β :: Lifetime) a. α >= β => Int -> (a %1 -> a) %1 -> Mut α (Vector a) %1 -> BO β (Mut α (Vector a))
- head :: forall (α :: Lifetime) (β :: Lifetime) (bk :: BorrowKind) a. (HasCallStack, α >= β) => Borrow bk α (Vector a) %1 -> BO β (Borrow bk α a)
- unsafeHead :: forall (α :: Lifetime) (β :: Lifetime) (bk :: BorrowKind) a. α >= β => Borrow bk α (Vector a) %1 -> BO β (Borrow bk α a)
- last :: forall (α :: Lifetime) (β :: Lifetime) (bk :: BorrowKind) a. (HasCallStack, α >= β) => Borrow bk α (Vector a) %1 -> BO β (Borrow bk α a)
- unsafeLast :: forall (α :: Lifetime) (β :: Lifetime) (bk :: BorrowKind) a. α >= β => Borrow bk α (Vector a) %1 -> BO β (Borrow bk α a)
- indicesMut :: forall (α :: Lifetime) (β :: Lifetime) a. (HasCallStack, α >= β) => Mut α (Vector a) %1 -> [Int] %1 -> BO β [Mut α a]
- unsafeIndicesMut :: forall (α :: Lifetime) (β :: Lifetime) a. α >= β => Mut α (Vector a) %1 -> [Int] %1 -> BO β [Mut α a]
- splitAt :: forall (bk :: BorrowKind) (α :: Lifetime) a. Int %1 -> Borrow bk α (Vector a) %1 -> (Borrow bk α (Vector a), Borrow bk α (Vector a))
- swap :: forall (α :: Lifetime) (β :: Lifetime) a. (HasCallStack, α >= β) => Mut α (Vector a) %1 -> Int -> Int -> BO β (Mut α (Vector a))
- unsafeSwap :: forall (α :: Lifetime) (β :: Lifetime) a. α >= β => Mut α (Vector a) %1 -> Int -> Int -> BO β (Mut α (Vector a))
- copyAt :: forall a (α :: Lifetime) (β :: Lifetime). (Copyable a, α >= β) => Int -> Share α (Vector a) -> BO β (Ur a)
- copyAtMut :: forall a (α :: Lifetime) (β :: Lifetime). (Copyable a, α >= β) => Int -> Mut α (Vector a) %1 -> BO β (Ur a, Mut α (Vector a))
- inplace :: forall (α :: Lifetime) (β :: Lifetime) a. α >= β => (forall s. MVector s a -> ST s ()) %1 -> Mut α (Vector a) %1 -> BO β (Mut α (Vector a))
- qsort :: forall a (α :: Lifetime) (β :: Lifetime). (Ord a, Copyable a, α >= β) => Word -> Mut α (Vector a) %1 -> BO β ()
- divide :: forall a (α :: Lifetime) (β :: Lifetime). (Ord a, Copyable a, α >= β) => a -> Mut α (Vector a) %1 -> Int -> Int -> BO β (Mut α (Vector a), Mut α (Vector a))
Documentation
Linearly owned mutable vector.
Contrary to those in linear-base, our Vector owns every element linearly.
This is because Pure Borrow can now treat nested mutability safely, so we must allow mutable values to be stored inside Vector.
This manifests in the type of set - it returns the old value, which MUST NOT drop in favour of the new value.
Instances
| LinearOnly (Vector a :: Type) Source # | |
Defined in Data.Vector.Mutable.Linear.Borrow Methods linearOnly :: LinearOnlyWitness (Vector a) Source # | |
| Dupable a => Clone (Vector a) Source # | |
| Unsatisfiable ('ShowType (Vector a) ':<>: 'Text " cannot be copied!") => Copyable (Vector a) Source # | |
Defined in Data.Vector.Mutable.Linear.Borrow | |
size :: forall (bk :: BorrowKind) (α :: Lifetime) a. Borrow bk α (Vector a) %1 -> (Ur Int, Borrow bk α (Vector a)) Source #
get :: forall (α :: Lifetime) (β :: Lifetime) (bk :: BorrowKind) a. (HasCallStack, α >= β) => Int -> Borrow bk α (Vector a) %1 -> BO β (Borrow bk α a) Source #
unsafeGet :: forall (α :: Lifetime) (β :: Lifetime) (bk :: BorrowKind) a. α >= β => Int -> Borrow bk α (Vector a) %1 -> BO β (Borrow bk α a) Source #
get without bounds check.
set :: forall (α :: Lifetime) (β :: Lifetime) a. (HasCallStack, α >= β) => Int -> a %1 -> Mut α (Vector a) %1 -> BO β (a, Mut α (Vector a)) Source #
sets the set i a vi-th element of v to a, and returns the old value alongside.
Note that a is bound linearly.
unsafeSet :: forall (α :: Lifetime) (β :: Lifetime) a. α >= β => Int -> a %1 -> Mut α (Vector a) %1 -> BO β (a, Mut α (Vector a)) Source #
set without bound check.
update :: forall (α :: Lifetime) (β :: Lifetime) a b. α >= β => Int -> (a %1 -> BO β (b, a)) %1 -> Mut α (Vector a) %1 -> BO β (b, Mut α (Vector a)) Source #
unsafeUpdate :: forall (α :: Lifetime) (β :: Lifetime) a b. α >= β => Int -> (a %1 -> BO β (b, a)) %1 -> Mut α (Vector a) %1 -> BO β (b, Mut α (Vector a)) Source #
modify :: forall (α :: Lifetime) (β :: Lifetime) a. α >= β => Int -> (a %1 -> a) %1 -> Mut α (Vector a) %1 -> BO β (Mut α (Vector a)) Source #
head :: forall (α :: Lifetime) (β :: Lifetime) (bk :: BorrowKind) a. (HasCallStack, α >= β) => Borrow bk α (Vector a) %1 -> BO β (Borrow bk α a) Source #
unsafeHead :: forall (α :: Lifetime) (β :: Lifetime) (bk :: BorrowKind) a. α >= β => Borrow bk α (Vector a) %1 -> BO β (Borrow bk α a) Source #
last :: forall (α :: Lifetime) (β :: Lifetime) (bk :: BorrowKind) a. (HasCallStack, α >= β) => Borrow bk α (Vector a) %1 -> BO β (Borrow bk α a) Source #
unsafeLast :: forall (α :: Lifetime) (β :: Lifetime) (bk :: BorrowKind) a. α >= β => Borrow bk α (Vector a) %1 -> BO β (Borrow bk α a) Source #
indicesMut :: forall (α :: Lifetime) (β :: Lifetime) a. (HasCallStack, α >= β) => Mut α (Vector a) %1 -> [Int] %1 -> BO β [Mut α a] Source #
unsafeIndicesMut :: forall (α :: Lifetime) (β :: Lifetime) a. α >= β => Mut α (Vector a) %1 -> [Int] %1 -> BO β [Mut α a] Source #
Get multiple elements at the given indices without bounds and duplication check.
For more safety, use indicesMut.
splitAt :: forall (bk :: BorrowKind) (α :: Lifetime) a. Int %1 -> Borrow bk α (Vector a) %1 -> (Borrow bk α (Vector a), Borrow bk α (Vector a)) Source #
swap :: forall (α :: Lifetime) (β :: Lifetime) a. (HasCallStack, α >= β) => Mut α (Vector a) %1 -> Int -> Int -> BO β (Mut α (Vector a)) Source #
unsafeSwap :: forall (α :: Lifetime) (β :: Lifetime) a. α >= β => Mut α (Vector a) %1 -> Int -> Int -> BO β (Mut α (Vector a)) Source #
copyAt :: forall a (α :: Lifetime) (β :: Lifetime). (Copyable a, α >= β) => Int -> Share α (Vector a) -> BO β (Ur a) Source #
copyAtMut :: forall a (α :: Lifetime) (β :: Lifetime). (Copyable a, α >= β) => Int -> Mut α (Vector a) %1 -> BO β (Ur a, Mut α (Vector a)) Source #
inplace :: forall (α :: Lifetime) (β :: Lifetime) a. α >= β => (forall s. MVector s a -> ST s ()) %1 -> Mut α (Vector a) %1 -> BO β (Mut α (Vector a)) Source #
Applies an in-place mutation on MVector from vector package.
An example algorithm implementations
Arguments
| :: forall a (α :: Lifetime) (β :: Lifetime). (Ord a, Copyable a, α >= β) | |
| => Word | Cost for using parallelism. Halved after each recursive call, and stops parallelizing when it reaches 1. |
| -> Mut α (Vector a) | |
| -> BO β () |
A simple parallel implementation of quicksort.
It uses a sequential divide-and-conquer when size <8,
and parallel divide-and-conquer with parBO otherwise.
This is meant to be a demonstrative implementation and not practical - you need a genuine parallel scheduler to scale this up.