nitlanguage
/
nit.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
| inline |
side by side
(parent:
ceffd5b
)
lib: introduce service `depth` in PosetElement
author
Alexandre Terrasa
<alexandre@moz-code.org>
Fri, 28 Feb 2014 01:27:57 +0000
(20:27 -0500)
committer
Alexandre 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
patch
|
blob
|
history
diff --git
a/lib/poset.nit
b/lib/poset.nit
index
aea40bb
..
fc6090f
100644
(file)
--- a/
lib/poset.nit
+++ b/
lib/poset.nit
@@
-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