From: bdemsky Date: Thu, 23 Apr 2009 00:00:26 +0000 (+0000) Subject: change parsing X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=55edffb1b3751c521a72de036ab5a096a177a65f;p=IRC.git change parsing --- diff --git a/Robust/src/Benchmarks/SingleTM/KMeans/KMeans.java b/Robust/src/Benchmarks/SingleTM/KMeans/KMeans.java index b4944876..5e4a3d3b 100644 --- a/Robust/src/Benchmarks/SingleTM/KMeans/KMeans.java +++ b/Robust/src/Benchmarks/SingleTM/KMeans/KMeans.java @@ -153,6 +153,7 @@ public class KMeans extends Thread { public void run() { while(true) { Barrier.enterBarrier(); + System.out.println(threadid); Normal.work(threadid, g_args); Barrier.enterBarrier(); } @@ -359,31 +360,56 @@ public class KMeans extends Thread { byte b[] = new byte[MAX_LINE_LENGTH]; int n; + byte oldbytes[]=null; + + while ((n = inputFile.read(b)) != 0) { - j = 0; - boolean skipFirstVar = true; - StringBuffer buffer = new StringBuffer(); - for (int x = 0; x < n; x++) { - if (b[x] == '\n') { - i++; - j = 0; - buffer = new StringBuffer(); - skipFirstVar = true; - continue; - } - if (b[x] != ' ') { - buffer.append((char)b[x]); - } else { - if(skipFirstVar) { - skipFirstVar = false; - buffer = new StringBuffer(); - continue; - } - double f = KMeans.StringToFloat(buffer.toString()); - buf[i][j] = f; - buffer = new StringBuffer(); - j++; - } + j = -1; + int x=0; + + if (oldbytes!=null) { + //find space + for (;x < n; x++) { + if (b[x] == ' ') + break; + } + byte newbytes[]=new byte[x+oldbytes.length]; + for(int ii=0;ii=0) + buf[i][j]=ByteToFloat(newbytes, 0, newbytes.length); + j++; + oldbytes=null; + } + + while (x < n) { + int y=x; + for(y=x;y=0) + buf[i][j]= ByteToFloat(b, x, y-x); + x=y;//skip to end of number + x++;//skip past space + j++; } } inputFile.close(); @@ -392,56 +418,22 @@ public class KMeans extends Thread { /** * Convert a string into double **/ - public static double StringToFloat (String str) { - double total = 0.0d; // the total to return - int length = str.length(); // the length of the string - int prefixLength=0; // the length of the number BEFORE the decimal - int suffixLength=0; // the length of the number AFTER the decimal - boolean decimalFound = false; // use this to decide whether to increment prefix or suffix - for (int i = 0; i < str.length(); i++) - { // loop through the string - if (str.charAt(i) == '.') - { // if we found the '.' then we are now counting how long the decimal place is - length --; // subtract one from the length (. isn't an integer!) - decimalFound = true; // we found the decimal! - } - else if (!decimalFound) - prefixLength++;// if the decimal still hasn't been found, we should count the main number - else if (decimalFound) // otherwise, we should count how long the decimal is! - suffixLength++; + public static double ByteToFloat (byte[] str, int offset, int length) { + double left=0.0d; + double right=0.0d; + int i; + for(i=0;i