use of com.vaticle.typedb.core.common.iterator.sorted.SortedIterator.Forwardable in project grakn by graknlabs.
the class GraphIterator method computeNext.
private boolean computeNext(int pos) {
if (pos == 0)
return false;
ProcedureEdge<?, ?> edge = procedure.edge(pos);
Identifier toID = edge.to().id();
if (pos == computeNextSeekPos) {
computeNextSeekPos = edgeCount;
} else if (pos > computeNextSeekPos) {
if (!edge.isClosureEdge())
iterators.get(toID).recycle();
if (!backTrack(pos))
return false;
if (edge.isClosureEdge()) {
Vertex<?, ?> fromVertex = answer.get(edge.from().id());
Vertex<?, ?> toVertex = answer.get(edge.to().id());
if (isClosure(edge, fromVertex, toVertex))
return true;
else
return computeNextClosure(pos);
} else {
Forwardable<? extends Vertex<?, ?>, Order.Asc> toIter = branch(answer.get(edge.from().id()), edge);
iterators.put(toID, toIter);
}
}
if (edge.isClosureEdge()) {
return computeNextClosure(pos);
} else if (iterators.get(toID).hasNext()) {
answer.put(toID, iterators.get(toID).next());
return true;
} else {
return computeNextBranch(pos);
}
}
use of com.vaticle.typedb.core.common.iterator.sorted.SortedIterator.Forwardable in project grakn by graknlabs.
the class RelationIterator method createIterator.
private Forwardable<ThingVertex, Order.Asc> createIterator(int pos) {
StructureEdge<?, ?> edge = edges.get(pos);
ThingVertex player = answer.get(edge.to().id().asVariable().asRetrievable()).asThing();
return SortedIterators.Forwardable.merge(iterate(edge.asNative().asRolePlayer().types()).map(roleLabel -> {
TypeVertex roleVertex = graphMgr.schema().getType(roleLabel);
return player.ins().edge(ROLEPLAYER, roleVertex).fromAndOptimised().filter(relRole -> relationTypes.contains(relRole.key().type().properLabel()));
}), ASC).filter(relRole -> !scoped.contains(relRole.value())).mapSorted(relRole -> {
scoped.record(pos, relRole.value());
return relRole.key();
}, relation -> new KeyValue<>(relation, null), ASC);
}
use of com.vaticle.typedb.core.common.iterator.sorted.SortedIterator.Forwardable in project grakn by graknlabs.
the class ThingTypeImpl method ownsAttribute.
private void ownsAttribute(AttributeTypeImpl attributeType) {
validateIsNotDeleted();
Forwardable<AttributeType, Order.Asc> owns = getSupertypes().filter(t -> !t.equals(this)).mergeMap(ThingType::getOwns, ASC);
if (owns.findFirst(attributeType).isPresent()) {
throw exception(TypeDBException.of(OWNS_ATT_NOT_AVAILABLE, attributeType.getLabel()));
}
TypeVertex attVertex = attributeType.vertex;
TypeEdge keyEdge;
if ((keyEdge = vertex.outs().edge(OWNS_KEY, attVertex)) != null)
keyEdge.delete();
vertex.outs().put(OWNS, attVertex);
}
Aggregations