com.carrotsearch.hppc.LongObjectHashMap Java Examples

The following examples show how to use com.carrotsearch.hppc.LongObjectHashMap. 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: ExpandComponent.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
public GroupExpandCollector(SortedDocValues docValues, FixedBitSet groupBits, IntHashSet collapsedSet, int limit, Sort sort) throws IOException {
  int numGroups = collapsedSet.size();
  groups = new LongObjectHashMap<>(numGroups);
  DocIdSetIterator iterator = new BitSetIterator(groupBits, 0); // cost is not useful here
  int group;
  while ((group = iterator.nextDoc()) != DocIdSetIterator.NO_MORE_DOCS) {
    groups.put(group, getCollector(limit, sort));
  }

  this.collapsedSet = collapsedSet;
  this.groupBits = groupBits;
  this.docValues = docValues;
  if(docValues instanceof MultiDocValues.MultiSortedDocValues) {
    this.multiSortedDocValues = (MultiDocValues.MultiSortedDocValues)docValues;
    this.ordinalMap = multiSortedDocValues.mapping;
  }
}
 
Example #2
Source File: RelationCacheTest.java    From titan1withtp3.1 with Apache License 2.0 6 votes vote down vote up
@Test
public void testPerformance() {
    int trials = 10;
    int iterations = 100000;
    for (int k = 0; k < iterations; k++) {
        int len = random.nextInt(10);
        LongObjectHashMap<Object> map = new LongObjectHashMap<Object>();
        for (int i = 1; i <= len; i++) {
            map.put(i * 1000, "TestValue " + i);
        }
        for (int t = 0; t < trials; t++) {
            for (int i = 1; i <= len; i++) {
                assertEquals("TestValue " + i, map.get(i * 1000));
            }
            assertEquals(len, map.size());
            for (LongObjectCursor<Object> entry : map) {
            }
        }
    }
}
 
Example #3
Source File: ThreadsStatsCollector.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
private void addCpuTime() {
  long timestamp = System.nanoTime();
  LongObjectHashMap<Deque<Entry<Long,Long>>> newHolder = new LongObjectHashMap<>();
  for (long id : slicingThreadIds) {
    add(id, timestamp, mxBean.getThreadCpuTime(id), newHolder);
  }
  this.data = newHolder;
}
 
Example #4
Source File: ThreadsStatsCollector.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
private void addUserTime() {
  long timestamp = System.nanoTime();
  LongObjectHashMap<Deque<Entry<Long,Long>>> newHolder = new LongObjectHashMap<>();
  for (long id : slicingThreadIds) {
    add(id, timestamp, mxBean.getThreadUserTime(id), newHolder);
  }
  this.data = newHolder;
}
 
Example #5
Source File: ThreadsStatsCollector.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
public void add(long id, long ts, long value, LongObjectHashMap<Deque<Entry<Long, Long>>> newHolder) {
  Entry<Long,Long> entry = new SimpleEntry<>(ts, value);
  Deque<Entry<Long,Long>> list = this.data.get(id);
  if (list == null) {
    list = new ConcurrentLinkedDeque<>();
  }
  list.add(entry);
  while (ts - list.peekFirst().getKey() > RETAIN_INTERVAL) {
    list.removeFirst();
  }
  newHolder.put(id, list);
}
 
Example #6
Source File: ExpandComponent.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
public NumericGroupExpandCollector(String field, long nullValue, LongHashSet groupSet, IntHashSet collapsedSet, int limit, Sort sort) throws IOException {
  int numGroups = collapsedSet.size();
  this.nullValue = nullValue;
  groups = new LongObjectHashMap<>(numGroups);
  for (LongCursor cursor : groupSet) {
    groups.put(cursor.value, getCollector(limit, sort));
  }

  this.field = field;
  this.collapsedSet = collapsedSet;
}
 
Example #7
Source File: TestByteBuffer.java    From titan1withtp3.1 with Apache License 2.0 5 votes vote down vote up
private static long testByte() {
    LongObjectMap<ConcurrentSkipListSet<ByteEntry>> tx = new LongObjectHashMap<ConcurrentSkipListSet<ByteEntry>>(NUM);
    for (int i = 0; i < NUM; i++) {
        tx.put(i, new ConcurrentSkipListSet<ByteEntry>());
    }
    for (int i = 0; i < NUM; i++) {
        for (int j = 0; j < NUM; j++) {
            if (i == j) continue;
            if (Math.random() < FRACTION) {
                ByteBuffer key = ByteBuffer.allocate(16);
                key.putLong(5).putLong(j).flip();
                ByteBuffer value = ByteBuffer.allocate(4);
                value.putInt(random.nextInt(ROUNDSIZE)).flip();
                tx.get(i).add(new ByteEntry(key, value));
            }
        }
    }
    long time = System.currentTimeMillis();
    long sum = 0;
    for (int t = 0; t < TRIALS; t++) {
        for (int i = 0; i < NUM; i++) {
            for (Vertex v : (new ByteVertex(i, tx)).getNeighbors(0)) {
                sum += v.getId();
            }
        }
    }
    time = System.currentTimeMillis() - time;
    return time;
}
 
Example #8
Source File: EdgeSerializer.java    From titan1withtp3.1 with Apache License 2.0 5 votes vote down vote up
private void readInlineTypes(long[] keyIds, LongObjectHashMap properties, ReadBuffer in, TypeInspector tx, InlineType inlineType) {
    for (long keyId : keyIds) {
        PropertyKey keyType = tx.getExistingPropertyKey(keyId);
        Object value = readInline(in, keyType, inlineType);
        if (value != null) properties.put(keyId, value);
    }
}
 
