
com.github.vickumar1981.stringdistance.impl.LongestCommonSeqImpl.scala Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of stringdistance_2.12 Show documentation
Show all versions of stringdistance_2.12 Show documentation
A fuzzy matching string distance library for Scala and Java.
The newest version!
package com.github.vickumar1981.stringdistance.impl
private[stringdistance] trait LongestCommonSeqImpl {
protected def longestCommonSeq[T](s1: Array[T], s2: Array[T]): Int = {
val (s1Len, s2Len) = (s1.length, s2.length)
val dist = Array.ofDim[Int](s1Len + 1, s2Len + 1)
for (i <- 1 to s1Len) {
for (j <- 1 to s2Len) {
if (s1(i - 1) == s2(j - 1)) {
dist(i)(j) = dist(i - 1)(j - 1) + 1
} else {
dist(i)(j) = math.max(dist(i - 1)(j), dist(i)(j - 1))
}
}
}
dist(s1Len)(s2Len)
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy