Skip to content

Commit

Permalink
Fix failing scalatest
Browse files Browse the repository at this point in the history
  • Loading branch information
Feynman Liang committed Jul 13, 2015
1 parent 2e00cba commit f055d82
Showing 1 changed file with 4 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,19 @@ private[fpm] object LocalPrefixSpan extends Logging with Serializable {
if (database.isEmpty) return Iterator.empty

val frequentItemAndCounts = getFreqItemAndCounts(minCount, database)
val frequentItems = frequentItemAndCounts.map(_._1)
val frequentItems = frequentItemAndCounts.map(_._1).toSet
val frequentPatternAndCounts = frequentItemAndCounts
.map { case (item, count) => ((item :: prefix).reverse.toArray, count) }

val filteredProjectedDatabase = database.map(x => x.filter(frequentItems.contains(_)))

if (prefix.length + 1 < maxPatternLength) {
frequentPatternAndCounts ++ frequentItems.flatMap { item =>
frequentPatternAndCounts.iterator ++ frequentItems.flatMap { item =>
val nextProjected = project(filteredProjectedDatabase, item)
run(minCount, maxPatternLength, item :: prefix, nextProjected)
}
} else {
frequentPatternAndCounts
frequentPatternAndCounts.iterator
}
}

Expand Down Expand Up @@ -93,12 +93,11 @@ private[fpm] object LocalPrefixSpan extends Logging with Serializable {
*/
private def getFreqItemAndCounts(
minCount: Long,
database: Iterable[Array[Int]]): Iterator[(Int, Long)] = {
database: Iterable[Array[Int]]): Iterable[(Int, Long)] = {
database.flatMap(_.distinct)
.foldRight(Map[Int, Long]().withDefaultValue(0L)) { case (item, ctr) =>
ctr + (item -> (ctr(item) + 1))
}
.filter(_._2 >= minCount)
.iterator
}
}

0 comments on commit f055d82

Please sign in to comment.