dry-up map creation

This commit is contained in:
Johannes Rudolph 2012-10-24 10:41:40 +02:00
parent eb54e20c56
commit ff4482064c
1 changed files with 11 additions and 7 deletions

View File

@ -47,14 +47,18 @@ object IvyGraphMLDependencies extends App {
def module(id: ModuleId): Module = modules(id)
lazy val dependencyMap: Map[ModuleId, Seq[Module]] = {
lazy val dependencyMap: Map[ModuleId, Seq[Module]] =
createMap(identity)
lazy val reverseDependencyMap: Map[ModuleId, Seq[Module]] =
createMap { case (a, b) => (b, a) }
def createMap(bindingFor: ((ModuleId, ModuleId)) => (ModuleId, ModuleId)): Map[ModuleId, Seq[Module]] = {
val m = new HashMap[ModuleId, MSet[Module]] with MultiMap[ModuleId, Module]
edges.foreach { case (from, to) => m.addBinding(from, module(to)) }
m.toMap.mapValues(_.toSeq.sortBy(_.id.idString))
}
lazy val reverseDependencyMap: Map[ModuleId, Seq[Module]] = {
val m = new HashMap[ModuleId, MSet[Module]] with MultiMap[ModuleId, Module]
edges.foreach { case (from, to) => m.addBinding(to, module(from)) }
edges.foreach { entry =>
val (f, t) = bindingFor(entry)
m.addBinding(f, module(t))
}
m.toMap.mapValues(_.toSeq.sortBy(_.id.idString))
}
}