layout_builders: Introduced ResolutionBMizer (for future refactoring)
authorAlexandre Terrasa <alexandre@moz-code.org>
Tue, 5 Mar 2013 22:47:34 +0000 (17:47 -0500)
committerAlexandre Terrasa <alexandre@moz-code.org>
Tue, 5 Mar 2013 22:47:34 +0000 (17:47 -0500)
Signed-off-by: Alexandre Terrasa <alexandre@moz-code.org>

src/layout_builders.nit

index 423238a..69b6862 100644 (file)
@@ -92,23 +92,8 @@ class BMResolutionLayoutBuilder
 
        # Compute resolved types position using BM
        redef fun build_layout(elements) do
-               var result = new Layout[MType]
-               result.ids = self.compute_ids(elements)
-               result.pos = result.ids
-               return result
-       end
-
-       fun compute_ids(elements: Map[MClassType, Set[MType]]): Map[MType, Int] do
-               var ids = new HashMap[MType, Int]
-               var color = 0
-               for mclasstype, mclasstypes in elements do
-                       for element in mclasstypes do
-                               if ids.has_key(element) then continue
-                               ids[element] = color
-                               color += 1
-                       end
-               end
-               return ids
+               var bmizer = new ResolutionBMizer
+               return bmizer.build_layout(elements)
        end
 end
 
@@ -223,6 +208,27 @@ class MClassBMizer
        end
 end
 
+# Layout builder for resolution tables using Binary Matrix (BM)
+class ResolutionBMizer
+       init do end
+
+       fun build_layout(elements: Map[MClassType, Set[MType]]): Layout[MType] do
+               var result = new Layout[MType]
+               var ids = new HashMap[MType, Int]
+               var color = 0
+               for mclasstype, mclasstypes in elements do
+                       for element in mclasstypes do
+                               if ids.has_key(element) then continue
+                               ids[element] = color
+                               color += 1
+                       end
+               end
+               result.ids = ids
+               result.pos = ids
+               return result
+       end
+end
+
 # Colorers
 
 abstract class TypingColorer[E: Object]