io.netty.util.collection.LongObjectHashMap Java Examples

The following examples show how to use io.netty.util.collection.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: GroupByMaps.java    From crate with Apache License 2.0 6 votes vote down vote up
public static <K, V> Supplier<Map<K, V>> mapForType(DataType<K> type) {
    switch (type.id()) {
        case ByteType.ID:
            return () -> (Map) new PrimitiveMapWithNulls<>(new ByteObjectHashMap<>());
        case ShortType.ID:
            return () -> (Map) new PrimitiveMapWithNulls<>(new ShortObjectHashMap<>());
        case IntegerType.ID:
            return () -> (Map) new PrimitiveMapWithNulls<>(new IntObjectHashMap<>());

        case LongType.ID:
        case TimestampType.ID_WITH_TZ:
        case TimestampType.ID_WITHOUT_TZ:
            return () -> (Map) new PrimitiveMapWithNulls<>(new LongObjectHashMap<>());

        default:
            return HashMap::new;
    }
}
 
Example #2
Source File: GroupingLongCollectorBenchmark.java    From crate with Apache License 2.0 6 votes vote down vote up
@Benchmark
public LongObjectHashMap<Long> measureGroupingOnNumericDocValues() throws Exception {
    Weight weight = searcher.createWeight(new MatchAllDocsQuery(), ScoreMode.COMPLETE_NO_SCORES, 1.0f);
    LeafReaderContext leaf = searcher.getTopReaderContext().leaves().get(0);
    Scorer scorer = weight.scorer(leaf);
    NumericDocValues docValues = DocValues.getNumeric(leaf.reader(), "x");
    DocIdSetIterator docIt = scorer.iterator();
    LongObjectHashMap<Long> sumByKey = new LongObjectHashMap<>();
    for (int docId = docIt.nextDoc(); docId != DocIdSetIterator.NO_MORE_DOCS; docId = docIt.nextDoc()) {
        if (docValues.advanceExact(docId)) {
            long number = docValues.longValue();
            sumByKey.compute(number, (key, oldValue) -> {
                if (oldValue == null) {
                    return number;
                } else {
                    return oldValue + number;
                }
            });
        }
    }
    return sumByKey;
}
 
Example #3
Source File: GroupingLongCollectorBenchmark.java    From crate with Apache License 2.0 6 votes vote down vote up
@Benchmark
public LongObjectHashMap<Long> measureGroupingOnSortedNumericDocValues() throws Exception {
    var weight = searcher.createWeight(new MatchAllDocsQuery(), ScoreMode.COMPLETE_NO_SCORES, 1.0f);
    var leaf = searcher.getTopReaderContext().leaves().get(0);
    var scorer = weight.scorer(leaf);
    var docValues = DocValues.getSortedNumeric(leaf.reader(), "y");
    var docIt = scorer.iterator();
    LongObjectHashMap<Long> sumByKey = new LongObjectHashMap<>();
    for (int docId = docIt.nextDoc(); docId != DocIdSetIterator.NO_MORE_DOCS; docId = docIt.nextDoc()) {
        if (docValues.advanceExact(docId)) {
            if (docValues.docValueCount() == 1) {
                long number = docValues.nextValue();
                sumByKey.compute(number, (key, oldValue) -> {
                    if (oldValue == null) {
                        return number;
                    } else {
                        return oldValue + number;
                    }
                });
            }
        }
    }
    return sumByKey;
}
 
Example #4
Source File: PageCursorProviderImpl.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
public PageCursorProviderImpl(final PagingStore pagingStore,
                              final StorageManager storageManager,
                              final ArtemisExecutor executor,
                              final int maxCacheSize,
                              final boolean readWholePage) {
   this.pagingStore = pagingStore;
   this.storageManager = storageManager;
   this.executor = executor;
   this.softCache = new SoftValueLongObjectHashMap<>(maxCacheSize);
   if (!readWholePage) {
      this.numberOfMessages = new LongObjectHashMap<>();
   }
   this.inProgressReadPages = new LongObjectHashMap<>();
}
 
Example #5
Source File: GroupingLongCollectorBenchmark.java    From crate with Apache License 2.0 5 votes vote down vote up
/**
 * To establish a base line on how fast it could go
 */
@Benchmark
public LongObjectHashMap<Long> measureGroupingOnLongArray() {
    LongObjectHashMap<Long> sumByKey = new LongObjectHashMap<>();
    for (long number : numbers) {
        sumByKey.compute(number, (key, oldValue) -> {
            if (oldValue == null) {
                return number;
            } else {
                return oldValue + number;
            }
        });
    }
    return sumByKey;
}