src/main/java/thinkd/ThinkDAcc.java
/**
     * counts triangles with the given edge and update estimates
     * @param src the source node of the given edge
     * @param dst the destination node of the given edge
     * @param add true for addition and false for deletion
     */
counts triangles with the given edge and update estimates
@param src the source node of the given edge
@param dst the destination node of the given edge
@param add true for addition and false for deletion
counts triangles with the given edge and update estimates @param src the source node of the given edge @param dst the destination node of the given edge @param add true for addition and false for deletion
private void count(int src, int dst, boolean add) {
        if(!srcToDsts.containsKey(src) || !srcToDsts.containsKey(dst)) {
            return;
        }
        IntOpenHashSet srcSet = srcToDsts.get(src);
        IntOpenHashSet dstSet = srcToDsts.get(dst);
        if(srcSet.size() > dstSet.size()) {
            IntOpenHashSet temp = srcSet;
            srcSet = dstSet;
            dstSet = temp;
        }
        final double weight = Math.max((s + nb + ng + 0.0) / k * (s + nb + ng - 1.0) / (k - 1.0), 1);
        if(add) { 
            double count = 0;
            for (int neighbor : srcSet) {
                if (dstSet.contains(neighbor)) {
                    count += 1;
                    nodeToTriangles.addTo(neighbor, weight);
                }
            }
            if (count > 0) {
                double weightSum = count * weight;
                nodeToTriangles.addTo(src, weightSum);
                nodeToTriangles.addTo(dst, weightSum);
                globalTriangle += weightSum;
            }
        }
        else if(lowerBound){ 
            double count = 0;
            for (int neighbor : srcSet) {
                if (dstSet.contains(neighbor)) {
                    count += 1;
                    double value = nodeToTriangles.addTo(neighbor, - weight);
                    if(value < weight) {
                        nodeToTriangles.put(neighbor, 0); 
                    }
                }
            }
            if (count > 0) {
                final double weightSum = count * weight;
                double value = nodeToTriangles.addTo(src, - weightSum);
                if(value < weightSum) {
                    nodeToTriangles.put(src, 0); 
                }
                value = nodeToTriangles.addTo(dst, - weightSum);
                if(value < weightSum) {
                    nodeToTriangles.put(dst, 0); 
                }
                globalTriangle -= weightSum;
                globalTriangle = Math.max(0, globalTriangle); 
            }
        }
        else { 
            double count = 0;
            for (int neighbor : srcSet) {
                if (dstSet.contains(neighbor)) {
                    count += 1;
                    nodeToTriangles.addTo(neighbor, - weight);
                }
            }
            if (count > 0) {
                double weightSum = count * weight;
                nodeToTriangles.addTo(src, - weightSum);
                nodeToTriangles.addTo(dst, - weightSum);
                globalTriangle -= weightSum;
            }
        }
    }
private void count ( int src , int dst , boolean add ) { if ( ! srcToDsts . containsKey ( src ) || ! srcToDsts . containsKey ( dst ) ) { return ; } IntOpenHashSet srcSet = srcToDsts . get ( src ) ; IntOpenHashSet dstSet = srcToDsts . get ( dst ) ; if ( srcSet . size ( ) > dstSet . size ( ) ) { IntOpenHashSet temp = srcSet ; srcSet = dstSet ; dstSet = temp ; } final double weight = Math . max ( ( s + nb + ng + 0.0 ) / k * ( s + nb + ng - 1.0 ) / ( k - 1.0 ) , 1 ) ; if ( add ) { double count = 0 ; for ( int neighbor : srcSet ) { if ( dstSet . contains ( neighbor ) ) { count += 1 ; nodeToTriangles . addTo ( neighbor , weight ) ; } } if ( count > 0 ) { double weightSum = count * weight ; nodeToTriangles . addTo ( src , weightSum ) ; nodeToTriangles . addTo ( dst , weightSum ) ; globalTriangle += weightSum ; } } else if ( lowerBound ) { double count = 0 ; for ( int neighbor : srcSet ) { if ( dstSet . contains ( neighbor ) ) { count += 1 ; double value = nodeToTriangles . addTo ( neighbor , - weight ) ; if ( value < weight ) { nodeToTriangles . put ( neighbor , 0 ) ; } } } if ( count > 0 ) { final double weightSum = count * weight ; double value = nodeToTriangles . addTo ( src , - weightSum ) ; if ( value < weightSum ) { nodeToTriangles . put ( src , 0 ) ; } value = nodeToTriangles . addTo ( dst , - weightSum ) ; if ( value < weightSum ) { nodeToTriangles . put ( dst , 0 ) ; } globalTriangle -= weightSum ; globalTriangle = Math . max ( 0 , globalTriangle ) ; } } else { double count = 0 ; for ( int neighbor : srcSet ) { if ( dstSet . contains ( neighbor ) ) { count += 1 ; nodeToTriangles . addTo ( neighbor , - weight ) ; } } if ( count > 0 ) { double weightSum = count * weight ; nodeToTriangles . addTo ( src , - weightSum ) ; nodeToTriangles . addTo ( dst , - weightSum ) ; globalTriangle -= weightSum ; } } }
counts triangles with the given edge and update estimates
 @param src the source node of the given edge
 @param dst the destination node of the given edge
 @param add true for addition and false for deletion
counts triangles with the given edge and update estimates @param src the source node of the given edge @param dst the destination node of the given edge @param add true for addition and false for deletion
// if this edge has a new node, there cannot be any triangles // process the addition // process the deletion with lower bounding // lower bounding // lower bounding // lower bounding // lower bounding // process the deletion without lower bounding