reverse-complement Dart #2 program
source code
/* The Computer Language Benchmarks Game
https://salsa.debian.org/benchmarksgame-team/benchmarksgame/
Contributed by James Wendel
*/
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.write(new String.fromCharCodes(buffer.getRange(0, count)));
sbuf.write('\n');
count=0;
}
buffer[count++] = g;
}
// Print any stragling data
if (count > 0) {
sbuf.write(new String.fromCharCodes(buffer.getRange(0, count)));
sbuf.write('\n');
}
// 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.write(new String.fromCharCodes(buffer.getRange(0, count)));
sbuf.write('\n');
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: 2.8.1 (stable) (Unknown timestamp) on "linux_x64"
Wed, 06 May 2020 20:15:57 GMT
MAKE:
/usr/bin/dartanalyzer revcomp.dart-2.dart
make: /usr/bin/dartanalyzer: Command not found
make: [/home/dunham/8000-benchmarksgame/nanobench/makefiles/u64q.programs.Makefile:445: revcomp.dart-2.dart_run] Error 127 (ignored)
0.13s to complete and log all make actions
COMMAND LINE:
/usr/bin/dart --old_gen_heap_size=3072 revcomp.dart-2.dart 0 < revcomp-input100000000.txt
PROGRAM FAILED
PROGRAM OUTPUT:
>ONE Homo sapiens alu
Exhausted heap space, trying to allocate 2147483664 bytes.
Unhandled exception:
Out of Memory
#0 List._allocateData (dart:core-patch/growable_array.dart)
#1 List._grow (dart:core-patch/growable_array.dart:250:19)
#2 main.<anonymous closure> (file:///home/dunham/benchmarksgame_quadcore/revcomp/tmp/revcomp.dart-2.dart:93:2229)
#3 _RootZone.runUnaryGuarded (dart:async/zone.dart:1374:10)
#4 _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:339:11)
#5 _BufferingStreamSubscription._add (dart:async/stream_impl.dart:266:7)
#6 _SyncStreamControllerDispatch._sendData (dart:async/stream_controller.dart:779:19)
#7 _StreamController._add (dart:async/stream_controller.dart:655:7)
#8 _StreamController.add (dart:async/stream_controller.dart:597:5)
#9 _FileStream._readBlock.<anonymous closure> (dart:io/file_impl.dart:105:19)
#10 _RootZone.runUnary (dart:async/zone.dart:1439:54)
#11 _FutureListener.handleValue (dart:async/future_impl.dart:141:18)
#12 Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:682:45)
#13 Future._propagateToListeners (dart:async/future_impl.dart:711:32)
#14 Future._completeWithValue (dart:async/future_impl.dart:526:5)
#15 Future._asyncComplete.<anonymous closure> (dart:async/future_impl.dart:556:7)
#16 _microtaskLoop (dart:async/schedule_microtask.dart:43:21)
#17 _startMicrotaskLoop (dart:async/schedule_microtask.dart:52:5)
#18 _runPendingImmediateCallback (dart:isolate-patch/isolate_patch.dart:118:13)
#19 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:169:5)