use of org.apache.jena.tdb2.store.tupletable.TupleIndex in project jena by apache.
the class TupleTable method find.
/**
* Find all matching tuples - a slot of NodeId.NodeIdAny means match any
*/
public Iterator<Tuple<NodeId>> find(Tuple<NodeId> pattern) {
if (tupleLen != pattern.len())
throw new TDBException(format("Mismatch: finding tuple of length %d in a table of tuples of length %d", pattern.len(), tupleLen));
int numSlots = 0;
// Canonical form.
for (int i = 0; i < tupleLen; i++) {
NodeId x = pattern.get(i);
if (!NodeId.isAny(x))
numSlots++;
if (NodeId.isDoesNotExist(x))
return Iter.nullIterator();
}
if (numSlots == 0)
return scanAllIndex.all();
int indexNumSlots = 0;
TupleIndex index = null;
for (TupleIndex idx : indexes) {
if (idx != null) {
int w = idx.weight(pattern);
if (w > indexNumSlots) {
indexNumSlots = w;
index = idx;
}
}
}
if (index == null)
// No index at all. Scan.
index = indexes[0];
return index.find(pattern);
}
Aggregations