chrislo-sourceclassifier 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Manifest +325 -0
- data/README.textile +51 -0
- data/Rakefile +64 -0
- data/examples/example.rb +22 -0
- data/lib/sourceclassifier.rb +22 -0
- data/lib/trainer.rb +51 -0
- data/sourceclassifier.gemspec +35 -0
- data/sources/gcc/ackermann.gcc-2.gcc +93 -0
- data/sources/gcc/ackermann.gcc-3.gcc +20 -0
- data/sources/gcc/ary.gcc +40 -0
- data/sources/gcc/binarytrees.gcc +136 -0
- data/sources/gcc/binarytrees.gcc-2.gcc +140 -0
- data/sources/gcc/binarytrees.gcc-3.gcc +134 -0
- data/sources/gcc/chameneos.gcc +117 -0
- data/sources/gcc/chameneos.gcc-2.gcc +134 -0
- data/sources/gcc/chameneos.gcc-3.gcc +120 -0
- data/sources/gcc/chameneosredux.gcc +306 -0
- data/sources/gcc/echo.gcc +144 -0
- data/sources/gcc/except.gcc +52 -0
- data/sources/gcc/fannkuch.gcc +105 -0
- data/sources/gcc/fannkuch.gcc-2.gcc +94 -0
- data/sources/gcc/fasta.gcc +158 -0
- data/sources/gcc/fasta.gcc-2.gcc +132 -0
- data/sources/gcc/fasta.gcc-3.gcc +145 -0
- data/sources/gcc/fasta.gcc-4.gcc +141 -0
- data/sources/gcc/fibo.gcc +20 -0
- data/sources/gcc/harmonic.gcc +22 -0
- data/sources/gcc/hash.gcc +31 -0
- data/sources/gcc/hash2.gcc +38 -0
- data/sources/gcc/heapsort.gcc +72 -0
- data/sources/gcc/hello.gcc-2.gcc +12 -0
- data/sources/gcc/hello.gcc-3.gcc +20 -0
- data/sources/gcc/knucleotide.gcc +173 -0
- data/sources/gcc/knucleotide.gcc-2.gcc +168 -0
- data/sources/gcc/lists.gcc +226 -0
- data/sources/gcc/magicsquares.gcc +378 -0
- data/sources/gcc/mandelbrot.gcc +84 -0
- data/sources/gcc/mandelbrot.gcc-2.gcc +63 -0
- data/sources/gcc/mandelbrot.gcc-3.gcc +91 -0
- data/sources/gcc/mandelbrot.gcc-4.gcc +78 -0
- data/sources/gcc/matrix.gcc +66 -0
- data/sources/gcc/message.gcc-2.gcc +72 -0
- data/sources/gcc/message.gcc-3.gcc +64 -0
- data/sources/gcc/methcall.gcc +89 -0
- data/sources/gcc/moments.gcc +120 -0
- data/sources/gcc/nbody.gcc +142 -0
- data/sources/gcc/nbody.gcc-2.gcc +143 -0
- data/sources/gcc/nbody.gcc-3.gcc +142 -0
- data/sources/gcc/nestedloop.gcc +25 -0
- data/sources/gcc/nsieve.gcc +35 -0
- data/sources/gcc/nsievebits.gcc-2.gcc +37 -0
- data/sources/gcc/nsievebits.gcc-3.gcc +53 -0
- data/sources/gcc/objinst.gcc +95 -0
- data/sources/gcc/partialsums.gcc +86 -0
- data/sources/gcc/partialsums.gcc-3.gcc +81 -0
- data/sources/gcc/partialsums.gcc-4.gcc +68 -0
- data/sources/gcc/pidigits.gcc +105 -0
- data/sources/gcc/primes.gcc +75 -0
- data/sources/gcc/prodcons.gcc +86 -0
- data/sources/gcc/random.gcc +29 -0
- data/sources/gcc/raytracer.gcc +125 -0
- data/sources/gcc/raytracer.gcc-2.gcc +181 -0
- data/sources/gcc/recursive.gcc +68 -0
- data/sources/gcc/recursive.gcc-2.gcc +55 -0
- data/sources/gcc/regexdna.gcc-2.gcc +126 -0
- data/sources/gcc/regexmatch.gcc +136 -0
- data/sources/gcc/revcomp.gcc +85 -0
- data/sources/gcc/revcomp.gcc-2.gcc +88 -0
- data/sources/gcc/revcomp.gcc-4.gcc +71 -0
- data/sources/gcc/reversefile.gcc +103 -0
- data/sources/gcc/reversefile.gcc-2.gcc +56 -0
- data/sources/gcc/sieve.gcc +34 -0
- data/sources/gcc/spectralnorm.gcc +54 -0
- data/sources/gcc/spellcheck.gcc +72 -0
- data/sources/gcc/spellcheck.gcc-2.gcc +61 -0
- data/sources/gcc/strcat.gcc +38 -0
- data/sources/gcc/sumcol.gcc-2.gcc +98 -0
- data/sources/gcc/sumcol.gcc-3.gcc +22 -0
- data/sources/gcc/sumcol.gcc-4.gcc +18 -0
- data/sources/gcc/sumcol.gcc-5.gcc +32 -0
- data/sources/gcc/takfp.gcc +23 -0
- data/sources/gcc/tcp-stream.gcc +122 -0
- data/sources/gcc/tcpecho.gcc +122 -0
- data/sources/gcc/tcpecho.gcc-2.gcc +136 -0
- data/sources/gcc/tcprequest.gcc +122 -0
- data/sources/gcc/threadring.gcc +73 -0
- data/sources/gcc/wc.gcc +52 -0
- data/sources/gcc/wc.gcc-2.gcc +40 -0
- data/sources/gcc/wc.gcc-3.gcc +46 -0
- data/sources/gcc/wordfreq.gcc-2.gcc +85 -0
- data/sources/perl/ackermann.perl +28 -0
- data/sources/perl/ackermann.perl-2.perl +25 -0
- data/sources/perl/ackermann.perl-3.perl +20 -0
- data/sources/perl/ackermann.perl-4.perl +18 -0
- data/sources/perl/ary.perl +25 -0
- data/sources/perl/ary.perl-2.perl +23 -0
- data/sources/perl/binarytrees.perl +66 -0
- data/sources/perl/binarytrees.perl-2.perl +71 -0
- data/sources/perl/chameneos.perl +67 -0
- data/sources/perl/echo.perl +81 -0
- data/sources/perl/except.perl +73 -0
- data/sources/perl/fannkuch.perl +44 -0
- data/sources/perl/fannkuch.perl-2.perl +38 -0
- data/sources/perl/fasta.perl +112 -0
- data/sources/perl/fasta.perl-2.perl +135 -0
- data/sources/perl/fasta.perl-4.perl +122 -0
- data/sources/perl/fibo.perl +15 -0
- data/sources/perl/fibo.perl-2.perl +0 -0
- data/sources/perl/fibo.perl-3.perl +0 -0
- data/sources/perl/harmonic.perl +7 -0
- data/sources/perl/hash.perl +23 -0
- data/sources/perl/hash.perl-2.perl +17 -0
- data/sources/perl/hash.perl-3.perl +24 -0
- data/sources/perl/hash2.perl +16 -0
- data/sources/perl/heapsort.perl +65 -0
- data/sources/perl/heapsort.perl-2.perl +0 -0
- data/sources/perl/hello.perl +5 -0
- data/sources/perl/knucleotide.perl-2.perl +30 -0
- data/sources/perl/lists.perl +48 -0
- data/sources/perl/mandelbrot.perl-2.perl +32 -0
- data/sources/perl/matrix.perl +59 -0
- data/sources/perl/matrix.perl-2.perl +0 -0
- data/sources/perl/matrix.perl-3.perl +0 -0
- data/sources/perl/message.perl +27 -0
- data/sources/perl/methcall.perl +66 -0
- data/sources/perl/moments.perl +44 -0
- data/sources/perl/nbody.perl +108 -0
- data/sources/perl/nestedloop.perl +28 -0
- data/sources/perl/nsieve.perl-2.perl +41 -0
- data/sources/perl/nsieve.perl-4.perl +43 -0
- data/sources/perl/nsievebits.perl +37 -0
- data/sources/perl/objinst.perl +73 -0
- data/sources/perl/partialsums.perl-3.perl +31 -0
- data/sources/perl/pidigits.perl +52 -0
- data/sources/perl/pidigits.perl-2.perl +47 -0
- data/sources/perl/process.perl +50 -0
- data/sources/perl/prodcons.perl +47 -0
- data/sources/perl/random.perl-4.perl +17 -0
- data/sources/perl/recursive.perl-2.perl +57 -0
- data/sources/perl/regexdna.perl +48 -0
- data/sources/perl/regexdna.perl-2.perl +43 -0
- data/sources/perl/regexdna.perl-3.perl +50 -0
- data/sources/perl/regexdna.perl-4.perl +49 -0
- data/sources/perl/regexdna.perl-5.perl +42 -0
- data/sources/perl/regexdna.perl-6.perl +43 -0
- data/sources/perl/regexmatch.perl +35 -0
- data/sources/perl/revcomp.perl-2.perl +34 -0
- data/sources/perl/reversefile.perl +8 -0
- data/sources/perl/reversefile.perl-2.perl +0 -0
- data/sources/perl/reversefile.perl-3.perl +0 -0
- data/sources/perl/sieve.perl +23 -0
- data/sources/perl/spectralnorm.perl-2.perl +54 -0
- data/sources/perl/spellcheck.perl +24 -0
- data/sources/perl/strcat.perl +13 -0
- data/sources/perl/strcat.perl-2.perl +0 -0
- data/sources/perl/sumcol.perl +8 -0
- data/sources/perl/takfp.perl +23 -0
- data/sources/perl/takfp.perl-3.perl +20 -0
- data/sources/perl/tcpecho.perl +61 -0
- data/sources/perl/tcprequest.perl +61 -0
- data/sources/perl/tcpstream.perl +61 -0
- data/sources/perl/threadring.perl +55 -0
- data/sources/perl/threadring.perl-2.perl +43 -0
- data/sources/perl/wc.perl +20 -0
- data/sources/perl/wc.perl-2.perl +14 -0
- data/sources/perl/wordfreq.perl +22 -0
- data/sources/perl/wordfreq.perl-3.perl +0 -0
- data/sources/perl/wordfreq.perl3.perl +0 -0
- data/sources/python/ackermann.python +21 -0
- data/sources/python/ary.python +19 -0
- data/sources/python/binarytrees.python +39 -0
- data/sources/python/binarytrees.python-3.python +44 -0
- data/sources/python/chameneos.python-6.python +73 -0
- data/sources/python/chameneosredux.python +126 -0
- data/sources/python/chameneosredux.python-2.python +122 -0
- data/sources/python/dispatch.python +176 -0
- data/sources/python/dispatch.python-2.python +136 -0
- data/sources/python/echo.python +64 -0
- data/sources/python/except.python +62 -0
- data/sources/python/fannkuch.python +50 -0
- data/sources/python/fannkuch.python-2.python +54 -0
- data/sources/python/fasta.python-2.python +79 -0
- data/sources/python/fibo.python +17 -0
- data/sources/python/fibo.python-2.python +0 -0
- data/sources/python/fibo.python-3.python +0 -0
- data/sources/python/harmonic.python-2.python +9 -0
- data/sources/python/hash.python +21 -0
- data/sources/python/hash.python-2.python +0 -0
- data/sources/python/hash2.python +30 -0
- data/sources/python/heapsort.python-3.python +66 -0
- data/sources/python/hello.python +5 -0
- data/sources/python/implicitode.python +231 -0
- data/sources/python/knucleotide.python +55 -0
- data/sources/python/lists.python +44 -0
- data/sources/python/magicsquares.python +145 -0
- data/sources/python/mandelbrot.python +44 -0
- data/sources/python/mandelbrot.python-2.python +35 -0
- data/sources/python/mandelbrot.python-3.python +46 -0
- data/sources/python/matrix.python +34 -0
- data/sources/python/matrix.python-2.python +23 -0
- data/sources/python/message.python +24 -0
- data/sources/python/message.python-2.python +20 -0
- data/sources/python/message.python-3.python +19 -0
- data/sources/python/meteor.python +210 -0
- data/sources/python/meteor.python-2.python +192 -0
- data/sources/python/methcall.python +51 -0
- data/sources/python/moments.python +65 -0
- data/sources/python/nbody.python +123 -0
- data/sources/python/nbody.python-2.python +120 -0
- data/sources/python/nestedloop.python +24 -0
- data/sources/python/nsieve.python +27 -0
- data/sources/python/nsieve.python-2.python +23 -0
- data/sources/python/nsieve.python-4.python +25 -0
- data/sources/python/nsievebits.python +27 -0
- data/sources/python/nsievebits.python-2.python +43 -0
- data/sources/python/objinst.python +53 -0
- data/sources/python/partialsums.python +37 -0
- data/sources/python/partialsums.python-2.python +35 -0
- data/sources/python/partialsums.python-3.python +48 -0
- data/sources/python/pidigits.python +38 -0
- data/sources/python/pidigits.python-3.python +63 -0
- data/sources/python/pidigits.python-4.python +24 -0
- data/sources/python/process.python +51 -0
- data/sources/python/process.python-2.python +133 -0
- data/sources/python/prodcons.python +51 -0
- data/sources/python/prodcons.python-2.python +0 -0
- data/sources/python/random.python +27 -0
- data/sources/python/raytracer.python +203 -0
- data/sources/python/recursive.python +35 -0
- data/sources/python/regexdna.python +39 -0
- data/sources/python/regexdna.python-2.python +34 -0
- data/sources/python/regexmatch.python +36 -0
- data/sources/python/revcomp.python-3.python +31 -0
- data/sources/python/reversefile.python +13 -0
- data/sources/python/reversefile.python-2.python +0 -0
- data/sources/python/reversefile.python-3.python +0 -0
- data/sources/python/sieve.python +50 -0
- data/sources/python/spectralnorm.python-2.python +36 -0
- data/sources/python/spellcheck.python +17 -0
- data/sources/python/strcat.python +35 -0
- data/sources/python/strcat.python-2.python +0 -0
- data/sources/python/sumcol.python-2.python +0 -0
- data/sources/python/sumcol.python-3.python +0 -0
- data/sources/python/takfp.python +19 -0
- data/sources/python/tcpecho.python +67 -0
- data/sources/python/tcprequest.python +67 -0
- data/sources/python/tcpstream.python +67 -0
- data/sources/python/threadring.python +47 -0
- data/sources/python/threadring.python-2.python +40 -0
- data/sources/python/threadring.python-3.python +34 -0
- data/sources/python/wc.python-2.python +19 -0
- data/sources/python/wordfreq.python +43 -0
- data/sources/python/wordfreq.python-2.python +0 -0
- data/sources/python/wordfreq.python-3.python +28 -0
- data/sources/python/wordfreq.python-4.python +38 -0
- data/sources/python/wordfreq.python-5.python +39 -0
- data/sources/ruby/ackermann.ruby +17 -0
- data/sources/ruby/ackermann.ruby-5.ruby +153 -0
- data/sources/ruby/ary.ruby +22 -0
- data/sources/ruby/binarytrees.ruby-2.ruby +55 -0
- data/sources/ruby/chameneos.ruby-2.ruby +71 -0
- data/sources/ruby/dispatch.ruby +114 -0
- data/sources/ruby/echo.ruby +41 -0
- data/sources/ruby/except.ruby +61 -0
- data/sources/ruby/except.ruby-2.ruby +61 -0
- data/sources/ruby/fannkuch.ruby +42 -0
- data/sources/ruby/fasta.ruby +81 -0
- data/sources/ruby/fibo.ruby +15 -0
- data/sources/ruby/harmonic.ruby-2.ruby +15 -0
- data/sources/ruby/hash.ruby +19 -0
- data/sources/ruby/hash2.ruby +23 -0
- data/sources/ruby/heapsort.ruby +55 -0
- data/sources/ruby/hello.ruby +6 -0
- data/sources/ruby/knucleotide.ruby-2.ruby +44 -0
- data/sources/ruby/lists.ruby +46 -0
- data/sources/ruby/mandelbrot.ruby-3.ruby +63 -0
- data/sources/ruby/matrix.ruby +40 -0
- data/sources/ruby/matrix.ruby-2.ruby +30 -0
- data/sources/ruby/message.ruby +29 -0
- data/sources/ruby/message.ruby-2.ruby +24 -0
- data/sources/ruby/meteor.ruby +386 -0
- data/sources/ruby/meteor.ruby-2.ruby +561 -0
- data/sources/ruby/methcall.ruby +58 -0
- data/sources/ruby/methcall.ruby-2.ruby +54 -0
- data/sources/ruby/moments.ruby +64 -0
- data/sources/ruby/nbody.ruby-2.ruby +145 -0
- data/sources/ruby/nestedloop.ruby +22 -0
- data/sources/ruby/nsieve.ruby +36 -0
- data/sources/ruby/nsieve.ruby-2.ruby +25 -0
- data/sources/ruby/nsievebits.ruby-2.ruby +42 -0
- data/sources/ruby/objinst.ruby +58 -0
- data/sources/ruby/partialsums.ruby +39 -0
- data/sources/ruby/pidigits.ruby +92 -0
- data/sources/ruby/pidigits.ruby-2.ruby +109 -0
- data/sources/ruby/prodcons.ruby +41 -0
- data/sources/ruby/random.ruby +17 -0
- data/sources/ruby/recursive.ruby-2.ruby +53 -0
- data/sources/ruby/regexdna.ruby +32 -0
- data/sources/ruby/regexdna.ruby-2.ruby +38 -0
- data/sources/ruby/regexmatch.ruby +33 -0
- data/sources/ruby/revcomp.ruby +28 -0
- data/sources/ruby/reversefile.ruby +7 -0
- data/sources/ruby/sieve.ruby +30 -0
- data/sources/ruby/spectralnorm.ruby +48 -0
- data/sources/ruby/spellcheck.ruby +18 -0
- data/sources/ruby/spellcheck.ruby-2.ruby +0 -0
- data/sources/ruby/strcat.ruby +12 -0
- data/sources/ruby/strcat.ruby-2.ruby +12 -0
- data/sources/ruby/sumcol.ruby +12 -0
- data/sources/ruby/sumcol.ruby-2.ruby +5 -0
- data/sources/ruby/takfp.ruby +15 -0
- data/sources/ruby/tcpecho.ruby +45 -0
- data/sources/ruby/tcprequest.ruby +45 -0
- data/sources/ruby/tcpstream.ruby +45 -0
- data/sources/ruby/threadring.ruby +61 -0
- data/sources/ruby/threadring.ruby-2.ruby +33 -0
- data/sources/ruby/wc.ruby +15 -0
- data/sources/ruby/wordfreq.ruby +17 -0
- data/sources/ruby/wordfreq.ruby2.ruby +0 -0
- data/test/fixtures/sources/gcc/ackermann.gcc-2.gcc +93 -0
- data/test/fixtures/sources/python/ackermann.python +21 -0
- data/test/fixtures/sources/ruby/ackermann.ruby +17 -0
- data/test/test_source_classifier.rb +40 -0
- data/test/test_trainer.rb +34 -0
- data/trainer.bin +1193 -0
- metadata +393 -0
@@ -0,0 +1,88 @@
|
|
1
|
+
#include <stdio.h>
|
2
|
+
#include <string.h>
|
3
|
+
#include <limits.h>
|
4
|
+
|
5
|
+
static unsigned char iubpairs[][2] = {
|
6
|
+
{ 'A', 'T' },
|
7
|
+
{ 'C', 'G' },
|
8
|
+
{ 'B', 'V' },
|
9
|
+
{ 'D', 'H' },
|
10
|
+
{ 'K', 'M' },
|
11
|
+
{ 'R', 'Y' },
|
12
|
+
{ '\0', '\0' }
|
13
|
+
};
|
14
|
+
|
15
|
+
static unsigned char iubComplement[1+UCHAR_MAX];
|
16
|
+
|
17
|
+
static void buildIubComplement (void) {
|
18
|
+
int i;
|
19
|
+
for (i=0; i <= UCHAR_MAX; i++) iubComplement[i] = (unsigned char) i;
|
20
|
+
for (i=0; iubpairs[i][0] != '\0'; i++) {
|
21
|
+
iubComplement[iubpairs[i][0]] = iubpairs[i][1];
|
22
|
+
iubComplement[iubpairs[i][1]] = iubpairs[i][0];
|
23
|
+
iubComplement[tolower (iubpairs[i][0])] = iubpairs[i][1];
|
24
|
+
iubComplement[tolower (iubpairs[i][1])] = iubpairs[i][0];
|
25
|
+
}
|
26
|
+
}
|
27
|
+
|
28
|
+
static void inPlaceReverse (unsigned char * strand, int len) {
|
29
|
+
int i;
|
30
|
+
for (i=0, len--; i < len; i++,len--) {
|
31
|
+
unsigned char c = strand[i];
|
32
|
+
strand[i] = iubComplement[strand[len]];
|
33
|
+
strand[len] = iubComplement[c];
|
34
|
+
}
|
35
|
+
if (i == len) strand[i] = iubComplement[strand[i]];
|
36
|
+
}
|
37
|
+
|
38
|
+
static void process (char * strand, int len) {
|
39
|
+
char * s, c;
|
40
|
+
|
41
|
+
inPlaceReverse ((unsigned char *) strand, len);
|
42
|
+
s = strand;
|
43
|
+
|
44
|
+
while (len > 60) {
|
45
|
+
c = s[60];
|
46
|
+
s[60] = '\0';
|
47
|
+
puts (s);
|
48
|
+
s[60] = c;
|
49
|
+
s += 60;
|
50
|
+
len -= 60;
|
51
|
+
}
|
52
|
+
|
53
|
+
s[len] = '\0';
|
54
|
+
puts (s);
|
55
|
+
}
|
56
|
+
|
57
|
+
int main (int argc, char * argv[]) {
|
58
|
+
static char buffer[1024];
|
59
|
+
char * inp = (char *) malloc (129);
|
60
|
+
int mlen = 128;
|
61
|
+
int slen = 0;
|
62
|
+
|
63
|
+
buildIubComplement ();
|
64
|
+
|
65
|
+
while (NULL != fgets (buffer, 1023, stdin)) {
|
66
|
+
if (buffer[0] == '>') {
|
67
|
+
if (slen > 0) {
|
68
|
+
process (inp, slen);
|
69
|
+
slen = 0;
|
70
|
+
}
|
71
|
+
printf ("%s", buffer);
|
72
|
+
} else {
|
73
|
+
int l = strlen (buffer);
|
74
|
+
while (l > 0 && !isalpha (buffer[l-1])) l--;
|
75
|
+
while (slen + l > mlen) {
|
76
|
+
mlen += mlen;
|
77
|
+
inp = (char *) realloc (inp, mlen + 1);
|
78
|
+
}
|
79
|
+
|
80
|
+
memcpy (inp + slen, buffer, l);
|
81
|
+
slen += l;
|
82
|
+
}
|
83
|
+
}
|
84
|
+
if (slen > 0) process (inp, slen);
|
85
|
+
free (inp);
|
86
|
+
return 0;
|
87
|
+
}
|
88
|
+
|
@@ -0,0 +1,71 @@
|
|
1
|
+
/*
|
2
|
+
* The Computer Language Benchmarks Game
|
3
|
+
* http://shootout.alioth.debian.org
|
4
|
+
*
|
5
|
+
* contributed by Bob W
|
6
|
+
*/
|
7
|
+
|
8
|
+
#include <stdio.h>
|
9
|
+
#include <stdlib.h>
|
10
|
+
|
11
|
+
#define JBFSIZE 82 // line input buffer size
|
12
|
+
#define QBFSIZE 5200 // output buffer initial size
|
13
|
+
#define Z16 "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
|
14
|
+
#define V32 "\0TVGH\0\0CD\0\0M\0KN\0\0\0YSA\0BW\0R\0\0\0\0\0\0"
|
15
|
+
#define VALL Z16 Z16 Z16 Z16 V32 V32 Z16 Z16 Z16 Z16 Z16 Z16 Z16 Z16
|
16
|
+
|
17
|
+
int errex(char *s, int n) { // error message+value, return 1
|
18
|
+
fprintf(stderr,"\n*** Error: %s [%d]!\n", s, n);
|
19
|
+
return 1;
|
20
|
+
}
|
21
|
+
|
22
|
+
int main () { // ***** main *****
|
23
|
+
char *pj, *pq, *pr; // buffer pointers: inp,out,/out
|
24
|
+
char *jjj = malloc(JBFSIZE); // allocate input line buffer
|
25
|
+
char *qqq = malloc(QBFSIZE); // output buffer (dyn. size)
|
26
|
+
char *pqstop = qqq+QBFSIZE; // end-of-buffer pointer
|
27
|
+
char xtab[256] = VALL; // char conversion table
|
28
|
+
|
29
|
+
if (!jjj || !qqq)
|
30
|
+
return errex("Buffer allocation", !jjj + !qqq);
|
31
|
+
pj = fgets(jjj,JBFSIZE,stdin); // fetch 1st line
|
32
|
+
if (!pj)
|
33
|
+
return errex("No input data",0);
|
34
|
+
if (*jjj != '>')
|
35
|
+
return errex("1st char not '>'", 0);
|
36
|
+
|
37
|
+
while (pj) { // MAIN LOOP: process data
|
38
|
+
fputs(jjj, stdout); // output ID line
|
39
|
+
|
40
|
+
for (pq=qqq+1, pr=pqstop; ; pq++) { // LOOP: fill output buffer
|
41
|
+
pj = fgets(jjj, JBFSIZE, stdin); // get line from stdin
|
42
|
+
if (!pj || (*jjj=='>')) break; // EOF or new ID line
|
43
|
+
if (pr <= (pq+61)) { // need to resize buffer
|
44
|
+
char *newstop = pqstop + 12777888;
|
45
|
+
char *newptr = realloc(qqq, newstop-qqq);
|
46
|
+
if (!newptr)
|
47
|
+
return errex("Out of memory", 0);
|
48
|
+
if (newptr != qqq) { // new base: adj. pointers
|
49
|
+
size_t x = newptr-qqq; // offset for pointer update
|
50
|
+
pq+=x; pr+=x; qqq+=x;
|
51
|
+
newstop+=x; pqstop+=x;
|
52
|
+
}
|
53
|
+
pr = __builtin_memmove(newstop-(pqstop-pr), pr, pqstop-pr);
|
54
|
+
pqstop = newstop; // buffer resize complete
|
55
|
+
}
|
56
|
+
while (*pj) { // LOOP: conv. & revert line
|
57
|
+
char c = xtab[(unsigned char)(*pj++)];
|
58
|
+
if (c) // conversion valid
|
59
|
+
*(--pr) = c;
|
60
|
+
}
|
61
|
+
}
|
62
|
+
|
63
|
+
for (pq = qqq; pr<pqstop; ) { // LOOP: format output
|
64
|
+
size_t x = (pqstop-pr)<60 ? pqstop-pr : 60;
|
65
|
+
__builtin_memmove(pq,pr,x); // move line to free space
|
66
|
+
pr+=x; pq+=x; *(pq++) = 0xA; // adjust pointers, add LF
|
67
|
+
}
|
68
|
+
fwrite(qqq, 1, pq-qqq, stdout); // output converted data
|
69
|
+
}
|
70
|
+
return 0;
|
71
|
+
}
|
@@ -0,0 +1,103 @@
|
|
1
|
+
/* -*- mode: c -*-
|
2
|
+
* $Id: reversefile.gcc,v 1.5 2004-10-18 07:15:07 bfulgham Exp $
|
3
|
+
* http://shootout.alioth.debian.org/
|
4
|
+
*
|
5
|
+
* from Alan Post <apost@recalcitrant.org>
|
6
|
+
*/
|
7
|
+
|
8
|
+
#include <stdio.h>
|
9
|
+
#include <stdlib.h>
|
10
|
+
#include <string.h>
|
11
|
+
#include <unistd.h>
|
12
|
+
#include <assert.h>
|
13
|
+
#include <limits.h>
|
14
|
+
#include <sys/uio.h>
|
15
|
+
|
16
|
+
#define MAXREAD 4096
|
17
|
+
#define IOV_MAX 1024
|
18
|
+
|
19
|
+
typedef struct buf_t { char d[MAXREAD];
|
20
|
+
size_t len;
|
21
|
+
struct buf_t *next;} buf_t;
|
22
|
+
|
23
|
+
static print_string( char *data, size_t len,
|
24
|
+
struct iovec *vec, size_t *p_ivec )
|
25
|
+
{
|
26
|
+
vec[ *p_ivec ].iov_base = data;
|
27
|
+
vec[ *p_ivec ].iov_len = (int) len;
|
28
|
+
++ *p_ivec;
|
29
|
+
if ( *p_ivec == IOV_MAX )
|
30
|
+
{
|
31
|
+
writev( STDOUT_FILENO, vec, *p_ivec );
|
32
|
+
*p_ivec = 0;
|
33
|
+
}
|
34
|
+
}
|
35
|
+
|
36
|
+
static print_line( char *pos, char *end, buf_t **p_loh,
|
37
|
+
struct iovec *vec, size_t *p_ivec )
|
38
|
+
{
|
39
|
+
print_string( pos, end - pos, vec, p_ivec );
|
40
|
+
for (; *p_loh != NULL; *p_loh = (*p_loh)->next )
|
41
|
+
print_string( (*p_loh)->d, (*p_loh)->len, vec, p_ivec );
|
42
|
+
}
|
43
|
+
|
44
|
+
static void rev_print( buf_t *head )
|
45
|
+
{
|
46
|
+
buf_t *loh = NULL;
|
47
|
+
buf_t *curr = head;
|
48
|
+
|
49
|
+
struct iovec vec[ IOV_MAX ];
|
50
|
+
size_t ivec = 0;
|
51
|
+
|
52
|
+
while ( 1 )
|
53
|
+
{
|
54
|
+
char *buf = curr->d;
|
55
|
+
char *end = buf + curr->len;
|
56
|
+
char *pos = end;
|
57
|
+
for (;; pos--)
|
58
|
+
{
|
59
|
+
if ( pos <= buf )
|
60
|
+
{
|
61
|
+
buf_t *new_curr = curr->next;
|
62
|
+
|
63
|
+
if ( new_curr == NULL )
|
64
|
+
{
|
65
|
+
print_line( pos, end, &loh, vec, &ivec );
|
66
|
+
writev( STDOUT_FILENO, vec, ivec );
|
67
|
+
return;
|
68
|
+
}
|
69
|
+
|
70
|
+
curr->len = end - buf;
|
71
|
+
curr->next = loh;
|
72
|
+
loh = curr;
|
73
|
+
|
74
|
+
curr = new_curr;
|
75
|
+
break;
|
76
|
+
}
|
77
|
+
if ( *(pos-1) == '\n' )
|
78
|
+
{
|
79
|
+
print_line( pos, end, &loh, vec, &ivec );
|
80
|
+
end = pos;
|
81
|
+
}
|
82
|
+
}
|
83
|
+
}
|
84
|
+
assert( NULL == "unreachable" );
|
85
|
+
}
|
86
|
+
|
87
|
+
static void f( buf_t *tail )
|
88
|
+
{
|
89
|
+
buf_t head;
|
90
|
+
|
91
|
+
head.next = tail;
|
92
|
+
head.len = read( STDIN_FILENO, head.d, MAXREAD );
|
93
|
+
|
94
|
+
if ( head.len == MAXREAD ) f( &head );
|
95
|
+
else rev_print( &head );
|
96
|
+
}
|
97
|
+
|
98
|
+
int main(int argc, char *argv[])
|
99
|
+
{
|
100
|
+
f( NULL );
|
101
|
+
return EXIT_SUCCESS;
|
102
|
+
}
|
103
|
+
|
@@ -0,0 +1,56 @@
|
|
1
|
+
/* -*- mode: c -*-
|
2
|
+
* $Id: reversefile.gcc-2.gcc,v 1.1 2004-11-10 06:51:38 bfulgham Exp $
|
3
|
+
* http://www.bagley.org/~doug/shootout/
|
4
|
+
*/
|
5
|
+
|
6
|
+
/* this version attempts to read the file line by line instead of
|
7
|
+
all at once. */
|
8
|
+
|
9
|
+
#include <stdio.h>
|
10
|
+
#include <stdlib.h>
|
11
|
+
#include <string.h>
|
12
|
+
#include <unistd.h>
|
13
|
+
|
14
|
+
#define BLKSIZE 16 * 1024
|
15
|
+
|
16
|
+
int main(int argc, char *argv[]) {
|
17
|
+
int nread, size, len;
|
18
|
+
char *cp, *offset, *buf = malloc(BLKSIZE + 1);
|
19
|
+
|
20
|
+
offset = buf;
|
21
|
+
size = len = BLKSIZE;
|
22
|
+
while (1) {
|
23
|
+
nread = read(0, offset, len);
|
24
|
+
if (0 == nread) break;
|
25
|
+
if (-1 == nread) {
|
26
|
+
perror("read");
|
27
|
+
exit(1);
|
28
|
+
}
|
29
|
+
offset += nread;
|
30
|
+
len -= nread;
|
31
|
+
if (0 == len) {
|
32
|
+
len = size;
|
33
|
+
size *= 2;
|
34
|
+
if (0 == (cp = realloc(buf, size + 1))) {
|
35
|
+
fprintf(stderr, "realloc failed\n");
|
36
|
+
exit(1);
|
37
|
+
}
|
38
|
+
buf = cp;
|
39
|
+
offset = buf + len;
|
40
|
+
}
|
41
|
+
}
|
42
|
+
*offset = 0;
|
43
|
+
for (cp = offset; cp > buf; --cp) {
|
44
|
+
if ('\n' == *cp) {
|
45
|
+
*offset = 0;
|
46
|
+
if (cp < offset)
|
47
|
+
printf(offset = cp+1);
|
48
|
+
}
|
49
|
+
}
|
50
|
+
if (cp < offset) {
|
51
|
+
*offset = 0;
|
52
|
+
printf(cp);
|
53
|
+
}
|
54
|
+
free(buf);
|
55
|
+
return(0);
|
56
|
+
}
|
@@ -0,0 +1,34 @@
|
|
1
|
+
/* -*- mode: c -*-
|
2
|
+
* $Id: sieve.gcc,v 1.1.1.1 2004-05-19 18:12:27 bfulgham Exp $
|
3
|
+
* http://www.bagley.org/~doug/shootout/
|
4
|
+
*/
|
5
|
+
|
6
|
+
#include <stdio.h>
|
7
|
+
#include <stdlib.h>
|
8
|
+
|
9
|
+
int
|
10
|
+
main(int argc, char *argv[]) {
|
11
|
+
int NUM = ((argc == 2) ? atoi(argv[1]) : 1);
|
12
|
+
static char flags[8192 + 1];
|
13
|
+
long i, k;
|
14
|
+
int count = 0;
|
15
|
+
|
16
|
+
while (NUM--) {
|
17
|
+
count = 0;
|
18
|
+
for (i=2; i <= 8192; i++) {
|
19
|
+
flags[i] = 1;
|
20
|
+
}
|
21
|
+
for (i=2; i <= 8192; i++) {
|
22
|
+
if (flags[i]) {
|
23
|
+
// remove all multiples of prime: i
|
24
|
+
for (k=i+i; k <= 8192; k+=i) {
|
25
|
+
flags[k] = 0;
|
26
|
+
}
|
27
|
+
count++;
|
28
|
+
}
|
29
|
+
}
|
30
|
+
}
|
31
|
+
printf("Count: %d\n", count);
|
32
|
+
return(0);
|
33
|
+
}
|
34
|
+
|
@@ -0,0 +1,54 @@
|
|
1
|
+
/* -*- mode: c -*-
|
2
|
+
*
|
3
|
+
* The Great Computer Language Shootout
|
4
|
+
* http://shootout.alioth.debian.org/
|
5
|
+
*
|
6
|
+
* Contributed by Sebastien Loisel
|
7
|
+
*/
|
8
|
+
|
9
|
+
#include <stdio.h>
|
10
|
+
#include <stdlib.h>
|
11
|
+
#include <math.h>
|
12
|
+
|
13
|
+
double eval_A(int i, int j) { return 1.0/((i+j)*(i+j+1)/2+i+1); }
|
14
|
+
|
15
|
+
void eval_A_times_u(int N, const double u[], double Au[])
|
16
|
+
{
|
17
|
+
int i,j;
|
18
|
+
for(i=0;i<N;i++)
|
19
|
+
{
|
20
|
+
Au[i]=0;
|
21
|
+
for(j=0;j<N;j++) Au[i]+=eval_A(i,j)*u[j];
|
22
|
+
}
|
23
|
+
}
|
24
|
+
|
25
|
+
void eval_At_times_u(int N, const double u[], double Au[])
|
26
|
+
{
|
27
|
+
int i,j;
|
28
|
+
for(i=0;i<N;i++)
|
29
|
+
{
|
30
|
+
Au[i]=0;
|
31
|
+
for(j=0;j<N;j++) Au[i]+=eval_A(j,i)*u[j];
|
32
|
+
}
|
33
|
+
}
|
34
|
+
|
35
|
+
void eval_AtA_times_u(int N, const double u[], double AtAu[])
|
36
|
+
{ double v[N]; eval_A_times_u(N,u,v); eval_At_times_u(N,v,AtAu); }
|
37
|
+
|
38
|
+
int main(int argc, char *argv[])
|
39
|
+
{
|
40
|
+
int i;
|
41
|
+
int N = ((argc == 2) ? atoi(argv[1]) : 2000);
|
42
|
+
double u[N],v[N],vBv,vv;
|
43
|
+
for(i=0;i<N;i++) u[i]=1;
|
44
|
+
for(i=0;i<10;i++)
|
45
|
+
{
|
46
|
+
eval_AtA_times_u(N,u,v);
|
47
|
+
eval_AtA_times_u(N,v,u);
|
48
|
+
}
|
49
|
+
vBv=vv=0;
|
50
|
+
for(i=0;i<N;i++) { vBv+=u[i]*v[i]; vv+=v[i]*v[i]; }
|
51
|
+
printf("%0.9f\n",sqrt(vBv/vv));
|
52
|
+
return 0;
|
53
|
+
}
|
54
|
+
|
@@ -0,0 +1,72 @@
|
|
1
|
+
/* -*- mode: c -*-
|
2
|
+
* $Id: spellcheck.gcc,v 1.1.1.1 2004-05-19 18:13:26 bfulgham Exp $
|
3
|
+
* http://www.bagley.org/~doug/shootout/
|
4
|
+
* with help from Brad Knotwell
|
5
|
+
*/
|
6
|
+
|
7
|
+
#include <ctype.h>
|
8
|
+
#include <stdio.h>
|
9
|
+
#include <stdlib.h>
|
10
|
+
#include <unistd.h>
|
11
|
+
#include "simple_hash.h"
|
12
|
+
|
13
|
+
#define MAXLINELEN 128
|
14
|
+
|
15
|
+
struct ht_ht *dict = NULL;
|
16
|
+
|
17
|
+
int handleInput(FILE *input,void (*hashManipFn)(char *))
|
18
|
+
{
|
19
|
+
int wordbufsize = 80,i = 0;
|
20
|
+
char *cp, *wordbuf = (char *)malloc(wordbufsize + 1);
|
21
|
+
char line[MAXLINELEN];
|
22
|
+
|
23
|
+
if((wordbuf = malloc(wordbufsize+1)) == NULL)
|
24
|
+
return(fprintf(stderr,"malloc\n"),0);
|
25
|
+
|
26
|
+
while (fgets(line, MAXLINELEN, input))
|
27
|
+
for (cp=line; *cp > 0; cp++) {
|
28
|
+
if (isspace(*cp)) {
|
29
|
+
if (i) {
|
30
|
+
wordbuf[i] = '\0';
|
31
|
+
hashManipFn(wordbuf);
|
32
|
+
i = 0;
|
33
|
+
}
|
34
|
+
} else {
|
35
|
+
wordbuf[i++] = *cp;
|
36
|
+
if (i == wordbufsize) {
|
37
|
+
wordbufsize *= 2;
|
38
|
+
if((wordbuf = realloc(wordbuf, wordbufsize + 1)) == NULL)
|
39
|
+
return(fprintf(stderr, "realloc\n"), 0);
|
40
|
+
}
|
41
|
+
}
|
42
|
+
}
|
43
|
+
|
44
|
+
free(wordbuf);
|
45
|
+
return(1);
|
46
|
+
}
|
47
|
+
|
48
|
+
void spellCheck(char *key) {
|
49
|
+
if (ht_find_new(dict,key)->val != 1) printf("%s\n",key);
|
50
|
+
}
|
51
|
+
|
52
|
+
void hashLoad(char *key) { ht_find_new(dict,key)->val = 1; }
|
53
|
+
|
54
|
+
int main(int argc, char *argv[]) {
|
55
|
+
FILE *fh;
|
56
|
+
int rc;
|
57
|
+
|
58
|
+
/*
|
59
|
+
ht_create doesn't handle malloc and calloc failures
|
60
|
+
so this is superfluous
|
61
|
+
*/
|
62
|
+
if((dict = ht_create(40000)) == NULL)
|
63
|
+
return(fprintf(stderr,"hash creation failed\n"),EXIT_FAILURE);
|
64
|
+
|
65
|
+
if ((fh = fopen("Usr.Dict.Words", "r")) == NULL)
|
66
|
+
return(fprintf(stderr,"couldn't open dictionary\n"),EXIT_FAILURE);
|
67
|
+
|
68
|
+
rc = ((handleInput(fh,hashLoad) && handleInput(stdin,spellCheck)) ? EXIT_SUCCESS : EXIT_FAILURE);
|
69
|
+
|
70
|
+
ht_destroy(dict);
|
71
|
+
return(rc);
|
72
|
+
}
|