aboutsummaryrefslogtreecommitdiffstats
path: root/subprojects/store-query/src/main/java/tools/refinery/store/query/equality/DeepDnfEqualityChecker.java
blob: bb60ccc9d74b3ecbd875e62badd8019cf533d299 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/*
 * SPDX-FileCopyrightText: 2021-2023 The Refinery Authors <https://refinery.tools/>
 *
 * SPDX-License-Identifier: EPL-2.0
 */
package tools.refinery.store.query.equality;

import tools.refinery.store.query.dnf.Dnf;
import tools.refinery.store.util.CycleDetectingMapper;

import java.util.List;

public class DeepDnfEqualityChecker implements DnfEqualityChecker {
	private final CycleDetectingMapper<Pair, Boolean> mapper = new CycleDetectingMapper<>(Pair::toString,
			this::doCheckEqual);

	@Override
	public boolean dnfEqual(Dnf left, Dnf right) {
		return mapper.map(new Pair(left, right));
	}

	protected boolean doCheckEqual(Pair pair) {
		return pair.left.equalsWithSubstitution(this, pair.right);
	}

	protected List<Pair> getInProgress() {
		return mapper.getInProgress();
	}

	protected record Pair(Dnf left, Dnf right) {
		@Override
		public String toString() {
			return "(%s, %s)".formatted(left.name(), right.name());
		}
	}
}