vector-rotcev-0.1.0.2: Vectors with O(1) reverse
Copyright(c) 2019 Andrew Lelechenko
LicenseBSD3
MaintainerAndrew Lelechenko <andrew.lelechenko@gmail.com>
Safe HaskellSafe-Inferred
LanguageHaskell2010

Data.Vector.Rotcev

Description

A wrapper for an arbitrary Vector with O(1) reverse. Instead of creating a copy, it just flips a flag, which inverts indexing. Imagine it as a vector with a switch between little-endianness and big-endianness.

Synopsis

Documentation

data Rotcev v a Source #

Wrapper for immutable vectors, equipped with a Vector instance.

>>> Forward  (Data.Vector.fromList [0..100]) Data.Vector.Generic.! 10
10
>>> Backward (Data.Vector.fromList [0..100]) Data.Vector.Generic.! 10
90

Constructors

Forward !(v a)

Behaves as an original vector in respect to Vector operations.

Backward !(v a)

Behaves as a reversed vector in respect to Vector operations.

Instances

Instances details
Vector v a => Vector (Rotcev v) a Source # 
Instance details

Defined in Data.Vector.Rotcev

Methods

basicUnsafeFreeze :: Mutable (Rotcev v) s a -> ST s (Rotcev v a) #

basicUnsafeThaw :: Rotcev v a -> ST s (Mutable (Rotcev v) s a) #

basicLength :: Rotcev v a -> Int #

basicUnsafeSlice :: Int -> Int -> Rotcev v a -> Rotcev v a #

basicUnsafeIndexM :: Rotcev v a -> Int -> Box a #

basicUnsafeCopy :: Mutable (Rotcev v) s a -> Rotcev v a -> ST s () #

elemseq :: Rotcev v a -> a -> b -> b #

Show (v a) => Show (Rotcev v a) Source # 
Instance details

Defined in Data.Vector.Rotcev

Methods

showsPrec :: Int -> Rotcev v a -> ShowS #

show :: Rotcev v a -> String #

showList :: [Rotcev v a] -> ShowS #

Eq (v a) => Eq (Rotcev v a) Source # 
Instance details

Defined in Data.Vector.Rotcev

Methods

(==) :: Rotcev v a -> Rotcev v a -> Bool #

(/=) :: Rotcev v a -> Rotcev v a -> Bool #

Ord (v a) => Ord (Rotcev v a) Source # 
Instance details

Defined in Data.Vector.Rotcev

Methods

compare :: Rotcev v a -> Rotcev v a -> Ordering #

(<) :: Rotcev v a -> Rotcev v a -> Bool #

(<=) :: Rotcev v a -> Rotcev v a -> Bool #

(>) :: Rotcev v a -> Rotcev v a -> Bool #

(>=) :: Rotcev v a -> Rotcev v a -> Bool #

max :: Rotcev v a -> Rotcev v a -> Rotcev v a #

min :: Rotcev v a -> Rotcev v a -> Rotcev v a #

type Mutable (Rotcev v) Source # 
Instance details

Defined in Data.Vector.Rotcev

type Mutable (Rotcev v) = MRotcev v

reverse :: Rotcev v a -> Rotcev v a Source #

Reverse an immutable vector in O(1) time and space.

>>> vec = Data.Vector.Generic.fromList [0..100] :: Rotcev Data.Vector.Vector Int
>>> reverse vec Data.Vector.Generic.! 10
90

unRotcev :: Vector v a => Rotcev v a -> v a Source #

Unwrap Rotcev, extracting an underlying vector. This takes O(1) for Forward, but full O(n) time for Backward case, so it would rather be avoided in intermediate computations. Instead leverage opportunities, provided by generic Vector and MVector instances.

data MRotcev v s a Source #

Wrapper for mutable vectors, equipped with a MVector instance.

Constructors

MForward !(Mutable v s a)

Behaves as an original vector in respect to MVector operations.

MBackward !(Mutable v s a)

Behaves as a reversed vector in respect to MVector operations.

Instances

Instances details
MVector (Mutable v) a => MVector (MRotcev v) a Source # 
Instance details

Defined in Data.Vector.Rotcev

Methods

basicLength :: MRotcev v s a -> Int #

basicUnsafeSlice :: Int -> Int -> MRotcev v s a -> MRotcev v s a #

basicOverlaps :: MRotcev v s a -> MRotcev v s a -> Bool #

basicUnsafeNew :: Int -> ST s (MRotcev v s a) #

basicInitialize :: MRotcev v s a -> ST s () #

basicUnsafeReplicate :: Int -> a -> ST s (MRotcev v s a) #

basicUnsafeRead :: MRotcev v s a -> Int -> ST s a #

basicUnsafeWrite :: MRotcev v s a -> Int -> a -> ST s () #

basicClear :: MRotcev v s a -> ST s () #

basicSet :: MRotcev v s a -> a -> ST s () #

basicUnsafeCopy :: MRotcev v s a -> MRotcev v s a -> ST s () #

basicUnsafeMove :: MRotcev v s a -> MRotcev v s a -> ST s () #

basicUnsafeGrow :: MRotcev v s a -> Int -> ST s (MRotcev v s a) #

mreverse :: MRotcev v s a -> MRotcev v s a Source #

Reverse a mutable vector in O(1) time and space.