Module
Data.FastVect.FastVect
- Package
- purescript-fast-vect
- Repository
- sigma-andex/purescript-fast-vect
#Vect Source
#append Source
append :: forall m n elem carry sum m_plus_n_untrimmed m_plus_n m_aligned n_aligned. PadZeroes m n m_aligned n_aligned => Add m_aligned n_aligned carry sum => Cons carry sum m_plus_n_untrimmed => Trim m_plus_n_untrimmed m_plus_n => Vect m elem -> Vect n elem -> Vect m_plus_n elem
Append two Vect
s.
as :: Vect "300" String
as = replicate (term :: _ "300") "a"
bs :: Vect "200" String
bs = replicate (term :: _ "200") "b"
cs :: Vect "500" String
cs = append as bs
#drop Source
drop :: forall m n elem m_aligned m_plus_n_aligned n_untrimmed m_plus_n. ToInt m => PadZeroes m m_plus_n m_aligned m_plus_n_aligned => Add m_aligned n_untrimmed "0" m_plus_n_aligned => Trim n_untrimmed n => Proxy m -> Vect m_plus_n elem -> Vect n elem
Drop m
elements from a Vect
.
vect :: Vect "300" String
vect = replicate (term :: _ "300") "a"
newVect :: Vect "200" String
newVect = drop (term :: _ "100") vect
#take Source
take :: forall m n elem m_plus_n m_aligned m_aligned_plus_n n_untrimmed. ToInt m => PadZeroes m m_plus_n m_aligned m_aligned_plus_n => Add m_aligned n_untrimmed "0" m_aligned_plus_n => Trim n_untrimmed n => Proxy m -> Vect m_plus_n elem -> Vect m elem
Take m
elements from a Vect
.
vect :: Vect "300" String
vect = replicate (term :: _ "300") "a"
newVect :: Vect "100" String
newVect = take (term :: _ "100") vect
#index Source
index :: forall m m_minus_one aligned_one m_aligned m_aligned_minus_one i i_aligned n elem. ToInt i => PadZeroes "1" m aligned_one m_aligned => Add aligned_one m_minus_one "0" m_aligned => PadZeroes i m_minus_one i_aligned m_aligned_minus_one => Add i_aligned n "0" m_aligned_minus_one => Proxy i -> Vect m elem -> elem
Safely access the i
-th element of a Vect
.
vect :: Vect "300" String
vect = replicate (term :: _ "300") "a"
elem :: String
elem = index (term :: _ "299") vect
#head Source
head :: forall m m_minus_one aligned_one m_aligned m_aligned_minus_one i_aligned n elem. PadZeroes "1" m aligned_one m_aligned => Add aligned_one m_minus_one "0" m_aligned => PadZeroes "0" m_minus_one i_aligned m_aligned_minus_one => Add i_aligned n "0" m_aligned_minus_one => Vect m elem -> elem
Safely access the head of a Vect
.
vect :: Vect "300" String
vect = replicate (term :: _ "300") "a"
elem :: String
elem = head vect
#splitAt Source
splitAt :: forall m n elem m_aligned m_plus_n_aligned n_untrimmed m_plus_n. ToInt m => PadZeroes m m_plus_n m_aligned m_plus_n_aligned => Add m_aligned n_untrimmed "0" m_plus_n_aligned => Trim n_untrimmed n => Proxy m -> Vect m_plus_n elem -> { after :: Vect n elem, before :: Vect m elem }
Split the Vect
into two sub vectors before
and after
, where before contains up to m
elements.
vect ∷ Vect "10" String
vect = replicate (term ∷ _ "10") "a"
split ∷
{ after ∷ Vect "7" String
, before ∷ Vect "3" String
}
split = splitAt (term ∷ _ "3") vect
#adjust Source
adjust :: forall len elem. ToInt len => Proxy len -> elem -> Array elem -> Vect len elem
Creates a Vect
by adjusting the given Array
, padding with the provided element if the array is to small or dropping elements if the array is to big.
toArray $ adjust (term ∷ _ "10") 0 [ 1, 2, 3 ] == [ 0, 0, 0, 0, 0, 0, 0, 1, 2, 3 ]
toArray $ adjust (term ∷ _ "3") 0 [ 0, 0, 0, 0, 1, 2, 3 ] == [ 1, 2, 3 ]
#cons Source
cons :: forall len elem one_aligned len_aligned carry sum len_plus_1_untrimmed len_plus_1. PadZeroes "1" len one_aligned len_aligned => Add one_aligned len carry sum => Cons carry sum len_plus_1_untrimmed => Trim len_plus_1_untrimmed len_plus_1 => elem -> Vect len elem -> Vect len_plus_1 elem
Attaches an element to the front of the Vect
, creating a new Vect
with size incremented.
Note, the running time of this function is O(n)
.
- Modules
- Data.
FastVect. FastVect