lib: introduce service `depth` in PosetElement
authorAlexandre Terrasa <alexandre@moz-code.org>
Fri, 28 Feb 2014 01:27:57 +0000 (20:27 -0500)
committerAlexandre Terrasa <alexandre@moz-code.org>
Fri, 28 Feb 2014 18:35:15 +0000 (13:35 -0500)
Signed-off-by: Alexandre Terrasa <alexandre@moz-code.org>

lib/poset.nit

index aea40bb..fc6090f 100644 (file)
@@ -230,4 +230,20 @@ class POSetElement[E: Object]
        do
                return t != self.element and self.tos.has(t)
        end
+
+       # The length of the shortest path to the root of the poset hierarchy
+       fun depth: Int do
+               if direct_greaters.is_empty then
+                       return 0
+               end
+               var min = -1
+               for p in direct_greaters do
+                       var d = poset[p].depth + 1
+                       if min == -1 or d < min then
+                               min = d
+                       end
+               end
+               return min
+
+       end
 end