Commit bff8c851 authored by Ryan Wisnesky's avatar Ryan Wisnesky
Browse files

fixes and improvements to sigma_chase and better hashcodes for a few types

parent fcba3c4f
......@@ -1072,7 +1072,7 @@ Defines the SQL quasi-type to be used with CONVERT statements when emitting SQL
\subsection{{\tt chase\_style}}
Either {\tt parallel} (faster, but uses more space) or {\tt leftkan} (slower, but uses less space).
Either {\tt parallel} (faster, but uses more space) or {\tt leftkan} (slower, but uses less space). Note that parallel will not be compatible with sigma operations such as sigma on transforms, the co-unit, etc. Parallel is recommended only when data volume is too large for the other algorithms.
\end{document}
......
......@@ -94,7 +94,7 @@ public class BinRelMap<X, Y> implements Iterable<Pair<X, Y>> {
}
public BinRelMap() {
R = new LinkedHashMap<>();
R = new LinkedHashMap<>(1000000);
}
public boolean add(X x, Y y) {
......
......@@ -8,13 +8,24 @@ import java.io.Serializable;
@SuppressWarnings("serial")
public class Pair<T1, T2> implements Comparable<Pair<T1, T2>>, Serializable {
public T1 first; //TODO aql make these final. Same for Triple
public T2 second;
public T1 first; //TODO aql make these final. Same for Triple
public T2 second;
public void setFirst(T1 x) {
first = x;
hashCode2();
}
public void setSecond(T2 x) {
second = x;
hashCode2();
}
public Pair(T1 value, T2 value2) {
first = value;
second = value2;
hashCode2();
}
private int hashCode;
@Override
public String toString() {
......@@ -24,11 +35,15 @@ public class Pair<T1, T2> implements Comparable<Pair<T1, T2>>, Serializable {
@Override
public int hashCode() {
return hashCode;
}
public void hashCode2() {
int prime = 31;
int result = 1;
result = prime * result + ((first == null) ? 0 : first.hashCode());
result = prime * result + ((second == null) ? 0 : second.hashCode());
return result;
hashCode = result;
}
@Override
......
......@@ -20,12 +20,12 @@ import catdata.graph.UnionFind;
public class Chase<Ty, En1, Sym, Fk1, Att1, En2, Fk2, Att2, Gen, Sk, X, Y> {
private static <Ty,Y,En2,Sym,Fk2,Att2,Gen,Sk> Optional<Term<Ty, Void, Sym, Void, Void, Void, Chc<Y, Lineage<Ty, En2, Sym, Fk2, Att2, Gen, Sk>>>> mergeable(
private static <Ty, Y, En2, Sym, Fk2, Att2, Gen, Sk> Optional<Term<Ty, Void, Sym, Void, Void, Void, Chc<Y, Lineage<Ty, En2, Sym, Fk2, Att2, Gen, Sk>>>> mergeable(
Term<Ty, Void, Sym, Void, Void, Void, Chc<Y, Lineage<Ty, En2, Sym, Fk2, Att2, Gen, Sk>>> t,
Term<Ty, Void, Sym, Void, Void, Void, Chc<Y, Lineage<Ty, En2, Sym, Fk2, Att2, Gen, Sk>>> r) {
if (t.sk != null ) {
if (t.sk != null) {
return Optional.of(r);
} else if (r.sk != null ) {
} else if (r.sk != null) {
return Optional.of(t);
} else if (t.obj != null && r.obj != null && t.obj.equals(r.obj)) {
return Optional.of(t);
......@@ -34,8 +34,8 @@ public class Chase<Ty, En1, Sym, Fk1, Att1, En2, Fk2, Att2, Gen, Sk, X, Y> {
.iterator(), b = r.args.iterator();
List<Term<Ty, Void, Sym, Void, Void, Void, Chc<Y, Lineage<Ty, En2, Sym, Fk2, Att2, Gen, Sk>>>> l = new LinkedList<>();
for (int i = 0; i < t.args.size(); i++) {
Term<Ty, Void, Sym, Void, Void, Void, Chc<Y, Lineage<Ty, En2, Sym, Fk2, Att2, Gen, Sk>>> c = a
.next(), d = b.next();
Term<Ty, Void, Sym, Void, Void, Void, Chc<Y, Lineage<Ty, En2, Sym, Fk2, Att2, Gen, Sk>>> c = a.next(),
d = b.next();
Optional<Term<Ty, Void, Sym, Void, Void, Void, Chc<Y, Lineage<Ty, En2, Sym, Fk2, Att2, Gen, Sk>>>> z = mergeable(
c, d);
if (!z.isPresent()) {
......@@ -47,7 +47,7 @@ public class Chase<Ty, En1, Sym, Fk1, Att1, En2, Fk2, Att2, Gen, Sk, X, Y> {
}
return Optional.empty();
}
private final Mapping<Ty, En1, Sym, Fk1, Att1, En2, Fk2, Att2> F;
// private final
// Schema<Ty,Chc<En1,En2>,Sym,Chc<Chc<Fk1,Fk2>,En1>,Chc<Att1,Att2>> S;
......@@ -61,8 +61,7 @@ public class Chase<Ty, En1, Sym, Fk1, Att1, En2, Fk2, Att2, Gen, Sk, X, Y> {
public final Ctx<Ty, BinRelMap<Term<Ty, Void, Sym, Void, Void, Void, Chc<Y, Lineage<Ty, En2, Sym, Fk2, Att2, Gen, Sk>>>, Term<Ty, Void, Sym, Void, Void, Void, Chc<Y, Lineage<Ty, En2, Sym, Fk2, Att2, Gen, Sk>>>>> tys;
public final Ctx<Att2, BinRelMap<Lineage<Void, En2, Void, Fk2, Void, Gen, Void>, Term<Ty, Void, Sym, Void, Void, Void, Chc<Y, Lineage<Ty, En2, Sym, Fk2, Att2, Gen, Sk>>>>> atts;
// public final Ctx<Ty, Ctx<Y, Term<Ty, Void, Sym, Void, Void, Void, Chc<Y,
// Lineage<Ty, En2, Sym, Fk2, Att2, Gen, Sk>>>>> vs;
public final Ctx<Ty, Ctx<Y, Term<Ty, Void, Sym, Void, Void, Void, Chc<Y, Lineage<Ty, En2, Sym, Fk2, Att2, Gen, Sk>>>>> vs;
public Content() {
ens = new Ctx<>();
......@@ -80,7 +79,7 @@ public class Chase<Ty, En1, Sym, Fk1, Att1, En2, Fk2, Att2, Gen, Sk, X, Y> {
tys = new Ctx<>();
atts = new Ctx<>();
// vs = new Ctx<>();
vs = new Ctx<>();
for (Ty ty : F.dst.typeSide.tys) {
tys.put(ty, new BinRelMap<>());
}
......@@ -88,7 +87,7 @@ public class Chase<Ty, En1, Sym, Fk1, Att1, En2, Fk2, Att2, Gen, Sk, X, Y> {
atts.put(att, new BinRelMap<>());
}
for (Ty ty : F.src.typeSide.tys) {
// vs.put(ty, new Ctx<>());
vs.put(ty, new Ctx<>());
}
}
......@@ -120,6 +119,9 @@ public class Chase<Ty, En1, Sym, Fk1, Att1, En2, Fk2, Att2, Gen, Sk, X, Y> {
for (En1 en1 : us.keySet()) {
us.get(en1).putAll(c.us.get(en1).map);
}
for (Ty t : vs.keySet()) {
vs.get(t).putAll(c.vs.get(t).map);
}
}
public Content(Instance<Ty, En1, Sym, Fk1, Att1, Gen, Sk, X, Y> I) {
......@@ -145,27 +147,28 @@ public class Chase<Ty, En1, Sym, Fk1, Att1, En2, Fk2, Att2, Gen, Sk, X, Y> {
}
this.tys = new Ctx<>();
this.vs = new Ctx<>();
for (Ty ty : F.dst.typeSide.tys) {
tys.put(ty, new BinRelMap<>());
vs.put(ty, new Ctx<>());
}
this.atts = new Ctx<>();
for (Att2 att : F.dst.atts.keySet()) {
atts.put(att, new BinRelMap<>());
}
// this.vs = new Ctx<>();
for (Y y : I.algebra().talg().sks.keySet()) {
Ty ty = I.algebra().talg().sks.get(y);
vs.get(ty).put(y, Term.Sk(Chc.inLeft(y)));
}
/*
* for (Ty ty : I.schema().typeSide.tys) { Ctx<Y, Term<Ty, Void, Sym, Void,
* Void, Void, Chc<Y, Lineage<Ty, En2, Sym, Fk2, Att2, Gen, Sk>>>> ctx = new
* Ctx<>(); for (Y y : I.algebra().talg().sks.keySet()) {
* ctx.put(y,Term.Sk(Chc.inLeft(y))); } vs.put(ty, ctx); }
*/
}
public Content merge(Ctx<En2, UnionFind<Lineage<Void, En2, Void, Fk2, Void, Gen, Void>>> ufs,
Ctx<Ty, UnionFind<Term<Ty, Void, Sym, Void, Void, Void, Chc<Y, Lineage<Ty, En2, Sym, Fk2, Att2, Gen, Sk>>>>> ufs2) {
//System.out.println("start " + this);
// System.out.println("start " + this);
Content ret = new Content();
for (En2 en : F.dst.ens) {
......@@ -178,7 +181,7 @@ public class Chase<Ty, En1, Sym, Fk1, Att1, En2, Fk2, Att2, Gen, Sk, X, Y> {
ret.ens.get(en).add(n, n);
}
}
//System.out.println("yyy " + ret);
// System.out.println("yyy " + ret);
for (Fk2 fk : F.dst.fks.keySet()) {
En2 a = F.dst.fks.get(fk).first;
......@@ -188,24 +191,23 @@ public class Chase<Ty, En1, Sym, Fk1, Att1, En2, Fk2, Att2, Gen, Sk, X, Y> {
Lineage<Void, En2, Void, Fk2, Void, Gen, Void> n1 = ufs.get(a).find(x.first);
Lineage<Void, En2, Void, Fk2, Void, Gen, Void> n2 = ufs.get(b).find(x.second);
ret.fks.get(fk).add(n1, n2);
//System.out.println("on " + fk + " doing " + x + " is " + n1 + "," + n2);
// System.out.println("on " + fk + " doing " + x + " is " + n1 + "," + n2);
}
}
//System.out.println("xxx " + ret);
// System.out.println("xxx " + ret);
for (En1 en : us.keySet()) {
for (X x : us.get(en).keySet()) {
Lineage<Void, En2, Void, Fk2, Void, Gen, Void> n = us.get(en).get(x);
ret.us.get(en).put(x, ufs.get(F.ens.get(en)).find(n));
}
}
// partitions to their constants, if any
Ctx<Term<Ty, Void, Sym, Void, Void, Void, Chc<Y, Lineage<Ty, En2, Sym, Fk2, Att2, Gen, Sk>>>, Term<Ty, Void, Sym, Void, Void, Void, Chc<Y, Lineage<Ty, En2, Sym, Fk2, Att2, Gen, Sk>>>> pars = new Ctx<>();
for (Ty ty : F.dst.typeSide.tys) {
for (Term<Ty, Void, Sym, Void, Void, Void, Chc<Y, Lineage<Ty, En2, Sym, Fk2, Att2, Gen, Sk>>> x
: ufs2.get(ty).values()) {
for (Term<Ty, Void, Sym, Void, Void, Void, Chc<Y, Lineage<Ty, En2, Sym, Fk2, Att2, Gen, Sk>>> x : ufs2
.get(ty).values()) {
Term<Ty, Void, Sym, Void, Void, Void, Chc<Y, Lineage<Ty, En2, Sym, Fk2, Att2, Gen, Sk>>> par = ufs2
.get(ty).find(x);
......@@ -214,31 +216,32 @@ public class Chase<Ty, En1, Sym, Fk1, Att1, En2, Fk2, Att2, Gen, Sk, X, Y> {
.get(par);
Optional<Term<Ty, Void, Sym, Void, Void, Void, Chc<Y, Lineage<Ty, En2, Sym, Fk2, Att2, Gen, Sk>>>> me = mergeable(
x, parConst);
//System.out.println("2 " + x + " and " + parConst);
// System.out.println("2 " + x + " and " + parConst);
if (!me.isPresent()) {
throw new RuntimeException("Collision: " + print(x) + " not mergeable with "
+ print(parConst) + " in input instance.");
} else {
pars.map.put(par, me.get());
//System.out.println("merge " + x + " and " + parConst + " to get " + me.get());
// System.out.println("merge " + x + " and " + parConst + " to get " +
// me.get());
}
} else {
Optional<Term<Ty, Void, Sym, Void, Void, Void, Chc<Y, Lineage<Ty, En2, Sym, Fk2, Att2, Gen, Sk>>>> me = mergeable(
x, par);
//System.out.println("1 " + x + " and " + par);
// System.out.println("1 " + x + " and " + par);
if (!me.isPresent()) {
throw new RuntimeException("Collision: " + print(x) + " not mergeable with "
+ print(par) + " in input instance.");
throw new RuntimeException("Collision: " + print(x) + " not mergeable with " + print(par)
+ " in input instance.");
} else {
pars.put(par, x);
//System.out.println("setting " + par + " to " + x);
// System.out.println("setting " + par + " to " + x);
}
}
}
}
//System.out.println("partitions: " + pars);
// System.out.println("partitions: " + pars);
BiFunction<Ty, Term<Ty, Void, Sym, Void, Void, Void, Chc<Y, Lineage<Ty, En2, Sym, Fk2, Att2, Gen, Sk>>>, Term<Ty, Void, Sym, Void, Void, Void, Chc<Y, Lineage<Ty, En2, Sym, Fk2, Att2, Gen, Sk>>>> nf = (
t, zz) -> {
......@@ -261,7 +264,7 @@ public class Chase<Ty, En1, Sym, Fk1, Att1, En2, Fk2, Att2, Gen, Sk, X, Y> {
ret.tys.get(ty).add(n, n);
}
}
//System.out.println("yyy2 " + ret);
// System.out.println("yyy2 " + ret);
for (Att2 att : F.dst.atts.keySet()) {
En2 a = F.dst.atts.get(att).first;
Ty b = F.dst.atts.get(att).second;
......@@ -274,14 +277,17 @@ public class Chase<Ty, En1, Sym, Fk1, Att1, En2, Fk2, Att2, Gen, Sk, X, Y> {
// ////System.out.println("on " + fk + " doing " + x + " is " + n1 + "," + n2);
}
}
//System.out.println("xxx2 " + ret);
// System.out.println("xxx2 " + ret);
for (Ty ty : vs.keySet()) {
for (Y x : vs.get(ty).keySet()) {
Term<Ty, Void, Sym, Void, Void, Void, Chc<Y, Lineage<Ty, En2, Sym, Fk2, Att2, Gen, Sk>>> n = vs
.get(ty).get(x);
ret.vs.get(ty).put(x, nf.apply(ty, n));
}
}
/*
* for (Ty ty : vs.keySet()) { for (Y x : vs.get(ty).keySet()) { Term<Ty, Void,
* Sym, Void, Void, Void, Chc<Y, Lineage<Ty, En2, Sym, Fk2, Att2, Gen, Sk>>> n =
* vs.get(ty).get(x); ret.vs.get(ty).put(x, nf.apply(ty, n)); } }
*/
////System.out.println("merged " + ret);
//// System.out.println("merged " + ret);
// ret.iso = iso.map((k,x)->new Pair<>(k,x.map(y->ufs.get(k).find(y))));
return ret;
}
......@@ -297,8 +303,6 @@ public class Chase<Ty, En1, Sym, Fk1, Att1, En2, Fk2, Att2, Gen, Sk, X, Y> {
return t.mapGenSk(Function.identity(), f).toString();
}
public String sizes() {
String s = "";
for (En2 en2 : ens.keySet()) {
......@@ -312,7 +316,8 @@ public class Chase<Ty, En1, Sym, Fk1, Att1, En2, Fk2, Att2, Gen, Sk, X, Y> {
@Override
public String toString() {
return "Content [ens=" + ens + ", fks=" + fks + ", us=" + us + ", tys=" + tys + ", atts=" + atts + "]";
return "Content [ens=" + ens + ", fks=" + fks + ", us=" + us + ", tys=" + tys + ", atts=" + atts + ", vs="
+ vs + "]";
}
}
......@@ -341,21 +346,19 @@ public class Chase<Ty, En1, Sym, Fk1, Att1, En2, Fk2, Att2, Gen, Sk, X, Y> {
int i = 0;
T = new Content(I);
//System.out.println(T);
// System.out.println(T);
for (;;) {
boolean changed = step();
boolean changed = step(i == 0);
if (!changed) {
return;
}
//System.out.println(T);
if (i++ > 2) {
throw new RuntimeException();
}
// System.out.println(T);
i++;
}
}
private boolean step() {
private boolean step(boolean isFirstTime) {
Content toAdd = new Content();
Ctx<En2, UnionFind<Lineage<Void, En2, Void, Fk2, Void, Gen, Void>>> ufs = new Ctx<>();
......@@ -368,29 +371,31 @@ public class Chase<Ty, En1, Sym, Fk1, Att1, En2, Fk2, Att2, Gen, Sk, X, Y> {
}
Boolean[] changed = new Boolean[] { false };
//System.out.println("A " + changed[0]);
// System.out.println("A " + changed[0]);
makeArrowsTotal(toAdd, changed);
//System.out.println("B " + changed[0]);
// System.out.println("B " + changed[0]);
makeObjectsTotal(toAdd, changed);
//System.out.println("C " + changed[0]);
// System.out.println("C " + changed[0]);
moveObjects(toAdd, changed);
//System.out.println("D " + changed[0]);
// if (isFirstTime) {
moveObjects(toAdd, changed);
// System.out.println("D " + changed[0]);
//}
doEqs(toAdd, ufs, ufs2, changed);
T.addAll(toAdd);
//System.out.println("E " + changed[0]);
// System.out.println("E " + changed[0]);
makeFunctional(ufs, changed, ufs2);
makeFunctional(ufs, changed, ufs2);
T = T.merge(ufs, ufs2);
if (!changed[0]) {
return false;
}
return true;
}
......@@ -437,7 +442,7 @@ public class Chase<Ty, En1, Sym, Fk1, Att1, En2, Fk2, Att2, Gen, Sk, X, Y> {
for (Term<Ty, Void, Sym, Void, Void, Void, Chc<Y, Lineage<Ty, En2, Sym, Fk2, Att2, Gen, Sk>>> y2 : ys) {
if (!y1.equals(y2)) {
ufs2.get(w).union(y1, y2);
////System.out.println("3equating " + y1 + " = " + y2 + " at " + w);
//// System.out.println("3equating " + y1 + " = " + y2 + " at " + w);
changed[0] = true;
}
......@@ -451,21 +456,21 @@ public class Chase<Ty, En1, Sym, Fk1, Att1, En2, Fk2, Att2, Gen, Sk, X, Y> {
Ctx<Ty, UnionFind<Term<Ty, Void, Sym, Void, Void, Void, Chc<Y, Lineage<Ty, En2, Sym, Fk2, Att2, Gen, Sk>>>>> ufs2,
Boolean[] changed) {
//System.out.println("P " + changed[0]);
// System.out.println("P " + changed[0]);
targetEqs(toAdd, ufs, changed);
//System.out.println("Q " + changed[0]);
// System.out.println("Q " + changed[0]);
collageEqs(toAdd, ufs, changed);
//System.out.println("R " + changed[0]);
// System.out.println("R " + changed[0]);
targetEqsT(toAdd, ufs2, changed);
//System.out.println("S " + changed[0]);
// System.out.println("S " + changed[0]);
collageEqsT(toAdd, ufs2, changed);
//System.out.println("T " + changed[0]);
// System.out.println("T " + changed[0]);
}
......@@ -511,12 +516,12 @@ public class Chase<Ty, En1, Sym, Fk1, Att1, En2, Fk2, Att2, Gen, Sk, X, Y> {
public void collageEqsT(Content toAdd,
Ctx<Ty, UnionFind<Term<Ty, Void, Sym, Void, Void, Void, Chc<Y, Lineage<Ty, En2, Sym, Fk2, Att2, Gen, Sk>>>>> ufs,
Boolean[] changed) {
// //System.out.println("is " + T);
// //System.out.println("is " + T);
for (Att1 a : F.src.atts.keySet()) {
En1 v = F.src.atts.get(a).first;
Ty w = F.src.atts.get(a).second;
// a.m_w = m_v.F(a)
//TODO aql m_w tables do exist
// TODO aql m_w tables do exist
for (X x : I.algebra().en(v)) {
Term<Ty, Void, Sym, Void, Void, Void, Y> a0 = I.algebra().att(a, x);
......@@ -525,25 +530,25 @@ public class Chase<Ty, En1, Sym, Fk1, Att1, En2, Fk2, Att2, Gen, Sk, X, Y> {
Lineage<Void, En2, Void, Fk2, Void, Gen, Void> initial = T.us.get(v).get(x);
Set<Term<Ty, Void, Sym, Void, Void, Void, Chc<Y, Lineage<Ty, En2, Sym, Fk2, Att2, Gen, Sk>>>> N = evalT(
F.atts.get(a).third, Util.singSet(initial));
//System.out.println("eval on " + x + " at " + a + " gives " + N + " with a lhs of " + lhs);
if (!N.contains(lhs)) {
// System.out.println("eval on " + x + " at " + a + " gives " + N + " with a lhs
// of " + lhs);
if (!N.contains(lhs)) {
Term<Ty, Void, Sym, Void, Void, Void, Chc<Y, Lineage<Ty, En2, Sym, Fk2, Att2, Gen, Sk>>> m = populateT(
toAdd, F.atts.get(a).third, initial);
//if (!mergeable(m, lhs)) {
changed[0] = true;
ufs.get(w).union(m, lhs);
for (Term<Ty, Void, Sym, Void, Void, Void, Chc<Y, Lineage<Ty, En2, Sym, Fk2, Att2, Gen, Sk>>> xx : N) {
ufs.get(w).union(xx, lhs);
}
// //System.out.println("2equating " + m + " and " + lhs + " at " + w );
// if (!mergeable(m, lhs)) {
changed[0] = true;
ufs.get(w).union(m, lhs);
for (Term<Ty, Void, Sym, Void, Void, Void, Chc<Y, Lineage<Ty, En2, Sym, Fk2, Att2, Gen, Sk>>> xx : N) {
ufs.get(w).union(xx, lhs);
}
// //System.out.println("2equating " + m + " and " + lhs + " at " + w );
} else {
// //System.out.println(" contains " + lhs + ", on " + x + " and " + a);
}
// //System.out.println(" contains " + lhs + ", on " + x + " and " + a);
}
}
}
}
......@@ -559,7 +564,11 @@ public class Chase<Ty, En1, Sym, Fk1, Att1, En2, Fk2, Att2, Gen, Sk, X, Y> {
}
return Term.Sym(t.sym, l);
} else if (t.sk != null) {
return Term.Sk(Chc.inLeft(t.sk));
Ty ty = I.algebra().talg().sks.get(t.sk);
Term<Ty, Void, Sym, Void, Void, Void, Chc<Y, Lineage<Ty, En2, Sym, Fk2, Att2, Gen, Sk>>> l = T.vs.get(ty)
.get(t.sk);
return l;
// return Term.Sk(Chc.inLeft(t.sk));
}
return Util.anomaly();
}
......@@ -618,7 +627,7 @@ public class Chase<Ty, En1, Sym, Fk1, Att1, En2, Fk2, Att2, Gen, Sk, X, Y> {
toAdd, eq.second, initial), m2 = populateT(toAdd, eq.third, initial);
ufs.get(dst).union(m, m2);
////System.out.println("1equating " + m + " and " + m2 + " at " + dst);
//// System.out.println("1equating " + m + " and " + m2 + " at " + dst);
}
}
}
......@@ -699,7 +708,8 @@ public class Chase<Ty, En1, Sym, Fk1, Att1, En2, Fk2, Att2, Gen, Sk, X, Y> {
Set<Term<Ty, Void, Sym, Void, Void, Void, Chc<Y, Lineage<Ty, En2, Sym, Fk2, Att2, Gen, Sk>>>> ret = new HashSet<>();
Set<Lineage<Void, En2, Void, Fk2, Void, Gen, Void>> x = eval(t.arg.toFkList(), N);
for (Lineage<Void, En2, Void, Fk2, Void, Gen, Void> l : x) {
Collection<Term<Ty, Void, Sym, Void, Void, Void, Chc<Y, Lineage<Ty, En2, Sym, Fk2, Att2, Gen, Sk>>>> w = T.atts.get(t.att).get(l);
Collection<Term<Ty, Void, Sym, Void, Void, Void, Chc<Y, Lineage<Ty, En2, Sym, Fk2, Att2, Gen, Sk>>>> w = T.atts
.get(t.att).get(l);
if (w == null) {
w = new HashSet<>();
}
......@@ -712,7 +722,7 @@ public class Chase<Ty, En1, Sym, Fk1, Att1, En2, Fk2, Att2, Gen, Sk, X, Y> {
public void moveObjects(Content toAdd, Boolean[] changed) {
// a : a -> F(a)
System.out.println("started");
for (En1 a : F.src.ens) {
// T_v(x) -> Ey. T_a(x,y)
// this is the 'loading' step in the Content constructor
......@@ -729,20 +739,31 @@ public class Chase<Ty, En1, Sym, Fk1, Att1, En2, Fk2, Att2, Gen, Sk, X, Y> {
}
}
}
/*
* for (Ty a : F.src.typeSide.tys) { // T_v(x) -> Ey. T_a(x,y) // this is the
* 'loading' step in the Content constructor
*
* // T_a(x,y) -> T_v(x) /\ T_w(y) Ty w = a; Ctx<Y, Term<Ty, Void, Sym, Void,
* Void, Void, Chc<Y, Lineage<Ty, En2, Sym, Fk2, Att2, Gen, Sk>>>> T_a =
* T.vs.get(a); BinRelMap<Term<Ty, Void, Sym, Void, Void, Void, Chc<Y,
* Lineage<Ty, En2, Sym, Fk2, Att2, Gen, Sk>>>, Term<Ty, Void, Sym, Void, Void,
* Void, Chc<Y, Lineage<Ty, En2, Sym, Fk2, Att2, Gen, Sk>>>> T_w = T.tys.get(w);
* for (Y xy : T_a.keySet()) { Term<Ty, Void, Sym, Void, Void, Void, Chc<Y,
* Lineage<Ty, En2, Sym, Fk2, Att2, Gen, Sk>>> x = T_a.get(xy); if
* (!T_w.containsKey(x)) { changed[0] = changed[0] | toAdd.tys.get(w).add(x, x);
* } } }
*/
System.out.println("started2");
for (Ty a : F.src.typeSide.tys) {
// T_v(x) -> Ey. T_a(x,y) // this is the 'loading' step in the Content
// T_a(x,y) -> T_v(x) /\ T_w(y)
Ty w = a;
Ctx<Y, Term<Ty, Void, Sym, Void, Void, Void, Chc<Y, Lineage<Ty, En2, Sym, Fk2, Att2, Gen, Sk>>>> T_a = T.vs
.get(a);
BinRelMap<Term<Ty, Void, Sym, Void, Void, Void, Chc<Y, Lineage<Ty, En2, Sym, Fk2, Att2, Gen, Sk>>>, Term<Ty, Void, Sym, Void, Void, Void, Chc<Y, Lineage<Ty, En2, Sym, Fk2, Att2, Gen, Sk>>>> T_w = T.tys
.get(w);
//int i = 0;
for (Y xy : T_a.keySet()) {
Term<Ty, Void, Sym, Void, Void, Void, Chc<Y, Lineage<Ty, En2, Sym, Fk2, Att2, Gen, Sk>>> x = T_a
.get(xy);
if (!T_w.containsKey(x)) {
changed[0] = changed[0] | toAdd.tys.get(w).add(x, x);
}
// System.out.println(xy + " " + i++);
}
}
// System.out.println("ended");
}
public void makeObjectsTotal(Content toAdd, Boolean[] changed) {
......
......@@ -162,7 +162,7 @@ public class SigmaLeftKanAlgebra<Ty, En1, Sym, Fk1, Att1, En2, Fk2, Att2, Gen, S
for (List<Pair<X, Lineage<Void, En2, Void, Fk2, Void, Gen, Void>>> a : ua.map.values()) {
for (Pair<X, Lineage<Void, En2, Void, Fk2, Void, Gen, Void>> s : a) {
if (s.second.equals(y)) {
s.second = x;
s.setSecond(x);
}
}
}
......
......@@ -281,7 +281,7 @@ public final class Term<Ty, En, Sym, Fk, Att, Gen, Sk> {
private Term(Var var, Sym sym, Fk fks, Att att, Gen gen, Sk sk, List<Term<Ty, En, Sym, Fk, Att, Gen, Sk>> args, Term<Ty, En, Sym, Fk, Att, Gen, Sk> arg, Object obj, Ty ty) {
this.var = var;
this.sym = sym;
fk = fks;
this.fk = fks;
this.att = att;
this.gen = gen;
this.sk = sk;
......@@ -289,6 +289,7 @@ public final class Term<Ty, En, Sym, Fk, Att, Gen, Sk> {
this.arg = arg;
this.obj = obj;
this.ty = ty;
_hashCode = hashCode2();
}
public String toStringSql() {
......@@ -507,6 +508,11 @@ public final class Term<Ty, En, Sym, Fk, Att, Gen, Sk> {
*/
@Override
public int hashCode() {
return _hashCode;
}
private int _hashCode;
public int hashCode2() {
int prime = 31;
int result = 1;
result = prime * result + ((arg == null) ? 0 : arg.hashCode());
......@@ -780,6 +786,12 @@ public final class Term<Ty, En, Sym, Fk, Att, Gen, Sk> {
return Head(e.getApp().f, e.getApp().args.stream().map(Term::fromKB).collect(Collectors.toList()));
}
public Set<Sk> sks() {
Set<Sk> ret = new HashSet<>();
sks(ret);
return ret;
}