本文整理了Java中com.clearspring.analytics.stream.quantile.QDigest.get
方法的一些代码示例,展示了QDigest.get
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。QDigest.get
方法的具体详情如下:
包路径:com.clearspring.analytics.stream.quantile.QDigest
类名称:QDigest
方法名:get
暂无
代码示例来源:origin: addthis/stream-lib
/**
* Restore P2 at node and upward the spine. Note that P2 can vanish
* at some nodes sideways as a result of this. We'll fix that later
* in compressFully when needed.
*/
private void compressUpward(long node) {
double threshold = Math.floor(size / compressionFactor);
long atNode = get(node);
while (!isRoot(node)) {
if (atNode > threshold) {
break;
}
long atSibling = get(sibling(node));
if (atNode + atSibling > threshold) {
break;
}
long atParent = get(parent(node));
if (atNode + atSibling + atParent > threshold) {
break;
}
node2count.addTo(parent(node), atNode + atSibling);
node2count.remove(node);
if (atSibling > 0) {
node2count.remove(sibling(node));
}
node = parent(node);
atNode = atParent + atNode + atSibling;
}
}
代码示例来源:origin: addthis/stream-lib
public static QDigest unionOf(QDigest a, QDigest b) {
if (a.compressionFactor != b.compressionFactor) {
throw new IllegalArgumentException(
"Compression factors must be the same: " +
"left is " + a.compressionFactor + ", " +
"right is " + b.compressionFactor);
}
if (a.capacity > b.capacity) {
return unionOf(b, a);
}
QDigest res = new QDigest(a.compressionFactor);
res.capacity = a.capacity;
res.size = a.size + b.size;
for (long k : a.node2count.keySet()) {
res.node2count.put(k, a.node2count.get(k));
}
if (b.capacity > res.capacity) {
res.rebuildToCapacity(b.capacity);
}
for (long k : b.node2count.keySet()) {
res.node2count.put(k, b.get(k) + res.get(k));
}
res.compressFully();
return res;
}
代码示例来源:origin: addthis/stream-lib
/**
* Restore P2 at seedNode and guarantee that no new violations of P2 appeared.
*/
private void compressDownward(long seedNode) {
double threshold = Math.floor(size / compressionFactor);
// P2 check same as above but shorter and slower (and invoked rarely)
LongArrayFIFOQueue q = new LongArrayFIFOQueue();
q.enqueue(seedNode);
while (!q.isEmpty()) {
long node = q.dequeueLong();
long atNode = get(node);
long atSibling = get(sibling(node));
if (atNode == 0 && atSibling == 0) {
continue;
}
long atParent = get(parent(node));
if (atParent + atNode + atSibling > threshold) {
continue;
}
node2count.addTo(parent(node), atNode + atSibling);
node2count.remove(node);
node2count.remove(sibling(node));
// Now P2 could have vanished at the node's and sibling's subtrees since they decreased.
if (!isLeaf(node)) {
q.enqueue(leftChild(node));
q.enqueue(leftChild(sibling(node)));
}
}
}
代码示例来源:origin: com.addthis/stream-lib
/**
* Restore P2 at node and upward the spine. Note that P2 can vanish
* at some nodes sideways as a result of this. We'll fix that later
* in compressFully when needed.
*/
private void compressUpward(long node) {
double threshold = Math.floor(size / compressionFactor);
long atNode = get(node);
while (!isRoot(node)) {
if (atNode > threshold) {
break;
}
long atSibling = get(sibling(node));
if (atNode + atSibling > threshold) {
break;
}
long atParent = get(parent(node));
if (atNode + atSibling + atParent > threshold) {
break;
}
node2count.addTo(parent(node), atNode + atSibling);
node2count.remove(node);
if (atSibling > 0) {
node2count.remove(sibling(node));
}
node = parent(node);
atNode = atParent + atNode + atSibling;
}
}
代码示例来源:origin: com.addthis/stream-lib
public static QDigest unionOf(QDigest a, QDigest b) {
if (a.compressionFactor != b.compressionFactor) {
throw new IllegalArgumentException(
"Compression factors must be the same: " +
"left is " + a.compressionFactor + ", " +
"right is " + b.compressionFactor);
}
if (a.capacity > b.capacity) {
return unionOf(b, a);
}
QDigest res = new QDigest(a.compressionFactor);
res.capacity = a.capacity;
res.size = a.size + b.size;
for (long k : a.node2count.keySet()) {
res.node2count.put(k, a.node2count.get(k));
}
if (b.capacity > res.capacity) {
res.rebuildToCapacity(b.capacity);
}
for (long k : b.node2count.keySet()) {
res.node2count.put(k, b.get(k) + res.get(k));
}
res.compressFully();
return res;
}
代码示例来源:origin: com.addthis/stream-lib
/**
* Restore P2 at seedNode and guarantee that no new violations of P2 appeared.
*/
private void compressDownward(long seedNode) {
double threshold = Math.floor(size / compressionFactor);
// P2 check same as above but shorter and slower (and invoked rarely)
LongArrayFIFOQueue q = new LongArrayFIFOQueue();
q.enqueue(seedNode);
while (!q.isEmpty()) {
long node = q.dequeueLong();
long atNode = get(node);
long atSibling = get(sibling(node));
if (atNode == 0 && atSibling == 0) {
continue;
}
long atParent = get(parent(node));
if (atParent + atNode + atSibling > threshold) {
continue;
}
node2count.addTo(parent(node), atNode + atSibling);
node2count.remove(node);
node2count.remove(sibling(node));
// Now P2 could have vanished at the node's and sibling's subtrees since they decreased.
if (!isLeaf(node)) {
q.enqueue(leftChild(node));
q.enqueue(leftChild(sibling(node)));
}
}
}
内容来源于网络,如有侵权,请联系作者删除!