Re: Data structures and algorithms in D?
On Monday, 8 October 2018 at 13:47:44 UTC, Russel Winder wrote: The purpose of these books is for students to learn the academic material, not the creation of production libraries. Most programming language libraries have all the algorithms coded up in the libraries. And for those algorithms that are not, this level of textbook is rarely going to be the right tool to help the coding. The real question is then, does Phobos have all the right algorithms and data structures in it. It has Red-Black Tree, but I suspect not B-Tree, B+-Tree, or B*-Tree. Is this an issue? I see that Go and Rust are basically in the same boat, but they have: https://www.golangprograms.com/data-structure-and-algorithms.html https://github.com/EbTech/rust-algorithms respectively. Doing something similar for D might be worthwhile. Thank you Russel. I think it would be very worthwhile for D. For experienced developers it might not be an issue, but as you highlight, for anyone who is learning or taking an algorithms course such a resource would be useful. Borrowing from the rust-algorithms readme, this would be for: 1. Students and educators 2. Potentially for D programming advocacy 3. Serve as a quick reference for implementing basic algorithms and ideally improve on the same.
Re: Data structures and algorithms in D?
On Monday, 8 October 2018 at 05:18:35 UTC, bauss wrote: On Sunday, 7 October 2018 at 20:27:47 UTC, eastanon wrote: Are there reading resources on Data structures and Algorithms in D? There are several such books in the C/C++ and Java world and many senior/experienced D users might have come across them in C. But for people who join D after reading Ali's book, a data structures and algorithms book in D would be a great next step. i.e. a book that uses D's idioms and best practices. Any such material in development or recommended blog posts? http://ddili.org/ders/d.en/index.html Pretty sure it also covers stuff like that. But this is a great introductory book it is not a dedicated text on algorithms and data structures. Have you read it?
Data structures and algorithms in D?
Are there reading resources on Data structures and Algorithms in D? There are several such books in the C/C++ and Java world and many senior/experienced D users might have come across them in C. But for people who join D after reading Ali's book, a data structures and algorithms book in D would be a great next step. i.e. a book that uses D's idioms and best practices. Any such material in development or recommended blog posts?
Is there a suffix tree or suffix array implementations in D
Maybe I have not searched well, but I am wondering whether there are suffix tree or suffix array implementations in D. I have seen a couple from other programming languages and before I translate one to D, there could be a something existing already.
determining if array element is null
Does D array implementation support an array of null values? int a[4] = null; But I ran into a type error while checking if a[i] is null foreach(i; 0..3){ if(i == null){ writeln("it is null"); } } } How do you set fixed size array of null values and check if they are null?
Re: What's the purpose of the 'in' keyword ?
On Sunday, 27 May 2018 at 16:00:15 UTC, Jonathan M Davis wrote: On Sunday, May 27, 2018 16:28:56 Russel Winder via Digitalmars-d-learn wrote: [...] Honestly, I'd suggest that folks never use in at this point. There's zero benefit to it. In principle, in was supposed to be const scope, but scope has never really done anything for anything other than delegates, so there has been no reason to use it over const. However, many folks seem to like it based on the idea that it was the opposite of out - and some folks used it based n what they expected scope to end up meaning whenever it finally got implemented for more than just delegates. Either way, it didn't actually buy them anything as long as scope has done nothing. [...] I really find these type of descriptions to be really useful and insightful. Going through the D textbooks can leave someone a little confused on when to use what and where? D has so many keywords and as a beginner it can be overwhelming. Thank you for your insights.
Looking for a mentor in D
I have been reading the D forums for a while and following on its amazing progress for a long time. Over time I have even written some basic D programs for myself, nothing major or earth shuttering. I have downloaded and read Ali's excellent book. I would like to dive deeper into D, however sometimes it can get intimidating when I read some of the discussions on the forums and I realise I know nothing. People argue on and on about a feature or lack of and the future of the language and it starts to cast doubts on my desire to learn and be proficient in D. I would like to choose D as my go to language and to do that I realise I need a mentor, someone who will walk and guide me and not get irritated by basic questions. I am pretty much a DIY person, so don't worry about mundane issues. I want to have someone with whom I can discuss some practical choices and algorithms. I am a self-taught programmer and never took CS classes. I am good in R, Python and Ruby. Please let me know if you would like to be a D mentor.
Re: parsing fastq files with D
On Thursday, 24 March 2016 at 06:34:51 UTC, rikki cattermole wrote: void popFront() { import std.string : indexOf; if (source is null) { isEmpty = true; return; } void tidyInput() { foreach(i, c; source) { switch(c) { case 0: .. case ' ': break; default: source = source[i .. $]; return; } } source = null; } tidyInput(); Do you mind to explain what is really going on at popFront() and tidyInput() functions?
Re: parsing fastq files with D
On Thursday, 24 March 2016 at 13:38:32 UTC, Marc Schütz wrote: Yes, it's read into your processes memory. You can use std.mmfile [1] to make things a bit more efficient. It will, too, read the data into memory, but it will do so in a way (memory mapping) that only loads what is actually accessed (everything in your case), and that allows the operating system to efficiently release and reload parts of it if memory runs low. Unfortunately there is no example in the documentation, but it works like this (untested): import std.mmfile; auto file = new MmFile(inputfile); string text = cast(string) file[]; ... [1] http://dlang.org/phobos/std_mmfile.html That is very clever. Thank you for the tip and I have implemented it and it works. I feel like it is a safer way of reading a file.
Re: parsing fastq files with D
On Thursday, 24 March 2016 at 06:34:51 UTC, rikki cattermole wrote: As a little fun thing to do I implemented it for you. It won't allocate. Making this perfect for you. With a bit of work you could make Result have buffers for result instead of using the input array allow for the source to be an input range itself. I made this up on dpaste and single quotes were not playing nicely there. So you'll see "\r"[0] as a workaround. Thank you very much. I think you have exposed me to a number of new concepts that I will go through and annotate the code with. I read all input from file as follows. string text = cast(string)std.file.read(inputfile); foreach(record;FastQRecord.parse(text)){ writeln(record); } Does this mean that text is allocated to memory? and is there a better way to read and process the inputfile?
parsing fastq files with D
Fastq is a format for storing DNA sequences together with the associated quality information often encoded in ascii characters. It is typically made of 4 lines for example 2 fastq entries would look like this. @seq1 TTAAAT + ?+BBB/DHH@ @seq2 GACCCTTTGCA + ?+BHB/DIH@ I do not have a lot of D expirience and I am writing a simple parser to help work with these files. Ideally it should be fast with low memory footprint. I am working with very large files of this type and can be up to 1GB. module fastq; import std.stdio; import std.file; import std.exception; import std.algorithm; import std.string; struct Record{ string sequence; string quals; string name; } auto Records(string filename){ static auto toRecords(S)(S str){ auto res = findSplitBefore(str,"+\n"); auto seq = res[0]; auto qual = res[1]; return Record(seq,qual); } string text = cast(string)std.file.read(filename); enforce(text.length > 0 && text[0] == '@'); text = text[1 .. $]; auto entries = splitter(text,'@'); return map!toRecords(entries); } The issue with this is that the "+" character can be part of the quality information and I am using it to split the quality information from the sequence information. and ends up splitting the quality information which is wrong. Ideally I do not want to use regex and I have heard of ragel for parsing but never used it. Such a solution would also be welcome, since I read it can be very fast. Which is the idiomatic way to capture, sequence name (starts with @ character and the first entry) the sequence, (line2) the quality scores( line 4)