Java Code Examples for com.carrotsearch.hppc.LongArrayList#add()

The following examples show how to use com.carrotsearch.hppc.LongArrayList#add() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SimpleVertexQueryProcessor.java    From titan1withtp3.1 with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the list of adjacent vertex ids for this query. By reading those ids
 * from the entries directly (without creating objects) we get much better performance.
 *
 * @return
 */
public VertexList vertexIds() {
    LongArrayList list = new LongArrayList();
    long previousId = 0;
    for (Long id : Iterables.transform(this,new Function<Entry, Long>() {
        @Nullable
        @Override
        public Long apply(@Nullable Entry entry) {
            return edgeSerializer.readRelation(entry,true,tx).getOtherVertexId();
        }
    })) {
        list.add(id);
        if (id>=previousId && previousId>=0) previousId=id;
        else previousId=-1;
    }
    return new VertexLongList(tx,list,previousId>=0);
}
 
Example 2
Source File: AbstractLongListUtil.java    From titan1withtp3.1 with Apache License 2.0 6 votes vote down vote up
public static LongArrayList mergeSort(LongArrayList a, LongArrayList b) {
    int posa=0, posb=0;
    LongArrayList result = new LongArrayList(a.size()+b.size());
    while (posa<a.size() || posb<b.size()) {
        long next;
        if (posa>=a.size()) {
            next=b.get(posb++);
        } else if (posb>=b.size()) {
            next=a.get(posa++);
        } else if (a.get(posa)<=b.get(posb)) {
            next=a.get(posa++);
        } else {
            next=b.get(posb++);
        }
        Preconditions.checkArgument(result.isEmpty() || result.get(result.size()-1)<=next,
                "The input lists are not sorted");
        result.add(next);
    }
    return result;
}
 
Example 3
Source File: SimpleTxnOperationFactory.java    From spliceengine with GNU Affero General Public License v3.0 6 votes vote down vote up
private byte[] encodeParentIds(TxnView txn,LongArrayList parentTxnIds){
    /*
     * For both active reads AND active writes, we only need to know the
     * parent's transaction ids, since we'll use the information immediately
     * available to determine other properties (additivity, etc.) Thus,
     * by doing this bit of logic, we can avoid a network call on the server
     * for every parent on the transaction chain, at the cost of 2-10 bytes
     * per parent on the chain--a cheap trade.
     */
    TxnView parent=txn.getParentTxnView();
    while(!Txn.ROOT_TRANSACTION.equals(parent)){
        parentTxnIds.add(parent.getTxnId());
        parent=parent.getParentTxnView();
    }
    int parentSize=parentTxnIds.size();
    long[] parentIds=parentTxnIds.buffer;
    MultiFieldEncoder parents=MultiFieldEncoder.create(parentSize);
    for(int i=1;i<=parentSize;i++){
        parents.encodeNext(parentIds[parentSize-i]);
    }
    return parents.build();
}
 
Example 4
Source File: TestingTxnStore.java    From spliceengine with GNU Affero General Public License v3.0 6 votes vote down vote up
private long[] findActiveTransactions(long minTimestamp,long maxId,byte[] table){
    LongArrayList activeTxns=new LongArrayList(txnMap.size());
    for(Map.Entry<Long, TxnHolder> txnEntry : txnMap.entrySet()){
        if(isTimedOut(txnEntry.getValue())) continue;
        Txn value=txnEntry.getValue().txn;
        if(value.getEffectiveState()==Txn.State.ACTIVE && value.getTxnId()<=maxId && value.getTxnId()>=minTimestamp){
            Iterator<ByteSlice> destinationTables=value.getDestinationTables();
            while(destinationTables.hasNext()){
                ByteSlice data=destinationTables.next();
                if(data.equals(table,0,table.length))
                    activeTxns.add(txnEntry.getKey());
            }
        }
    }
    return activeTxns.toArray();
}
 
