下面列出了怎么用io.netty.util.collection.LongObjectHashMap的API类实例代码及写法,或者点击链接到github查看源代码。
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;
}
}
@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;
}
@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;
}
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<>();
}
/**
* 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;
}