// Path: src/main/java/org/apache/jena/grande/MemoryUtil.java
// public class MemoryUtil {
// 
// 	private static final Logger LOG = LoggerFactory.getLogger(MemoryUtil.class);
// 	
// 	public static long getUsedMemory() {
// 		System.gc() ;
// 		System.gc() ;
// 		System.gc() ;
// 		
// 		return ( Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory() ) / ( 1024 * 1024 ) ;
// 	}
// 	
// 	public static void printUsedMemory() {
// 		LOG.debug (String.format("memory used is %d MB", getUsedMemory())) ;
// 	}
// 	
// }


import org.apache.jena.grande.MemoryUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import edu.uci.ics.jung.algorithms.scoring.PageRank;
import edu.uci.ics.jung.graph.DirectedSparseGraph;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.StringTokenizer;
		int edgeCnt = 0;
		String line;
		while ((line = in.readLine()) != null) {
			StringTokenizer st = new StringTokenizer(line);
			String source = null;
			if ( st.hasMoreTokens() ) {
				source = st.nextToken();
				if (graph.addVertex(source))
					LOG.debug(String.format("Added verted %s to the graph", source));
			}

			HashSet<String> seen = new HashSet<String>() ;
			while ( st.hasMoreTokens() ) {
				String destination = st.nextToken();
				if (graph.addVertex(destination)) // implicit dangling nodes
					LOG.debug(String.format("Added verted %s to the graph", destination));				
				if (!destination.equals(source)) { // no self-references
					if (!seen.contains(destination)) { // no duplicate links
						graph.addEdge(new Integer(edgeCnt++), source, destination);
						seen.add(destination) ;
					}
				}
			}
		}
		in.close();
		
		LOG.debug(String.format("Loaded %d nodes and %d links in %d ms", graph.getVertexCount(), graph.getEdgeCount(), (System.currentTimeMillis()-start)));
	}
	
	public Map<String, Double> compute() throws IOException {
// Path: src/main/java/org/apache/jena/grande/MemoryUtil.java
// public class MemoryUtil {
// 
// 	private static final Logger LOG = LoggerFactory.getLogger(MemoryUtil.class);
// 	
// 	public static long getUsedMemory() {
// 		System.gc() ;
// 		System.gc() ;
// 		System.gc() ;
// 		
// 		return ( Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory() ) / ( 1024 * 1024 ) ;
// 	}
// 	
// 	public static void printUsedMemory() {
// 		LOG.debug (String.format("memory used is %d MB", getUsedMemory())) ;
// 	}
// 	
// }


// Path: src/test/java/org/apache/jena/grande/giraph/pagerank/memory/JungPageRank.java
import org.apache.jena.grande.MemoryUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import edu.uci.ics.jung.algorithms.scoring.PageRank;
import edu.uci.ics.jung.graph.DirectedSparseGraph;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.StringTokenizer;

		int edgeCnt = 0;
		String line;
		while ((line = in.readLine()) != null) {
			StringTokenizer st = new StringTokenizer(line);
			String source = null;
			if ( st.hasMoreTokens() ) {
				source = st.nextToken();
				if (graph.addVertex(source))
					LOG.debug(String.format("Added verted %s to the graph", source));
			}

			HashSet<String> seen = new HashSet<String>() ;
			while ( st.hasMoreTokens() ) {
				String destination = st.nextToken();
				if (graph.addVertex(destination)) // implicit dangling nodes
					LOG.debug(String.format("Added verted %s to the graph", destination));				
				if (!destination.equals(source)) { // no self-references
					if (!seen.contains(destination)) { // no duplicate links
						graph.addEdge(new Integer(edgeCnt++), source, destination);
						seen.add(destination) ;
					}
				}
			}
		}
		in.close();
		
		LOG.debug(String.format("Loaded %d nodes and %d links in %d ms", graph.getVertexCount(), graph.getEdgeCount(), (System.currentTimeMillis()-start)));
	}
	
	public Map<String, Double> compute() throws IOException {
		MemoryUtil.printUsedMemory() ;