Example 5
Source File: ActiveTransactionTest.java    From spliceengine with GNU Affero General Public License v3.0 6 votes vote down vote up
@Test
public void oldestActiveTransactionIgnoresCommitTimestampIds() throws IOException{
    final Txn t0=control.beginTransaction(DESTINATION_TABLE);
    transactorSetup.timestampSource.rememberTimestamp(t0.getTxnId());
    LongArrayList committedTxns=new LongArrayList();
    for(int i=0;i<4;i++){
        final Txn transactionId=control.beginTransaction(DESTINATION_TABLE);
        transactionId.commit();
        committedTxns.add(transactionId.getTxnId());
    }

    final Txn t1=control.beginTransaction(DESTINATION_TABLE);
    final long[] ids=txnStore.getActiveTransactionIds(t1,DESTINATION_TABLE);
    Assert.assertEquals(2,ids.length);
    Arrays.sort(ids);
    Assert.assertEquals(t0.getTxnId(),ids[0]);
    Assert.assertEquals(t1.getTxnId(),ids[1]);
    //this transaction should still be missing
}
 
Example 6
Source File: ExhaustiveLongEncodingTest.java    From spliceengine with GNU Affero General Public License v3.0 6 votes vote down vote up
@DataPoints public static long[] powersOf2(){
    LongArrayList dataPoints = new LongArrayList(100);
    long l = 1l;
    while(l>0){
        dataPoints.add(l);
        dataPoints.add(-l);
        dataPoints.add(3*l);
        dataPoints.add(-3*l);
        dataPoints.add(5*l);
        dataPoints.add(-5*l);
        dataPoints.add(7*l);
        dataPoints.add(-7*l);
        l<<=1;
    }

    return dataPoints.toArray();
}
 
Example 7
Source File: MemTxnStore.java    From spliceengine with GNU Affero General Public License v3.0 6 votes vote down vote up
private long[] findActiveTransactions(long minTimestamp,long maxId,byte[] table){
    LongArrayList activeTxns=new LongArrayList(txnMap.size());
    for(Map.Entry<Long, TxnHolder> txnEntry : txnMap.entrySet()){
        if(isTimedOut(txnEntry.getValue())) continue;
        Txn value=txnEntry.getValue().txn;
        if(value.getEffectiveState()==Txn.State.ACTIVE && value.getTxnId()<=maxId && value.getTxnId()>=minTimestamp){
            Iterator<ByteSlice> destinationTables=value.getDestinationTables();
            while(destinationTables.hasNext()){
                ByteSlice data=destinationTables.next();
                if(data.equals(table,0,table.length))
                    activeTxns.add(txnEntry.getKey());
            }
        }
    }
    return activeTxns.toArray();
}
 
Example 8
Source File: VertexArrayList.java    From titan1withtp3.1 with Apache License 2.0 5 votes vote down vote up
/**
 * Utility method used to convert the list of vertices into a list of vertex ids (assuming all vertices have ids)
 *
 * @param vertices
 * @return
 */
private static final LongArrayList toLongList(List<TitanVertex> vertices) {
    LongArrayList result = new LongArrayList(vertices.size());
    for (TitanVertex n : vertices) {
        result.add(n.longId());
    }
    return result;
}
 
Example 9
Source File: TestingTxnStore.java    From spliceengine with GNU Affero General Public License v3.0 5 votes vote down vote up
private long[] getAllActiveTransactions(long minTimestamp,long maxId) throws IOException{

        LongArrayList activeTxns=new LongArrayList(txnMap.size());
        for(Map.Entry<Long, TxnHolder> txnEntry : txnMap.entrySet()){
            if(isTimedOut(txnEntry.getValue())) continue;
            Txn value=txnEntry.getValue().txn;
            if(value.getEffectiveState()==Txn.State.ACTIVE
                    && value.getTxnId()<=maxId
                    && value.getTxnId()>=minTimestamp)
                activeTxns.add(txnEntry.getKey());
        }
        return activeTxns.toArray();
    }
 
