// Path: src/main/java/com/maxdemarzi/processing/NodeCounter.java
// public class NodeCounter {
//     public int getNodeCount(GraphDatabaseService db) {
//         Result result = db.execute( "MATCH (n) RETURN max(id(n)) AS maxId" );
//         return ((Number) result.next().get( "maxId" )).intValue() + 1;
// 
//     }
//     public int getRelationshipCount(GraphDatabaseService db) {
//         Result result = db.execute( "MATCH ()-[r]->() RETURN max(id(r)) AS maxId" );
//         return ((Number) result.next().get( "maxId" )).intValue() + 1;
//     }
// }


import com.maxdemarzi.processing.NodeCounter;
import it.unimi.dsi.fastutil.longs.Long2DoubleOpenHashMap;
import org.neo4j.graphdb.*;
package com.maxdemarzi.processing.labelpropagation;


public class LabelPropagationMapStorage implements LabelPropagation {
    private final GraphDatabaseService db;
    private final long nodes;
    private Long2DoubleOpenHashMap labelMap;

    public LabelPropagationMapStorage(GraphDatabaseService db) {
        this.db = db;
        this.nodes = new NodeCounter().getNodeCount(db);
    }

    @Override
    public void compute(String label, String type, int iterations) {
        RelationshipType relationshipType = RelationshipType.withName(type);
        labelMap = new Long2DoubleOpenHashMap();
        boolean done = false;
        int iteration = 0;
        try ( Transaction tx = db.beginTx()) {
            ResourceIterator<Node> nodes = db.findNodes(DynamicLabel.label(label));
            while (nodes.hasNext()) {
                Node node = nodes.next();
                labelMap.put(node.getId(), node.getId());
            }

            while (!done) {
                done = true;
                iteration++;

                for( Relationship relationship : db.getAllRelationships()) {
                    if (relationship.isType(relationshipType)) {
                        long x = relationship.getStartNode().getId();
// Path: src/main/java/com/maxdemarzi/processing/NodeCounter.java
// public class NodeCounter {
//     public int getNodeCount(GraphDatabaseService db) {
//         Result result = db.execute( "MATCH (n) RETURN max(id(n)) AS maxId" );
//         return ((Number) result.next().get( "maxId" )).intValue() + 1;
// 
//     }
//     public int getRelationshipCount(GraphDatabaseService db) {
//         Result result = db.execute( "MATCH ()-[r]->() RETURN max(id(r)) AS maxId" );
//         return ((Number) result.next().get( "maxId" )).intValue() + 1;
//     }
// }


// Path: src/main/java/com/maxdemarzi/processing/labelpropagation/LabelPropagationMapStorage.java
import com.maxdemarzi.processing.NodeCounter;
import it.unimi.dsi.fastutil.longs.Long2DoubleOpenHashMap;
import org.neo4j.graphdb.*;

package com.maxdemarzi.processing.labelpropagation;


public class LabelPropagationMapStorage implements LabelPropagation {
    private final GraphDatabaseService db;
    private final long nodes;
    private Long2DoubleOpenHashMap labelMap;

    public LabelPropagationMapStorage(GraphDatabaseService db) {
        this.db = db;
        this.nodes = new NodeCounter().getNodeCount(db);
    }

    @Override
    public void compute(String label, String type, int iterations) {
        RelationshipType relationshipType = RelationshipType.withName(type);
        labelMap = new Long2DoubleOpenHashMap();
        boolean done = false;
        int iteration = 0;
        try ( Transaction tx = db.beginTx()) {
            ResourceIterator<Node> nodes = db.findNodes(DynamicLabel.label(label));
            while (nodes.hasNext()) {
                Node node = nodes.next();
                labelMap.put(node.getId(), node.getId());
            }

            while (!done) {
                done = true;
                iteration++;

                for( Relationship relationship : db.getAllRelationships()) {
                    if (relationship.isType(relationshipType)) {
                        long x = relationship.getStartNode().getId();
                        long y = relationship.getEndNode().getId();