BaseType findmatchingvar(BaseType var) { assert (isprimitive(var)); BaseType match = null; for (BaseType bt : leaves) { if (bt == var) continue; if (sametype(bt, var)) { // make sure that this var does not cause conflict if (selections.contains(bt)) continue; if (projections.contains(bt)) continue; if (valuelist.contains(bt)) continue; BaseType parent = containsParent(bt, projections); if (parent != null) continue; match = bt; valuelist.add(bt); } } return match; }
void genconstraint(StringBuilder buf) { int nprojections = random.nextInt(NPROJECTIONS); int nselections = random.nextInt(NSELECTIONS); if (nprojections + nselections == 0) nprojections++; // guarantee non-null constraint projections = new ArrayList<BaseType>(); // generate candidate projection list while (projections.size() < nprojections) { BaseType node = choose(allnodes); // check for conflicts if (projections.contains(node)) continue; // no duplicates if (containsChild(node, projections)) continue; // child => !parent BaseType parent = containsParent(node, projections); if (parent != null) projections.remove(parent); // parent && child => !parent projections.add(node); } projections = sort(projections); // sort for (int i = 0; i < projections.size(); i++) { BaseType node = projections.get(i); if (i > 0) buf.append(","); genprojection(node, buf); } selections = new ArrayList<BaseType>(); valuelist = new ArrayList<BaseType>(); // generate candidate selection list while (selections.size() < nselections) { BaseType node = choose(leaves); if (selections.contains(node)) continue; // no duplicates // conflict avoidance if (projections.contains(node)) continue; // no duplicates with projection list if (containsChild(node, projections)) continue; // child => !parent wrt projection list BaseType parent = containsParent(node, projections); if (parent != null) continue; // project parent && select child => remove child selections.add(node); } for (int i = 0; i < nselections; i++) { BaseType node = selections.get(i); buf.append("&"); genselection(node, buf); } }