use of com.carrotsearch.hppc.LongArrayList in project titan by thinkaurelius.
the class VertexLongList method addAll.
@Override
public void addAll(VertexList vertexlist) {
LongArrayList othervertexids = null;
if (vertexlist instanceof VertexLongList) {
othervertexids = ((VertexLongList) vertexlist).vertices;
} else if (vertexlist instanceof VertexArrayList) {
VertexArrayList other = (VertexArrayList) vertexlist;
othervertexids = new LongArrayList(other.size());
for (int i = 0; i < other.size(); i++) othervertexids.add(other.getID(i));
} else {
throw new IllegalArgumentException("Unsupported vertex-list: " + vertexlist.getClass());
}
if (sorted && vertexlist.isSorted()) {
//Merge join
vertices = AbstractLongListUtil.mergeSort(vertices, othervertexids);
} else {
sorted = false;
vertices.add(othervertexids.buffer, 0, othervertexids.size());
}
}
use of com.carrotsearch.hppc.LongArrayList in project titan by thinkaurelius.
the class StandardTitanTx method getVertices.
@Override
public Iterable<TitanVertex> getVertices(long... ids) {
verifyOpen();
if (ids == null || ids.length == 0)
return (Iterable) getInternalVertices();
if (null != config.getGroupName()) {
MetricManager.INSTANCE.getCounter(config.getGroupName(), "db", "getVerticesByID").inc();
}
List<TitanVertex> result = new ArrayList<TitanVertex>(ids.length);
LongArrayList vids = new LongArrayList(ids.length);
for (long id : ids) {
if (isValidVertexId(id)) {
if (idInspector.isPartitionedVertex(id))
id = idManager.getCanonicalVertexId(id);
if (vertexCache.contains(id))
result.add(vertexCache.get(id, existingVertexRetriever));
else
vids.add(id);
}
}
if (!vids.isEmpty()) {
if (externalVertexRetriever.hasVerifyExistence()) {
List<EntryList> existence = graph.edgeMultiQuery(vids, graph.vertexExistenceQuery, txHandle);
for (int i = 0; i < vids.size(); i++) {
if (!existence.get(i).isEmpty()) {
long id = vids.get(i);
result.add(vertexCache.get(id, existingVertexRetriever));
}
}
} else {
for (int i = 0; i < vids.size(); i++) {
result.add(vertexCache.get(vids.get(i), externalVertexRetriever));
}
}
}
//Filter out potentially removed vertices
for (Iterator<TitanVertex> iterator = result.iterator(); iterator.hasNext(); ) {
if (iterator.next().isRemoved())
iterator.remove();
}
return result;
}
use of com.carrotsearch.hppc.LongArrayList in project titan by thinkaurelius.
the class AbstractLongListUtil method singleton.
public static LongArrayList singleton(long el) {
LongArrayList l = new LongArrayList(1);
l.add(el);
return l;
}
use of com.carrotsearch.hppc.LongArrayList in project titan by thinkaurelius.
the class AbstractLongListUtil method mergeJoin.
public static LongArrayList mergeJoin(LongArrayList a, LongArrayList b, final boolean unique) {
assert isSorted(a) : a.toString();
assert isSorted(b) : b.toString();
int counterA = 0, counterB = 0;
int sizeA = a.size();
int sizeB = b.size();
LongArrayList merge = new LongArrayList(Math.min(sizeA, sizeB));
int resultSize = 0;
while (counterA < sizeA && counterB < sizeB) {
if (a.get(counterA) == b.get(counterB)) {
long value = a.get(counterA);
if (!unique) {
merge.add(value);
resultSize++;
} else {
if (resultSize <= 0 || merge.get(resultSize - 1) != value) {
merge.add(value);
resultSize++;
}
}
counterA++;
counterB++;
} else if (a.get(counterA) < b.get(counterB)) {
counterA++;
} else {
assert a.get(counterA) > b.get(counterB);
counterB++;
}
}
return merge;
}
use of com.carrotsearch.hppc.LongArrayList in project titan by thinkaurelius.
the class StandardTitanTx method executeMultiQuery.
public void executeMultiQuery(final Collection<InternalVertex> vertices, final SliceQuery sq, final QueryProfiler profiler) {
LongArrayList vids = new LongArrayList(vertices.size());
for (InternalVertex v : vertices) {
if (!v.isNew() && v.hasId() && (v instanceof CacheVertex) && !v.hasLoadedRelations(sq))
vids.add(v.longId());
}
if (!vids.isEmpty()) {
List<EntryList> results = QueryProfiler.profile(profiler, sq, true, q -> graph.edgeMultiQuery(vids, q, txHandle));
int pos = 0;
for (TitanVertex v : vertices) {
if (pos < vids.size() && vids.get(pos) == v.longId()) {
final EntryList vresults = results.get(pos);
((CacheVertex) v).loadRelations(sq, new Retriever<SliceQuery, EntryList>() {
@Override
public EntryList get(SliceQuery query) {
return vresults;
}
});
pos++;
}
}
}
}
Aggregations