Returns true if v can be unified with t, updates unionfind sets.
(v ast.Variable, t ast.BaseTerm)
| 93 | |
| 94 | // Returns true if v can be unified with t, updates unionfind sets. |
| 95 | func (uf UnionFind) unify(v ast.Variable, t ast.BaseTerm) bool { |
| 96 | vroot := uf.find(v) |
| 97 | if vroot == nil { |
| 98 | vroot = v |
| 99 | } |
| 100 | troot := uf.find(t) |
| 101 | if troot == nil { |
| 102 | troot = t |
| 103 | } |
| 104 | if vroot.Equals(troot) { |
| 105 | return true |
| 106 | } |
| 107 | _, vconst := vroot.(ast.Constant) |
| 108 | _, tconst := troot.(ast.Constant) |
| 109 | if vconst && tconst { |
| 110 | return false |
| 111 | } |
| 112 | uf.parent[v] = vroot |
| 113 | uf.parent[t] = troot |
| 114 | uf.union(vroot, troot) |
| 115 | return true |
| 116 | } |
| 117 | |
| 118 | // Get implements the Subst interface so UnionFind can be used as substituion. |
| 119 | func (uf UnionFind) Get(v ast.Variable) ast.BaseTerm { |