Program Listing for File NeighborsMeasureIndex.hpp

Return to documentation for file (include/networkit/linkprediction/NeighborsMeasureIndex.hpp)

/*
 * NeighborsMeasureIndex.hpp
 *
 *  Created on: 05.04.2015
 *      Author: Kolja Esders
 */

#ifndef NETWORKIT_LINKPREDICTION_NEIGHBORS_MEASURE_INDEX_HPP_
#define NETWORKIT_LINKPREDICTION_NEIGHBORS_MEASURE_INDEX_HPP_

#include <networkit/linkprediction/LinkPredictor.hpp>

namespace NetworKit {

class NeighborsMeasureIndex final : public LinkPredictor {
    double runImpl(node u, node v) override {
        double neighborConnections = 0;
        G->forNeighborsOf(u, [&](node uNeighbor) {
            G->forNeighborsOf(v, [&](node vNeighbor) {
                // Don't count self-loops
                if (uNeighbor == vNeighbor || G->hasEdge(uNeighbor, vNeighbor)) {
                    ++neighborConnections;
                }
            });
        });
        return neighborConnections;
    }

public:
    using LinkPredictor::LinkPredictor;
};

} // namespace NetworKit

#endif // NETWORKIT_LINKPREDICTION_NEIGHBORS_MEASURE_INDEX_HPP_