@@ -20,7 +20,6 @@ import cats.Eq
20
20
import cats .implicits ._
21
21
22
22
import scala .annotation .tailrec
23
- import scala .collection .SortedMap
24
23
import scala .collection .immutable .TreeMap
25
24
import scala .collection .compat ._
26
25
@@ -43,17 +42,17 @@ class Patience[T: Eq](withFallback: Boolean = true) extends Lcs[T] {
43
42
/** Returns occurrences that appear only once in the list, associated with their index */
44
43
private def uniques (l : List [T ]): Map [T , Int ] = {
45
44
@ tailrec
46
- def loop (l : List [Occurrence ] , acc : Map [T , Int ]): Map [T , Int ] = l match {
47
- case ( value, idx) :: tl =>
45
+ def loop (l : List [T ], idx : Int , acc : Map [T , Int ]): Map [T , Int ] = l match {
46
+ case value :: tl =>
48
47
if (acc.contains(value))
49
48
// not unique, remove it from the accumulator and go further
50
- loop(tl, acc - value)
49
+ loop(tl, idx + 1 , acc - value)
51
50
else
52
- loop(tl, acc + (value -> idx))
51
+ loop(tl, idx + 1 , acc.updated (value, idx))
53
52
case Nil =>
54
53
acc
55
54
}
56
- loop(l.zipWithIndex , Map .empty)
55
+ loop(l, 0 , Map .empty)
57
56
}
58
57
59
58
/** Takes all occurences from the first sequence and order them as in the second sequence if it is present */
0 commit comments