Example 10
Source File: ActiveTransactionTest.java    From spliceengine with GNU Affero General Public License v3.0 5 votes vote down vote up
@Test
    @Ignore("This is subject to contamination failures when other tests are running concurrently")
    public void oldestActiveTransactionsManyActive() throws IOException{
        LongArrayList startedTxns=new LongArrayList();
        final Txn t0=control.beginTransaction(DESTINATION_TABLE);
        startedTxns.add(t0.getTxnId());
        transactorSetup.timestampSource.rememberTimestamp(t0.getTxnId());
//        long[] startIds = txnStore.getActiveTransactionIds(t0,DESTINATION_TABLE);
//        for(long sId:startIds){
//            startedTxns.add(sId);
//        }
        for(int i=0;i<4;i++){
            Txn transactionId=control.beginTransaction(DESTINATION_TABLE);
            startedTxns.add(transactionId.getTxnId());
        }
        final Txn t1=control.beginTransaction(DESTINATION_TABLE);
        startedTxns.add(t1.getTxnId());
        final long[] ids=txnStore.getActiveTransactionIds(t0.getTxnId(),t1.getTxnId(),DESTINATION_TABLE);
        System.out.println(startedTxns.toString());
        System.out.println(Arrays.toString(ids));

        Assert.assertEquals(startedTxns.size(),ids.length);
        Arrays.sort(ids);
        Assert.assertArrayEquals(startedTxns.toArray(),ids);
//        Assert.assertEquals(t0.getTxnId(), ids[0]);
//        Assert.assertEquals(t1.getTxnId(), result.get(ids.length - 1).getId());
    }
 
Example 11
Source File: RegionTxnStore.java    From spliceengine with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public long[] getActiveTxnIds(long afterTs,long beforeTs,byte[] destinationTable) throws IOException{
    if(LOG.isTraceEnabled())
        SpliceLogUtils.trace(LOG,"getActiveTxnIds beforeTs=%d, afterTs=%s, destinationTable=%s",beforeTs,afterTs,destinationTable);

    LongArrayList lal = new LongArrayList();
    try (Source<TxnMessage.Txn> activeTxn = getActiveTxns(afterTs, beforeTs, destinationTable)) {
        while (activeTxn.hasNext()) {
            TxnMessage.Txn next = activeTxn.next();
            TxnMessage.TxnInfo info = next.getInfo();
            lal.add(info.getTxnId());
        }
    }
    return lal.toArray();
}
 
Example 12
Source File: ExhaustiveLongEncodingTest.java    From spliceengine with GNU Affero General Public License v3.0 5 votes vote down vote up
@DataPoints public static long[] powersOf7(){
    LongArrayList dataPoints = new LongArrayList(100);
    long l = 1l;
    while(l>0){
        dataPoints.add(l);
        dataPoints.add(-l);
        l*=7;
    }

    return dataPoints.toArray();
}
 
Example 13
Source File: MemTxnStore.java    From spliceengine with GNU Affero General Public License v3.0 5 votes vote down vote up
private long[] getAllActiveTransactions(long minTimestamp,long maxId) throws IOException{

        LongArrayList activeTxns=new LongArrayList(txnMap.size());
        for(Map.Entry<Long, TxnHolder> txnEntry : txnMap.entrySet()){
            if(isTimedOut(txnEntry.getValue())) continue;
            Txn value=txnEntry.getValue().txn;
            if(value.getEffectiveState()==Txn.State.ACTIVE
                    && value.getTxnId()<=maxId
                    && value.getTxnId()>=minTimestamp)
                activeTxns.add(txnEntry.getKey());
        }
        return activeTxns.toArray();
    }
 
Example 14
Source File: AbstractLongListUtil.java    From titan1withtp3.1 with Apache License 2.0 4 votes vote down vote up
public static LongArrayList singleton(long el) {
    LongArrayList l = new LongArrayList(1);
    l.add(el);
    return l;
}