Safe Haskell | Safe |
---|---|
Language | Haskell2010 |
Implements "patience diff" and the patience algorithm for the longest increasing subsequence problem.
Patience diff
diff :: Ord t => [t] -> [t] -> [Item t] Source #
The difference between two lists, according to the "patience diff" algorithm.
An element of a computed difference.
Old t | Value taken from the "old" list, i.e. left argument to |
New t | Value taken from the "new" list, i.e. right argument to |
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 # | |
Eq t => Eq (Item t) Source # | |
Data t => Data (Item t) Source # | |
Defined in Patience 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 # | |
Read t => Read (Item t) Source # | |
Show t => Show (Item t) Source # | |
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.