patience-0.2.0.0: Patience diff and longest increasing subsequence

Safe HaskellSafe
LanguageHaskell2010

Patience

Contents

Description

Implements "patience diff" and the patience algorithm for the longest increasing subsequence problem.

Synopsis

Patience diff

diff :: Ord t => [t] -> [t] -> [Item t] Source #

The difference between two lists, according to the "patience diff" algorithm.

data Item t Source #

An element of a computed difference.

Constructors

Old t

Value taken from the "old" list, i.e. left argument to diff

New t

Value taken from the "new" list, i.e. right argument to diff

Both t t

Value taken from both lists. Both values are provided, in case your type has a non-structural definition of equality.

Instances
Functor Item Source # 
Instance details

Defined in Patience

Methods

fmap :: (a -> b) -> Item a -> Item b #

(<$) :: a -> Item b -> Item a #

Eq t => Eq (Item t) Source # 
Instance details

Defined in Patience

Methods

(==) :: Item t -> Item t -> Bool #

(/=) :: Item t -> Item t -> Bool #

Data t => Data (Item t) Source # 
Instance details

Defined in Patience

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Item t -> c (Item t) #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (Item t) #

toConstr :: Item t -> Constr #

dataTypeOf :: Item t -> DataType #

dataCast1 :: Typeable t0 => (forall d. Data d => c (t0 d)) -> Maybe (c (Item t)) #

dataCast2 :: Typeable t0 => (forall d e. (Data d, Data e) => c (t0 d e)) -> Maybe (c (Item t)) #

gmapT :: (forall b. Data b => b -> b) -> Item t -> Item t #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Item t -> r #

gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Item t -> r #

gmapQ :: (forall d. Data d => d -> u) -> Item t -> [u] #

gmapQi :: Int -> (forall d. Data d => d -> u) -> Item t -> u #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> Item t -> m (Item t) #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Item t -> m (Item t) #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Item t -> m (Item t) #

Ord t => Ord (Item t) Source # 
Instance details

Defined in Patience

Methods

compare :: Item t -> Item t -> Ordering #

(<) :: Item t -> Item t -> Bool #

(<=) :: Item t -> Item t -> Bool #

(>) :: Item t -> Item t -> Bool #

(>=) :: Item t -> Item t -> Bool #

max :: Item t -> Item t -> Item t #

min :: Item t -> Item t -> Item t #

Read t => Read (Item t) Source # 
Instance details

Defined in Patience

Show t => Show (Item t) Source # 
Instance details

Defined in Patience

Methods

showsPrec :: Int -> Item t -> ShowS #

show :: Item t -> String #

showList :: [Item t] -> ShowS #

itemChar :: Item t -> Char Source #

The character '-' or '+' or ' ' for Old or New or Both respectively.

itemValue :: Item t -> t Source #

The value from an Item. For Both, returns the "old" value.

Longest increasing subsequence

longestIncreasing :: [(Int, a)] -> [(Int, a)] Source #

Given: a list of distinct integers. Picks a subset of the integers in the same order, i.e. a subsequence, with the property that

  • it is monotonically increasing, and
  • it is at least as long as any other such subsequence.

This function uses patience sort: http://en.wikipedia.org/wiki/Patience_sorting. For implementation reasons, the actual list returned is the reverse of the subsequence.

You can pair each integer with an arbitrary annotation, which will be carried through the algorithm.