use of it.unimi.dsi.fastutil.longs.Long2LongOpenHashMap in project stream-lib by addthis.
the class QDigest method rebuildToCapacity.
private void rebuildToCapacity(long newCapacity) {
Long2LongOpenHashMap newNode2count = new Long2LongOpenHashMap(MAP_INITIAL_SIZE, MAP_LOAD_FACTOR);
// rebuild to newLogCapacity.
// This means that our current tree becomes a leftmost subtree
// of the new tree.
// E.g. when rebuilding a tree with logCapacity = 2
// (i.e. storing values in 0..3) to logCapacity = 5 (i.e. 0..31):
// node 1 => 8 (+= 7 = 2^0*(2^3-1))
// nodes 2..3 => 16..17 (+= 14 = 2^1*(2^3-1))
// nodes 4..7 => 32..35 (+= 28 = 2^2*(2^3-1))
// This is easy to see if you draw it on paper.
// Process the keys by "layers" in the original tree.
long scaleR = newCapacity / capacity - 1;
Long[] keys = node2count.keySet().toArray(new Long[node2count.size()]);
Arrays.sort(keys);
long scaleL = 1;
for (long k : keys) {
while (scaleL <= k / 2) {
scaleL <<= 1;
}
newNode2count.put(k + scaleL * scaleR, node2count.get(k));
}
node2count = newNode2count;
capacity = newCapacity;
compressFully();
}
use of it.unimi.dsi.fastutil.longs.Long2LongOpenHashMap in project druid by druid-io.
the class AllocationMetricCollector method calculateDelta.
/**
* Uses getThreadAllocatedBytes internally {@link com.sun.management.ThreadMXBean#getThreadAllocatedBytes}.
*
* Tests show the call to getThreadAllocatedBytes for a single thread ID out of 500 threads running takes around
* 9000 ns (in the worst case), which for 500 IDs should take 500*9000/1000/1000 = 4.5 ms to the max.
* AllocationMetricCollector takes linear time to calculate delta, for 500 threads it's negligible.
* See the default emitting period {@link MonitorSchedulerConfig#getEmitterPeriod}.
*
* @return all threads summed allocated bytes delta
*/
long calculateDelta() {
try {
long[] allThreadIds = threadMXBean.getAllThreadIds();
// the call time depends on number of threads, for 500 threads the estimated time is 4 ms
long[] bytes = (long[]) getThreadAllocatedBytes.invoke(threadMXBean, (Object) allThreadIds);
long sum = 0;
Long2LongMap newResults = new Long2LongOpenHashMap();
newResults.defaultReturnValue(NO_DATA);
for (int i = 0; i < allThreadIds.length; i++) {
long threadId = allThreadIds[i];
long previous = previousResults.get(threadId);
long current = bytes[i];
newResults.put(threadId, current);
// before
if (previous == NO_DATA || previous > current) {
sum += current;
} else {
sum += current - previous;
}
}
previousResults = newResults;
return sum;
} catch (ReflectiveOperationException e) {
// it doesn't make sense after initialization is complete
log.error(e, "Cannot calculate delta");
}
return 0;
}
use of it.unimi.dsi.fastutil.longs.Long2LongOpenHashMap in project angel by Tencent.
the class PathQueue method pushBatch.
public static void pushBatch(int psPartId, ServerLongAnyRow row, Long2LongOpenHashMap pathTail) {
ReentrantLock queueLock = psPartId2Lock.get(psPartId);
int completeCount = 0;
queueLock.lock();
try {
Queue<WalkPath> queue = psPartId2Queue.get(psPartId);
for (Map.Entry<Long, Long> entry : pathTail.entrySet()) {
long key = entry.getKey();
long tail = entry.getValue();
WalkPath wPath = (WalkPath) row.get(key);
wPath.add2Path(tail);
if (wPath.isComplete()) {
completeCount += 1;
} else {
queue.add(wPath);
}
}
progress.put(psPartId, progress.get(psPartId) + completeCount);
} finally {
queueLock.unlock();
}
}
use of it.unimi.dsi.fastutil.longs.Long2LongOpenHashMap in project angel by Tencent.
the class GetNumNeighborEdgesFunc method merge.
@Override
public GetResult merge(List<PartitionGetResult> partResults) {
Int2ObjectArrayMap<PartitionGetResult> partIdToResultMap = new Int2ObjectArrayMap<>(partResults.size());
for (PartitionGetResult result : partResults) {
partIdToResultMap.put(((PartGetNumNeighborEdgesResult) result).getPartId(), result);
}
GetNumNeighborEdgesParam param = (GetNumNeighborEdgesParam) getParam();
long[] nodeIds = param.getNodeIds();
List<PartitionGetParam> partParams = param.getPartParams();
Long2LongOpenHashMap nodeIdToNumEdges = new Long2LongOpenHashMap(nodeIds.length);
for (PartitionGetParam partParam : partParams) {
int start = ((PartGetNumNeighborEdgesParam) partParam).getStartIndex();
int end = ((PartGetNumNeighborEdgesParam) partParam).getEndIndex();
PartGetNumNeighborEdgesResult partResult = (PartGetNumNeighborEdgesResult) (partIdToResultMap.get(partParam.getPartKey().getPartitionId()));
long[] results = partResult.getNodeIdToNumEdges();
for (int i = start; i < end; i++) {
nodeIdToNumEdges.put(nodeIds[i], results[i - start]);
}
}
return new GetNumNeighborEdgesResult(nodeIdToNumEdges);
}
use of it.unimi.dsi.fastutil.longs.Long2LongOpenHashMap in project angel by Tencent.
the class PartInitNumNeighborEdgesParam method deserialize.
@Override
public void deserialize(ByteBuf buf) {
super.deserialize(buf);
int len = buf.readInt();
nodeIdToNumEdges = new Long2LongOpenHashMap(len);
for (int i = 0; i < len; i++) {
long nodeId = buf.readLong();
long numEdges = buf.readLong();
nodeIdToNumEdges.put(nodeId, numEdges);
}
}
Aggregations