ordered_tree: remove subs when all children are detached.
authorJean Privat <jean@pryen.org>
Sat, 26 Sep 2015 05:33:32 +0000 (01:33 -0400)
committerJean Privat <jean@pryen.org>
Sat, 26 Sep 2015 05:33:32 +0000 (01:33 -0400)
Signed-off-by: Jean Privat <jean@pryen.org>

lib/ordered_tree.nit

index 32cea45..d1dde15 100644 (file)
@@ -128,7 +128,15 @@ class OrderedTree[E: Object]
        do
                var old_parent = parents.get_or_null(e)
                if old_parent != null then
-                       sub[old_parent].remove(e)
+                       var subs = sub[old_parent]
+                       subs.remove(e)
+                       if subs.is_empty then
+                               # remove the sub when all children are detached
+                               # so that `==` and `hash` are sane
+                               # Otherwise an empty array will be considered
+                               # differently than no array.
+                               sub.keys.remove(old_parent)
+                       end
                else if roots.has(e) then
                        roots.remove(e)
                end