Search in sources :

Example 6 with LongArrayList

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());
    }
}
Also used : LongArrayList(com.carrotsearch.hppc.LongArrayList)

Example 7 with LongArrayList

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;
}
Also used : LongArrayList(com.carrotsearch.hppc.LongArrayList) LongArrayList(com.carrotsearch.hppc.LongArrayList) EntryList(com.thinkaurelius.titan.diskstorage.EntryList)

Example 8 with LongArrayList

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;
}
Also used : LongArrayList(com.carrotsearch.hppc.LongArrayList)

Example 9 with LongArrayList

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;
}
Also used : LongArrayList(com.carrotsearch.hppc.LongArrayList)

Example 10 with LongArrayList

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++;
            }
        }
    }
}
Also used : LongArrayList(com.carrotsearch.hppc.LongArrayList) EntryList(com.thinkaurelius.titan.diskstorage.EntryList) CacheVertex(com.thinkaurelius.titan.graphdb.vertices.CacheVertex) SliceQuery(com.thinkaurelius.titan.diskstorage.keycolumnvalue.SliceQuery)

Aggregations

LongArrayList (com.carrotsearch.hppc.LongArrayList)11 EntryList (com.thinkaurelius.titan.diskstorage.EntryList)2 LongHashSet (com.carrotsearch.hppc.LongHashSet)1 LongSet (com.carrotsearch.hppc.LongSet)1 GHPoint (com.graphhopper.util.shapes.GHPoint)1 Entry (com.thinkaurelius.titan.diskstorage.Entry)1 SliceQuery (com.thinkaurelius.titan.diskstorage.keycolumnvalue.SliceQuery)1 StaticArrayEntry (com.thinkaurelius.titan.diskstorage.util.StaticArrayEntry)1 DirectionID (com.thinkaurelius.titan.graphdb.database.idhandling.IDHandler.DirectionID)1 DataOutput (com.thinkaurelius.titan.graphdb.database.serialize.DataOutput)1 EdgeDirection (com.thinkaurelius.titan.graphdb.relations.EdgeDirection)1 ImplicitKey (com.thinkaurelius.titan.graphdb.types.system.ImplicitKey)1 CacheVertex (com.thinkaurelius.titan.graphdb.vertices.CacheVertex)1 OLAPTest (com.thinkaurelius.titan.olap.OLAPTest)1 IOException (java.io.IOException)1 Nullable (javax.annotation.Nullable)1 XMLStreamException (javax.xml.stream.XMLStreamException)1 Direction (org.apache.tinkerpop.gremlin.structure.Direction)1 Edge (org.apache.tinkerpop.gremlin.structure.Edge)1 VertexProperty (org.apache.tinkerpop.gremlin.structure.VertexProperty)1