import java.util.HashMap; import java.util.StringTokenizer; import java.util.zip.GZIPInputStream; import java.io.*; /** * @author asingh * */ public class HashJoin2 { public static HashMap map1 = null; public static long count = 0; public static void runMatch(String filename2) { try { // Open the file that is the first // command line parameter FileInputStream fstream = new FileInputStream(filename2); InputStream in = new GZIPInputStream(fstream); // Get the object of DataInputStream //DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String strLine; // Read File Line By int i=0; StringTokenizer myToken = null; while ((strLine = br.readLine()) != null) { myToken = new StringTokenizer(strLine); if( myToken.nextToken().equals("19") == false ) break; String newString = "19:" + myToken.nextToken(); myToken.nextToken(); if(Integer.parseInt(myToken.nextToken()) >= 5 ) continue; i++; if( map1.containsKey(newString) && map1.get(newString).equals(19)) { count++; map1.put(newString, 0); } if(i%2999999 == 0){ System.err.println("Gone through " + i + "rows, num matches = " + count); } } // Close the input stream in.close(); } catch (Exception e) {// Catch exception if any System.err.println("Error: " + e.getMessage()); } } /** * @param args */ public static void main(String[] args) { String filename1 = args[0]; String filename2 = args[1]; try { FileInputStream fstream = new FileInputStream(filename1); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String strLine; // Read File Line By Line int numLines = 0; map1 = new HashMap(); int hashTableCount = 1; while ((strLine = br.readLine()) != null) { numLines++; map1.put(strLine, 1); if(numLines%49999999 == 0) { System.err.println("Done Creating HashTable " + hashTableCount); runMatch(filename2); map1 = new HashMap(); hashTableCount++; } } System.err.println("Done Creating HashTable " + hashTableCount); runMatch(filename2); // Close the input stream in.close(); } catch (Exception e) {// Catch exception if any System.err.println("Error: " + e.getMessage()); } System.out.println("Total Matches are " + count); } }