poset: introduce POSet::linearize
authorAlexandre Terrasa <alexandre@moz-code.org>
Thu, 8 May 2014 00:28:03 +0000 (20:28 -0400)
committerAlexandre Terrasa <alexandre@moz-code.org>
Thu, 8 May 2014 01:28:14 +0000 (21:28 -0400)
Signed-off-by: Alexandre Terrasa <alexandre@moz-code.org>

lib/poset.nit

index 65695da..ac0765e 100644 (file)
@@ -163,6 +163,13 @@ class POSet[E: Object]
                if res != 0 then return res
                return elements[a].count <=> elements[b].count
        end
+
+       # Sort a sorted array of poset elements using linearization order
+       fun linearize(elements: Collection[E]): Array[E] do
+               var lin = elements.to_a
+               sort(lin)
+               return lin
+       end
 end
 
 # View of an objet in a poset