Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

ding dong the Java's dead

  • Loading branch information...
commit a9176678d759629ac694f62e92f40cf43f393d56 1 parent 207db21
David R. MacIver authored
View
13 Rakefile
@@ -3,16 +3,13 @@ require 'spec/rake/spectask'
directory "classes"
directory "tally"
-file "bin/tally" => "tally" do
- sh "cd tally && rake clobber tally && cd .."
- sh "cp tally/tally bin"
+task "compile" => "cutils" do
+ sh "cc -lm -Icutils cutils/lines.o cutils/hash_counter.o cutils/hash.o pearsons.c -opearsons"
end
-task "compile" => "classes" do
- sh "javac -d classes #{File.dirname(__FILE__)}/src/*.java"
-end
-
-task "dist" => ["bin/tally", "compile"]
+task "cutils" do
+ sh "cd cutils && rake && cd .."
+end
Spec::Rake::SpecTask.new do |t|
t.rcov = false
View
2  cutils/Rakefile
@@ -15,3 +15,5 @@ CC_OPTS="-Wall -Werror -Wextra -Wwrite-strings #{if ENV["PROFILE"] then "-pg -f
rule '.o' => '.c' do |t|
sh "cc #{CC_OPTS} -c -o #{t.name} #{t.source}"
end
+
+task :default => OBJ
View
1  cutils/lines.h
@@ -1,6 +1,7 @@
#ifndef SILLY_LINE_READING
#define SILLY_LINE_READING
extern char *current_line;
+extern int current_line_length;
extern int read_line(FILE *file);
extern void reset_lines();
#endif
View
41 src/cooccurrences.java
@@ -1,41 +0,0 @@
-import java.io.*;
-import java.lang.reflect.*;
-
-/**
- * Little utility program as part of the larger pearsons code. Don't use
- * this directly.
- *
- * Takes events of the form identifier1 ... identifiern and prints all pairs
- * identifierj identifierk where identifierj < identifierk lexicographically
- */
-class cooccurrences{
- public static void main(String[] args) throws Exception{
- final BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
-
- // We want to change the buffer size on stdout.
- // Unfortunately the Java standard library gives us no way to do this.
- // Or even, in fact, any indication that System.in is a BufferedInputStream.
- // So we use reflection in amusingly abusibe ways to get access to the underlying
- final Field outout = FilterOutputStream.class.getDeclaredField("out");
- outout.setAccessible(true);
- final OutputStream stdout = new BufferedOutputStream((OutputStream)outout.get(System.out), 1024 * 1024);
-
- String line = null;
- while((line = stdin.readLine()) != null){
- final String[] fragments = line.trim().split(" ");
- java.util.Arrays.sort(fragments);
- final byte[][] arrayfragments = new byte[fragments.length][];
- for(int i = 0; i < fragments.length; i++) arrayfragments[i] = fragments[i].getBytes();
-
- for(int i = 0; i < arrayfragments.length; i++){
- for(int j = i + 1; j < arrayfragments.length; j++){
- stdout.write(arrayfragments[i]);
- stdout.write((byte)' ');
- stdout.write(arrayfragments[j]);
- stdout.write((byte)'\n');
- }
- }
- }
- stdout.flush();
- }
-}
View
146 src/pearsons.java
@@ -1,146 +0,0 @@
-import java.util.HashMap;
-import java.io.*;
-import java.lang.reflect.Field;
-
-/**
- * Utility class for doing some of the heavy lifting for the larger pearsons
- * program. Don't use this directly.
- *
- * Takes previously calculated tallies and sums and combines them to give the
- * actual pearsons balues.
- */
-public class pearsons{
-
- /**
- * Returns the index of the first ' ' character in the String.
- * Same as indexOf(' ') only lots faster.
- */
- public static int firstSpace(String line){
- for(int i = 0; i < line.length(); i ++){
- if(line.charAt(i) == ' ') return i;
- }
- return -1;
- }
-
- /**
- * Remove leading space from the line.
- */
- public static String trimLeading(String line){
- int i = 0;
- while(i < line.length() && (line.charAt(i) == ' ')) i++;
- return line.substring(i);
- }
-
- public final static String[] FRAGMENTS = new String[3];
-
- /**
- * Split the line around spaces and shove the contents into FRAGMENTS.
- * Return the number of pieces found.
- */
- public static int splitLine(String line){
- for(int j = 0; j < 3; j ++){
- line = trimLeading(line);
- int i = firstSpace(line);
-
- if(i == -1) {
- FRAGMENTS[j] = line;
- return j + 1;
- }
-
- FRAGMENTS[j] = line.substring(0, i);
- line = line.substring(i);
- }
- return 3;
- }
-
- public static void main(String[] args) throws Exception{
- final HashMap<String, Integer> tallies = new HashMap<String, Integer>();
- final BufferedReader reader = new BufferedReader(new FileReader(args[0]));
-
- String line = null;
-
- while((line = reader.readLine()) != null){
- // artifact of the way we use sed is that lines can be blank. We simply ignore them in this case.
- if(splitLine(line) == 2){
- tallies.put(FRAGMENTS[0], new Integer(FRAGMENTS[1]));
- }
- }
-
- final BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
-
- reader.close();
-
- final Field outout = FilterOutputStream.class.getDeclaredField("out");
- outout.setAccessible(true);
- final OutputStream stdout = new BufferedOutputStream((OutputStream)outout.get(System.out), 1024 * 1024);
-
- double count = Integer.parseInt(args[1]);
- double lowerLimit = Double.parseDouble(args[2]);
-
- while((line = stdin.readLine()) != null){
- splitLine(line);
- int cc = Integer.parseInt(FRAGMENTS[0]);
- String id1 = FRAGMENTS[1];
- String id2 = FRAGMENTS[2];
-
- double mu1 = tallies.get(id1) / count;
- double mu2 = tallies.get(id2) / count;
-
- double ss1 = mu1 - mu1 * mu1;
- double ss2 = mu2 - mu2 * mu2;
-
- double pearsons = (cc / count - mu1 * mu2) / Math.sqrt(ss1 * ss2);
-
- if(pearsons > lowerLimit){
- write(stdout, id1);
- write(stdout, ' ');
- write(stdout, id2);
- write(stdout, ' ');
- write(stdout, pearsons);
- write(stdout, '\n');
- }
- }
- stdout.close();
- }
-
- // Specialized crufty hacks for writing things to output streams
- // It's all gross and horrible and very special cased.
- // It's also dramatically faster than the java.io.Reader infrastructure
- // and the standard conversion routines to strings.
- public static void write(OutputStream writer, char c) throws Exception{
- writer.write((byte)c);
- }
-
- public static void write(OutputStream writer, String string) throws Exception{
- for(int i = 0; i < string.length(); i++){
- write(writer, string.charAt(i));
- }
- }
-
- public static void write(OutputStream writer, int x) throws Exception{
- if(x < 0 || x >= 100) {
- throw new RuntimeException(x + " out of bounds: My shitty int writing routine only handles ints in the range 0-99");
- }
-
- int tens = x / 10;
- x -= 10 * tens;
- int digits = x;
-
- writer.write('0' + tens);
- writer.write('0' + digits);
- }
-
- static void write(OutputStream writer, double x) throws Exception{
- if (x < 0){
- write(writer, '-');
- x = -x;
- }
-
- x = x + 0.005; // adjust for rounding
-
- int i = (int)x;
- write(writer, i);
- writer.write('.');
- write(writer, (int)(100 * (x - i)));
- }
-}
Please sign in to comment.
Something went wrong with that request. Please try again.