From: Francis Russell Date: Mon, 16 Apr 2012 10:37:28 +0000 (+0100) Subject: Move IndexBindings into separate file. X-Git-Url: https://git.unchartedbackwaters.co.uk/w/?a=commitdiff_plain;h=1124ac68b076234a4aeff135f1644ff60b3ae734;p=francis%2Fofc.git Move IndexBindings into separate file. --- diff --git a/src/ofc/generators/onetep/IndexBindings.scala b/src/ofc/generators/onetep/IndexBindings.scala new file mode 100644 index 0000000..c69b0f4 --- /dev/null +++ b/src/ofc/generators/onetep/IndexBindings.scala @@ -0,0 +1,27 @@ +package ofc.generators.onetep + +class IndexBindings { + import scala.collection.mutable.{Set,HashSet, HashMap} + + val spatial = new HashMap[BindingIndex, Set[SpatialIndex]] + val discrete = new HashMap[BindingIndex,Set[DiscreteIndex]] + + override def toString = spatial.mkString("\n") + "\n" + discrete.mkString("\n") + + def add(binding: BindingIndex, index: SpatialIndex) = spatial.getOrElseUpdate(binding, new HashSet()) += index + def add(binding: BindingIndex, index: DiscreteIndex) = discrete.getOrElseUpdate(binding, new HashSet()) += index + + def contains(index: SpatialIndex) : Boolean = { + for((bindingIndex, spatialIndices) <- spatial; if spatialIndices.contains(index)) + return true + + false + } + + def contains(index: DiscreteIndex) : Boolean = { + for((bindingIndex, discreteIndices) <- discrete; if discreteIndices.contains(index)) + return true + + false + } +} diff --git a/src/ofc/generators/onetep/TreeBuilder.scala b/src/ofc/generators/onetep/TreeBuilder.scala index 00b6a36..bc863f3 100644 --- a/src/ofc/generators/onetep/TreeBuilder.scala +++ b/src/ofc/generators/onetep/TreeBuilder.scala @@ -31,18 +31,6 @@ class Dictionary { } } -class IndexBindings { - import scala.collection.mutable.{Set,HashSet, HashMap} - - val spatial = new HashMap[BindingIndex, Set[SpatialIndex]] - val discrete = new HashMap[BindingIndex,Set[DiscreteIndex]] - - def add(binding: BindingIndex, index: SpatialIndex) = spatial.getOrElseUpdate(binding, new HashSet()) += index - def add(binding: BindingIndex, index: DiscreteIndex) = discrete.getOrElseUpdate(binding, new HashSet()) += index - - override def toString = spatial.mkString("\n") + "\n" + discrete.mkString("\n") -} - class TreeBuilder(dictionary : Dictionary) { val indexBindings = new IndexBindings var nextBindingIndexID = 0 @@ -62,6 +50,8 @@ class TreeBuilder(dictionary : Dictionary) { case _ => throw new InvalidInputException("Non-assignable expression on LHS of assignment.") } } + + def getIndexBindings = indexBindings private def buildIndexedSpace(term: parser.IndexedIdentifier) : IterationSpace = { val dataSpace = dictionary.getData(term.id)