]> git.unchartedbackwaters.co.uk Git - francis/ofc.git/commitdiff
Move IndexBindings into separate file.
authorFrancis Russell <francis@unchartedbackwaters.co.uk>
Mon, 16 Apr 2012 10:37:28 +0000 (11:37 +0100)
committerFrancis Russell <francis@unchartedbackwaters.co.uk>
Mon, 16 Apr 2012 10:37:28 +0000 (11:37 +0100)
src/ofc/generators/onetep/IndexBindings.scala [new file with mode: 0644]
src/ofc/generators/onetep/TreeBuilder.scala

diff --git a/src/ofc/generators/onetep/IndexBindings.scala b/src/ofc/generators/onetep/IndexBindings.scala
new file mode 100644 (file)
index 0000000..c69b0f4
--- /dev/null
@@ -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
+  }
+}
index 00b6a36036a029c7d3d4c4d4dd315465657d8219..bc863f3e618ae8b993fbb61fc33fedef0d7b9db5 100644 (file)
@@ -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)