File tree Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -141,6 +141,26 @@ namespace utils
141141 virtual void current_node (const node<Tp> &c_node) {}
142142#endif
143143
144+ protected:
145+ const node<Tp> &find_common_ancestor (const node &a, const node &b) const
146+ {
147+ std::unordered_set<const node<Tp> *> ancestors;
148+ auto c_a = &a;
149+ while (c_a)
150+ {
151+ ancestors.insert (c_a);
152+ c_a = c_a->get_parent () ? c_a->get_parent ().get () : nullptr ;
153+ }
154+ auto c_b = &b;
155+ while (c_b)
156+ {
157+ if (ancestors.count (c_b))
158+ return *c_b;
159+ c_b = c_b->get_parent () ? c_b->get_parent ().get () : nullptr ;
160+ }
161+ throw std::runtime_error (" No common ancestor found" );
162+ }
163+
144164 private:
145165 std::priority_queue<std::shared_ptr<node<Tp>>, std::vector<std::shared_ptr<node<Tp>>>, node_cmp> open_list;
146166 std::unordered_set<std::shared_ptr<const node<Tp>>> closed_list;
You can’t perform that action at this time.
0 commit comments