reverse-complement Dart #3 program
source code
/* The Computer Language Benchmarks Game
http://benchmarksgame.alioth.debian.org/
Contributed by James Wendel
Modified by Anders Johnsen
*/
import 'dart:io';
void main() {
var src = "CGATMKRYVBHD";
var dst = "GCTAKMYRBVDH";
var tbl = new List<int>(256);
var seq = new List<int>();
// Set up lookup table
for (int i = 0; i < tbl.length; i++)
tbl[i] = i;
for (int i = 0; i < src.length; i++) {
tbl[src.codeUnitAt(i)] = dst.codeUnitAt(i);
tbl[src.toLowerCase().codeUnitAt(i)] = dst.codeUnitAt(i);
}
var buffer = new List<int>(60);
List<int> list = new List<int>();
bool commentLine = false;
StringBuffer sbuf = new StringBuffer();
stdin.listen((List<int> dataList) {
// Loop over all the contents of the buffer so far
for (int data in dataList) {
// Check if this is a comment line (and that we aren't already on a comment line)
if (data == 62 && !commentLine) {
int count = 0;
// Print the reverse components for the last block
for (int g in list.reversed) {
if (count == 60) {
sbuf.writeln(new String.fromCharCodes(buffer));
count=0;
}
buffer[count++] = g;
}
// Print any stragling data
if (count > 0) {
sbuf.writeln(new String.fromCharCodes(buffer.getRange(0, count)));
}
// Reset the data for the begining of a block of data
list.clear();
commentLine = true;
}
if (commentLine) {
if (data == 10) {
sbuf.write(new String.fromCharCodes(list));
print(sbuf);
sbuf = new StringBuffer();
commentLine = false;
list.clear();
} else {
list.add(data);
}
} else if (data != 10) {
// Add the complement to the buffer
list.add(tbl[data]);
}
}
}).onDone(() {
// Print out anything remaining in the buffers
if (commentLine) {
sbuf.write(new String.fromCharCodes(list));
} else {
int count = 0;
for (int data in list.reversed) {
if (count == 60) {
sbuf.writeln(new String.fromCharCodes(buffer));
count=0;
}
buffer[count++] = data;
}
if (count > 0) {
sbuf.write(new String.fromCharCodes(buffer.getRange(0, count)));
}
}
print(sbuf);
});
}
notes, command-line, and program output
NOTES:
64-bit Ubuntu quad core
Dart VM version: 1.24.2 (Thu Jun 22 08:43:26 2017) on "linux_x64"
Wed, 28 Mar 2018 00:41:34 GMT
MAKE:
make: 'revcomp.dart-3.dart_run' is up to date.
0.05s to complete and log all make actions
COMMAND LINE:
/opt/src/dartsdk-linux-x64-release/dart-sdk/bin/dart --old_gen_heap_size=3072 revcomp.dart-3.dart 0 < revcomp-input100000000.txt
PROGRAM FAILED
PROGRAM OUTPUT:
>ONE Homo sapiens alu
Exhausted heap space, trying to allocate 2147483680 bytes.
Unhandled exception:
Out of Memory
#0 main.<anonymous closure> (file:///home/dunham/benchmarksgame_quadcore/revcomp/tmp/revcomp.dart-3.dart:13:13)
#1 _RootZone.runUnaryGuarded (dart:async/zone.dart:1307)
#2 _FileStream._readBlock.<anonymous closure> (dart:io/file_impl.dart:238)
#3 _FutureListener.handleValue (dart:async/future_impl.dart)
#4 _Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:636)
#5 _Future._propagateToListeners (dart:async/future_impl.dart)
#6 _Future._completeWithValue (dart:async/future_impl.dart:478)
#7 _Future._asyncComplete.<anonymous closure> (dart:async/future_impl.dart:510)
#8 _microtaskLoop (dart:async/schedule_microtask.dart:41)
#9 _startMicrotaskLoop (dart:async/schedule_microtask.dart:50)
#10 _runPendingImmediateCallback (dart:isolate-patch/isolate_patch.dart:99)
#11 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:152)