- }
-
- @Override
- public BinaryQuery<IntProcedure> getEntry(QueryProcessor provider) {
- return provider.objectsMap.get(id);
- }
-
- @Override
- public void putEntry(QueryProcessor provider) {
- if(Development.DEVELOPMENT) {
- if(Development.<Boolean>getProperty(DevelopmentKeys.QUERYPROCESSOR_PUT, Bindings.BOOLEAN)) {
- System.err.println("put " + this);
- }
- }
- provider.objectsMap.put(id, this);
- }
-
- @Override
- final public void removeEntry(QueryProcessor provider) {
- provider.objectsMap.remove(id);
- }
-
- final static private IntArray getAssertionMap(ReadGraphImpl graph, final int r1, final int r2, final Objects entry) {
-
- class AssertionMapProc implements IntProcedure {
-
- boolean first = true;
-
- private IntArray result;
-
- public void addStatement(int s, int p, int o) {
-
- if(result.size() == 0) {
- result.add(s);
- result.add(p);
- result.add(o);
- } else {
- for(int i = 0;i < result.sizeOrData ; i+=3) {
- int existingP = result.data[i+1];
- if(p == existingP) {
- int existingO = result.data[i+2];
- if(existingO == o) return;
- }
- }
- result.add(s);
- result.add(p);
- result.add(o);
- }
-
- }
-
- @Override
- public void execute(ReadGraphImpl graph, int type) {
- AssertedStatements stms = AssertedStatements.queryEach(graph, type, r2, graph.processor, entry, null, NOPT);
- if(result == null) {
- result = stms.getResult();
- } else {
- if (first) {
- IntArray ia = result;
- result = new IntArray();
- if(ia.data != null) {
- for(int i = 0;i < ia.sizeOrData ; i+=3) addStatement(ia.data[i],ia.data[i+1],ia.data[i+2]);
- }
- first = false;
- }
- IntArray ia = stms.getResult();
- if(ia.data != null) {
- for(int i = 0;i < ia.sizeOrData ; i+=3) addStatement(ia.data[i],ia.data[i+1],ia.data[i+2]);
- }
- }
- }
-
- @Override
- public void finished(ReadGraphImpl graph) {
- }
-
- @Override
- public void exception(ReadGraphImpl graph, Throwable throwable) {
- }
-
- }
-
- AssertionMapProc amp = new AssertionMapProc();
-
- // This dependency could be cut
- PrincipalTypes.queryEach(graph, r1, graph.processor, entry, null, amp);
-
- return amp.result;
-
- }
-
- final static private void forSingleAssertion(ReadGraphImpl graph, final int r1, final int r2, final Objects entry, final IntProcedure procedure) {
-
- IntArray map = getAssertionMap(graph, r1, r2, entry);
- if(map == null) {
- if(entry != null) entry.finish(graph, procedure);
- else procedure.finished(graph);
- return;
- }
-
- int size = map.size();
- if(size == 3) {
-
- int value = map.data[2];
-
- if(entry != null) {
- entry.addOrSetFunctional(value);
- entry.finish(graph, procedure);
- } else {
- procedure.execute(graph, value);
- procedure.finished(graph);
- }
-
- } else if(size == 0) {
-
- if(entry != null) entry.finish(graph, procedure);
- else procedure.finished(graph);
-
- } else {
-
- int candidateS = map.data[0];
- int candidateO = map.data[2];
-
- SuperTypes candidate = SuperTypes.queryEach(graph, candidateS, graph.processor, entry, null, NOP);
- if(candidate.isExcepted()) {
- if(entry != null) entry.except((Throwable)candidate.getResult());
- procedure.exception(graph, (Throwable)candidate.getResult());
- return;
- }
- IntSet candidateIs = candidate.getResult();
-
- for(int i=3;i<map.size();i+=3) {
-
- int nextS = map.data[i];
- int nextO = map.data[i+2];
-
- if(nextS != candidateS) {
-
- if(candidateIs.contains(nextS)) {
-
- // Next is a super type of candidate => ignore next
-
- } else {
-
- SuperTypes next = SuperTypes.queryEach(graph, nextS, graph.processor, entry, null, NOP);
- if(next.isExcepted()) {
- if(entry != null) entry.except((Throwable)next.getResult());
- procedure.exception(graph, (Throwable)next.getResult());
- return;
- }
- IntSet nextIs = next.getResult();
-
- if(nextIs.contains(candidateS)) {
-
- // Candidate is a super type of next => next is the new candidate
-
- candidateS = nextS;
- candidateO = nextO;
- candidateIs = nextIs;
-
- } else {
-
- // candidate and next are unrelated => error
- ManyObjectsForFunctionalRelationException exception = new ManyObjectsForFunctionalRelationException("Functional relation has conflicting assertions " + r1 + ", " + r2 + " " + map , r1);
-
- if(entry != null) entry.except(exception);
- procedure.exception(graph, exception);
- return;