当前位置: 首页>>代码示例>>Java>>正文


Java IteratorUtils.reduce方法代码示例

本文整理汇总了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));
    }
}
 
开发者ID:PKUSilvester,项目名称:LiteGraph,代码行数:22,代码来源:PageRankVertexProgram.java

示例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);
    }
}
 
开发者ID:graknlabs,项目名称:grakn,代码行数:12,代码来源:ConnectedComponentsVertexProgram.java

示例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()));
    }
}
 
开发者ID:graknlabs,项目名称:grakn,代码行数:9,代码来源:MinMapReduce.java

示例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);
    }
}
 
开发者ID:graknlabs,项目名称:grakn,代码行数:14,代码来源:KCoreVertexProgram.java

示例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);
}
 
开发者ID:graknlabs,项目名称:grakn,代码行数:8,代码来源:KCoreVertexProgram.java

示例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;
            });
}
 
开发者ID:graknlabs,项目名称:grakn,代码行数:13,代码来源:MeanMapReduce.java

示例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()));
    }
}
 
开发者ID:graknlabs,项目名称:grakn,代码行数:9,代码来源:MaxMapReduce.java

示例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;
            });
}
 
开发者ID:graknlabs,项目名称:grakn,代码行数:15,代码来源:StdMapReduce.java

示例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());
    }
}
 
开发者ID:graknlabs,项目名称:grakn,代码行数:9,代码来源:SumMapReduce.java

示例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);
}
 
开发者ID:graknlabs,项目名称:grakn,代码行数:4,代码来源:GraknVertexProgram.java

示例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);
}
 
开发者ID:graknlabs,项目名称:grakn,代码行数:5,代码来源:CountMapReduce.java


注:本文中的org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils.reduce方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。