本文整理汇总了Java中org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils.reduce方法的典型用法代码示例。如果您正苦于以下问题:Java IteratorUtils.reduce方法的具体用法?Java IteratorUtils.reduce怎么用?Java IteratorUtils.reduce使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils
的用法示例。
在下文中一共展示了IteratorUtils.reduce方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: execute
import org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils; //导入方法依赖的package包/类
@Override
public void execute(final Vertex vertex, Messenger<Double> messenger, final Memory memory) {
if (memory.isInitialIteration()) {
messenger.sendMessage(this.countMessageScope, 1.0d);
} else if (1 == memory.getIteration()) {
double initialPageRank = (null == this.initialRankTraversal ?
1.0d :
TraversalUtil.apply(vertex, this.initialRankTraversal.get()).doubleValue()) / this.vertexCountAsDouble;
double edgeCount = IteratorUtils.reduce(messenger.receiveMessages(), 0.0d, (a, b) -> a + b);
vertex.property(VertexProperty.Cardinality.single, this.property, initialPageRank);
vertex.property(VertexProperty.Cardinality.single, EDGE_COUNT, edgeCount);
if (!this.terminate(memory)) // don't send messages if this is the last iteration
messenger.sendMessage(this.incidentMessageScope, initialPageRank / edgeCount);
} else {
double newPageRank = IteratorUtils.reduce(messenger.receiveMessages(), 0.0d, (a, b) -> a + b);
newPageRank = (this.alpha * newPageRank) + ((1.0d - this.alpha) / this.vertexCountAsDouble);
vertex.property(VertexProperty.Cardinality.single, this.property, newPageRank);
if (!this.terminate(memory)) // don't send messages if this is the last iteration
messenger.sendMessage(this.incidentMessageScope, newPageRank / vertex.<Double>value(EDGE_COUNT));
}
}
示例2: updateClusterLabel
import org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils; //导入方法依赖的package包/类
private static void updateClusterLabel(Vertex vertex, Messenger<String> messenger, Memory memory) {
String currentMax = vertex.value(CLUSTER_LABEL);
String max = IteratorUtils.reduce(messenger.receiveMessages(), currentMax,
(a, b) -> a.compareTo(b) > 0 ? a : b);
if (max.compareTo(currentMax) > 0) {
vertex.property(CLUSTER_LABEL, max);
messenger.sendMessage(messageScopeIn, max);
messenger.sendMessage(messageScopeOut, max);
memory.add(VOTE_TO_HALT, false);
}
}
示例3: reduceValues
import org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils; //导入方法依赖的package包/类
@Override
Number reduceValues(Iterator<Number> values) {
if (usingLong()) {
return IteratorUtils.reduce(values, Long.MAX_VALUE, (a, b) -> Math.min(a.longValue(), b.longValue()));
} else {
return IteratorUtils.reduce(values, Double.MAX_VALUE, (a, b) -> Math.min(a.doubleValue(), b.doubleValue()));
}
}
示例4: updateClusterLabel
import org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils; //导入方法依赖的package包/类
private static void updateClusterLabel(Vertex vertex, Messenger<String> messenger, Memory memory) {
String currentMax = vertex.value(CLUSTER_LABEL);
String max = IteratorUtils.reduce(messenger.receiveMessages(), currentMax,
(a, b) -> a.compareTo(b) > 0 ? a : b);
if (!max.equals(currentMax)) {
LOGGER.trace("Cluster label of " + vertex + " changed from " + currentMax + " to " + max);
vertex.property(CLUSTER_LABEL, max);
sendMessage(messenger, max);
memory.add(VOTE_TO_HALT, false);
} else {
LOGGER.trace("Cluster label of " + vertex + " is still " + currentMax);
}
}
示例5: relayClusterLabel
import org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils; //导入方法依赖的package包/类
private static void relayClusterLabel(Messenger<String> messenger, Memory memory) {
String firstMessage = messenger.receiveMessages().next();
String max = IteratorUtils.reduce(messenger.receiveMessages(), firstMessage,
(a, b) -> a.compareTo(b) > 0 ? a : b);
sendMessage(messenger, max);
memory.add(VOTE_TO_HALT, false);
}
示例6: reduceValues
import org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils; //导入方法依赖的package包/类
@Override
Map<String, Double> reduceValues(Iterator<Map<String, Double>> values) {
Map<String, Double> emptyTuple = new HashMap<>(2);
emptyTuple.put(SUM, 0D);
emptyTuple.put(COUNT, 0D);
return IteratorUtils.reduce(values, emptyTuple,
(a, b) -> {
a.put(COUNT, a.get(COUNT) + b.get(COUNT));
a.put(SUM, a.get(SUM) + b.get(SUM));
return a;
});
}
示例7: reduceValues
import org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils; //导入方法依赖的package包/类
@Override
Number reduceValues(Iterator<Number> values) {
if (usingLong()) {
return IteratorUtils.reduce(values, Long.MIN_VALUE, (a, b) -> Math.max(a.longValue(), b.longValue()));
} else {
return IteratorUtils.reduce(values, Double.MIN_VALUE, (a, b) -> Math.max(a.doubleValue(), b.doubleValue()));
}
}
示例8: reduceValues
import org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils; //导入方法依赖的package包/类
@Override
Map<String, Double> reduceValues(Iterator<Map<String, Double>> values) {
Map<String, Double> emptyTuple = new HashMap<>(3);
emptyTuple.put(SUM, 0D);
emptyTuple.put(SQUARE_SUM, 0D);
emptyTuple.put(COUNT, 0D);
return IteratorUtils.reduce(values, emptyTuple,
(a, b) -> {
a.put(COUNT, a.get(COUNT) + b.get(COUNT));
a.put(SUM, a.get(SUM) + b.get(SUM));
a.put(SQUARE_SUM, a.get(SQUARE_SUM) + b.get(SQUARE_SUM));
return a;
});
}
示例9: reduceValues
import org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils; //导入方法依赖的package包/类
@Override
Number reduceValues(Iterator<Number> values) {
if (usingLong()) {
return IteratorUtils.reduce(values, 0L, (a, b) -> a.longValue() + b.longValue());
} else {
return IteratorUtils.reduce(values, 0D, (a, b) -> a.doubleValue() + b.doubleValue());
}
}
示例10: getMessageCount
import org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils; //导入方法依赖的package包/类
static long getMessageCount(Messenger<Long> messenger) {
return IteratorUtils.reduce(messenger.receiveMessages(), 0L, (a, b) -> a + b);
}
示例11: reduceValues
import org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils; //导入方法依赖的package包/类
@Override
Long reduceValues(Iterator<Long> values) {
return IteratorUtils.reduce(values, 0L, (a, b) -> a + b);
}