diff --git a/src/Data/Observers/link.cpp b/src/Data/Observers/link.cpp index a3b92b0849..07aec28874 100644 --- a/src/Data/Observers/link.cpp +++ b/src/Data/Observers/link.cpp @@ -10,6 +10,7 @@ ******************************************************************************/ #include "link.hpp" +#include "hashset.hpp" #include "iterator.hpp" #include "modification.hpp" #include "observers.hpp" @@ -20,10 +21,15 @@ using namespace moebius; -hashmap> id_resolve; -hashmap> pointer_resolve; -hashmap> vertex_occurrences; -hashmap type_count (0); +static int +hash (soft_link l) { + return hash (l->t); +} + +hashmap> id_resolve; +hashmap> pointer_resolve; +hashmap> vertex_occurrences; +hashmap type_count (0); static hashset visited_table; @@ -57,15 +63,22 @@ unregister_pointer (string id, observer which) { void register_vertex (tree v, soft_link ln) { - list& l= vertex_occurrences (v); - l = list (ln, l); + if (vertex_occurrences->contains (v)) { + hashset& l= vertex_occurrences (v); + l->insert (ln); + } + else { + hashset l= hashset (); + l->insert (ln); + vertex_occurrences (v)= l; + } } void unregister_vertex (tree v, soft_link ln) { - list& l= vertex_occurrences (v); - l = remove (l, ln); - if (is_nil (l)) vertex_occurrences->reset (v); + hashset& l= vertex_occurrences (v); + l->remove (ln); + if (N (l) == 0) vertex_occurrences->reset (v); } void @@ -162,9 +175,13 @@ get_trees (string id) { } list -as_tree_list (list l) { - if (is_nil (l)) return list (); - else return list (l->item->t, as_tree_list (l->next)); +as_tree_list (hashset l) { + iterator it= iterate (l); + list r; + while (it->busy ()) { + r= list (it->next ()->t, r); + } + return r; } list