Re: Code improvement for DNA reverse complement?

2017-05-19 Thread crimaniak via Digitalmars-d-learn
On Friday, 19 May 2017 at 12:55:05 UTC, Biotronic wrote: revComp6 seems to be the fastest, but it's probably also the least readable (a common trade-off). Try revComp7 with -release :) string revComp7(string bps) { char[] result = new char[bps.length]; auto p1 = result.ptr; auto p2

Re: "if" is not evaluated for fields of Class.tupleof

2017-05-19 Thread ag0aep6g via Digitalmars-d-learn
On 05/19/2017 03:46 PM, Timoses wrote: foreach (field; fields) { // Here it should actually not enter when field is mbyte (byte) if (isStaticArray!(typeof(field))) You probably want `static if` here. With normal `if`, the body still gets compiled,

"if" is not evaluated for fields of Class.tupleof

2017-05-19 Thread Timoses via Digitalmars-d-learn
Hey there, trying to read data into the fields of a class. This is what I got so far: ``` import std.traits; import std.bitmanip; class Test { byte[4] marray; byte mbyte; this(ubyte[] data) { auto fields = this.tupleof; foreach (field; fields) {

Re: Code improvement for DNA reverse complement?

2017-05-19 Thread ag0aep6g via Digitalmars-d-learn
On 05/19/2017 02:55 PM, Biotronic wrote: On Friday, 19 May 2017 at 12:21:10 UTC, biocyberman wrote: 1. Why do we need to use assumeUnique in 'revComp0' and 'revComp3'? D strings are immutable, so if I'd created the result array as a string, I couldn't change the individual characters.

Re: Code improvement for DNA reverse complement?

2017-05-19 Thread Nicholas Wilson via Digitalmars-d-learn
On Friday, 19 May 2017 at 12:21:10 UTC, biocyberman wrote: On Friday, 19 May 2017 at 09:17:04 UTC, Biotronic wrote: On Friday, 19 May 2017 at 07:29:44 UTC, biocyberman wrote: [...] Question about your implementation: you assume the input may contain newlines, but don't handle any other

Re: Getopt default int init and zero

2017-05-19 Thread Jonathan M Davis via Digitalmars-d-learn
On Friday, May 19, 2017 12:09:38 PM PDT Suliman via Digitalmars-d-learn wrote: > I would like to check if user specified `0` as getopt parameter. > But the problem that `int`'s are default in `0`. So if user did > not specified nothing `int x` will be zero, and all other code > will work as if

Re: Code improvement for DNA reverse complement?

2017-05-19 Thread Biotronic via Digitalmars-d-learn
On Friday, 19 May 2017 at 12:21:10 UTC, biocyberman wrote: 1. Why do we need to use assumeUnique in 'revComp0' and 'revComp3'? D strings are immutable, so if I'd created the result array as a string, I couldn't change the individual characters. Instead, I create a mutable array, change the

Re: Code improvement for DNA reverse complement?

2017-05-19 Thread biocyberman via Digitalmars-d-learn
On Friday, 19 May 2017 at 09:17:04 UTC, Biotronic wrote: On Friday, 19 May 2017 at 07:29:44 UTC, biocyberman wrote: [...] Question about your implementation: you assume the input may contain newlines, but don't handle any other non-ACGT characters. The problem definition states 'DNA string'

Getopt default int init and zero

2017-05-19 Thread Suliman via Digitalmars-d-learn
I would like to check if user specified `0` as getopt parameter. But the problem that `int`'s are default in `0`. So if user did not specified nothing `int x` will be zero, and all other code will work as if it's zero. In std.typecons I found Nullable that allow init int to zero. I tried to

Re: How to check a struct exists at a particular memory address?

2017-05-19 Thread Steven Schveighoffer via Digitalmars-d-learn
On 5/18/17 4:20 PM, Gary Willoughby wrote: This might be a really silly question but: I've allocated some memory like this (Foo is a struct): this._data = cast(Foo*) calloc(n, Foo.sizeof); How can I then later check that there is a valid Foo at `this._data` or `this._data + n`? The

Re: Code improvement for DNA reverse complement?

2017-05-19 Thread Biotronic via Digitalmars-d-learn
On Friday, 19 May 2017 at 07:29:44 UTC, biocyberman wrote: I am solving this problem http://rosalind.info/problems/revc/ as an exercise to learn D. This is my solution: https://dpaste.dzfl.pl/8aa667f962b7 Is there some D tricks I can use to make the `reverseComplement` function more concise

Re: Code improvement for DNA reverse complement?

2017-05-19 Thread biocyberman via Digitalmars-d-learn
On Friday, 19 May 2017 at 07:46:13 UTC, Stefan Koch wrote: On Friday, 19 May 2017 at 07:29:44 UTC, biocyberman wrote: I am solving this problem http://rosalind.info/problems/revc/ as an exercise to learn D. This is my solution: https://dpaste.dzfl.pl/8aa667f962b7 Is there some D tricks I can

Re: Code improvement for DNA reverse complement?

2017-05-19 Thread Stefan Koch via Digitalmars-d-learn
On Friday, 19 May 2017 at 07:29:44 UTC, biocyberman wrote: I am solving this problem http://rosalind.info/problems/revc/ as an exercise to learn D. This is my solution: https://dpaste.dzfl.pl/8aa667f962b7 Is there some D tricks I can use to make the `reverseComplement` function more concise

Code improvement for DNA reverse complement?

2017-05-19 Thread biocyberman via Digitalmars-d-learn
I am solving this problem http://rosalind.info/problems/revc/ as an exercise to learn D. This is my solution: https://dpaste.dzfl.pl/8aa667f962b7 Is there some D tricks I can use to make the `reverseComplement` function more concise and speedy? Any other comments for improvement of the whole