Example #9
Source File: RelationCache.java    From titan1withtp3.1 with Apache License 2.0 5 votes vote down vote up
public RelationCache(final Direction direction, final long typeId, final long relationId,
                     final Object other, final LongObjectHashMap<Object> properties) {
    this.direction = direction;
    this.typeId = typeId;
    this.relationId = relationId;
    this.other = other;
    this.properties = (properties == null || properties.size() > 0) ? properties : EMPTY;
}
 
Example #10
Source File: QueryTreeNode.java    From spliceengine with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * For a given ResultColumnList, return a map from
 * [resultSetNumber, virtualColumnId] => ResultColumn
 * where there is one entry for each ResultColumn down the chain of reference to
 * its source column on a table. This allows translation from a column reference at
 * any node below into the ResultColumn projected from the passed ResultColumnList.
 */
public LongObjectHashMap<ResultColumn> rsnChainMap()
        throws StandardException {
    LongObjectHashMap<ResultColumn> chain = new LongObjectHashMap<>();
    List<ResultColumn> cols = RSUtils.collectNodes(this, ResultColumn.class);
    for (ResultColumn rc : cols) {
        long top = rc.getCoordinates();
        chain.put(top, rc);
        LongArrayList list = rc.chain();
        for (int i = 0; i< list.size(); i++) {
            chain.put(list.buffer[i],rc);
        }
    }
    return chain;
}
 
Example #11
Source File: LocalCheckpointTracker.java    From crate with Apache License 2.0 5 votes vote down vote up
private void markSeqNo(final long seqNo, final AtomicLong checkPoint, final LongObjectHashMap<CountedBitSet> bitSetMap) {
    assert Thread.holdsLock(this);
    // make sure we track highest seen sequence number
    advanceMaxSeqNo(seqNo);
    if (seqNo <= checkPoint.get()) {
        // this is possible during recovery where we might replay an operation that was also replicated
        return;
    }
    final CountedBitSet bitSet = getBitSetForSeqNo(bitSetMap, seqNo);
    final int offset = seqNoToBitSetOffset(seqNo);
    bitSet.set(offset);
    if (seqNo == checkPoint.get() + 1) {
        updateCheckpoint(checkPoint, bitSetMap);
    }
}
 
Example #12
Source File: LocalCheckpointTracker.java    From crate with Apache License 2.0 5 votes vote down vote up
/**
 * Moves the checkpoint to the last consecutively processed sequence number. This method assumes that the sequence number
 * following the current checkpoint is processed.
 */
@SuppressForbidden(reason = "Object#notifyAll")
private void updateCheckpoint(AtomicLong checkPoint, LongObjectHashMap<CountedBitSet> bitSetMap) {
    assert Thread.holdsLock(this);
    assert getBitSetForSeqNo(bitSetMap, checkPoint.get() + 1).get(seqNoToBitSetOffset(checkPoint.get() + 1)) :
        "updateCheckpoint is called but the bit following the checkpoint is not set";
    try {
        // keep it simple for now, get the checkpoint one by one; in the future we can optimize and read words
        long bitSetKey = getBitSetKey(checkPoint.get());
        CountedBitSet current = bitSetMap.get(bitSetKey);
        if (current == null) {
            // the bit set corresponding to the checkpoint has already been removed, set ourselves up for the next bit set
            assert checkPoint.get() % BIT_SET_SIZE == BIT_SET_SIZE - 1;
            current = bitSetMap.get(++bitSetKey);
        }
        do {
            checkPoint.incrementAndGet();
            /*
             * The checkpoint always falls in the current bit set or we have already cleaned it; if it falls on the last bit of the
             * current bit set, we can clean it.
             */
            if (checkPoint.get() == lastSeqNoInBitSet(bitSetKey)) {
                assert current != null;
                final CountedBitSet removed = bitSetMap.remove(bitSetKey);
                assert removed == current;
                current = bitSetMap.get(++bitSetKey);
            }
        } while (current != null && current.get(seqNoToBitSetOffset(checkPoint.get() + 1)));
    } finally {
        // notifies waiters in waitForProcessedOpsToComplete
        this.notifyAll();
    }
}
 
Example #13
Source File: LocalCheckpointTracker.java    From crate with Apache License 2.0 5 votes vote down vote up
private CountedBitSet getBitSetForSeqNo(final LongObjectHashMap<CountedBitSet> bitSetMap, final long seqNo) {
    assert Thread.holdsLock(this);
    final long bitSetKey = getBitSetKey(seqNo);
    final int index = bitSetMap.indexOf(bitSetKey);
    final CountedBitSet bitSet;
    if (bitSetMap.indexExists(index)) {
        bitSet = bitSetMap.indexGet(index);
    } else {
        bitSet = new CountedBitSet(BIT_SET_SIZE);
        bitSetMap.indexInsert(index, bitSetKey, bitSet);
    }
    return bitSet;
}
 
Example #14
Source File: ExpandComponent.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
public LongObjectHashMap<Collector> getGroups() {
  return groups;
}
 
Example #15
Source File: RelationCacheTest.java    From titan1withtp3.1 with Apache License 2.0 4 votes vote down vote up
@Test
public void testEmpty() {
    LongObjectHashMap<Object> map = new LongObjectHashMap<Object>();
    assertEquals(0, map.size());
    assertEquals(0, Iterables.size(map));
}