/** * Verify if a clause exists that is compatible with goal. As a side effect, clauses that are not * compatible get discarded from the currently examined family. * * @param goal */ private boolean checkCompatibility(Term goal) { if (clauses == null) return false; ClauseInfo clause = null; do { clause = (ClauseInfo) clauses.getHead(); if (goal.match(clause.getHead())) return true; clauses = clauses.getTail(); } while (clauses != null); return false; }
// Updates indexes, deleting informations about the last removed clause public void unregister(ClauseInfo ci) { Term clause = ci.getHead(); if (clause instanceof Struct) { Struct g = (Struct) clause.getTerm(); if (g.getArity() == 0) { return; } Term t = g.getArg(0).getTerm(); if (t instanceof Var) { numCompClausesIndex.removeShared(ci); constantCompClausesIndex.removeShared(ci); structCompClausesIndex.removeShared(ci); listCompClausesList.remove(ci); } else if (t.isAtomic()) { if (t instanceof Number) { numCompClausesIndex.delete((Number) t, ci); } else if (t instanceof Struct) { constantCompClausesIndex.delete(((Struct) t).getName(), ci); } } else if (t instanceof Struct) { if (t.isList()) { listCompClausesList.remove(ci); } else { structCompClausesIndex.delete(((Struct) t).getPredicateIndicator(), ci); } } } }
// Updates indexes, storing informations about the last added clause private void register(ClauseInfo ci, boolean first) { // See FamilyClausesList.get(Term): same concept Term clause = ci.getHead(); if (clause instanceof Struct) { Struct g = (Struct) clause.getTerm(); if (g.getArity() == 0) { return; } Term t = g.getArg(0).getTerm(); if (t instanceof Var) { numCompClausesIndex.insertAsShared(ci, first); constantCompClausesIndex.insertAsShared(ci, first); structCompClausesIndex.insertAsShared(ci, first); if (first) { listCompClausesList.addFirst(ci); } else { listCompClausesList.addLast(ci); } } else if (t.isAtomic()) { if (t instanceof Number) { numCompClausesIndex.insert((Number) t, ci, first); } else if (t instanceof Struct) { constantCompClausesIndex.insert(((Struct) t).getName(), ci, first); } } else if (t instanceof Struct) { if (isAList((Struct) t)) { if (first) { listCompClausesList.addFirst(ci); } else { listCompClausesList.addLast(ci); } } else { structCompClausesIndex.insert(((Struct) t).getPredicateIndicator(), ci, first); } } } }