d word counting approach performs well but has higher mem usage

2018-11-03 Thread dwdv via Digitalmars-d-learn
Hi there, the task is simple: count word occurrences from stdin (around 150mb in this case) and print sorted results to stdout in a somewhat idiomatic fashion. Now, d is quite elegant while maintaining high performance compared to both c and c++, but I, as a complete beginner, can't

Re: d word counting approach performs well but has higher mem usage

2018-11-04 Thread dwdv via Digitalmars-d-learn
Assoc array allocations? Yup. AAs do keep their memory around (supposedly for reuse). [...] Why it consumes so much is a question to the implementation. [...] I guess built-in AAs just love to hoard. What a darn shame. This way I'm missing out on all those slick internet benchmark points.

Re: Help with Regular Expressions (std.regex)

2019-03-04 Thread dwdv via Digitalmars-d-learn
On 3/3/19 7:07 PM, Samir via Digitalmars-d-learn wrote: I am belatedly working my way through the 2018 edition of the Advent of Code[1] programming challenges using D and am stumped on Problem 3[2]. The challenge requires you to parse a set of lines in the format: #99 @ 652,39: 24x23 #100 @

Re: Finding Max Value of Column in Multi-Dimesional Array

2019-07-05 Thread dwdv via Digitalmars-d-learn
On 7/5/19 9:56 PM, ag0aep6g via Digitalmars-d-learn wrote: On 05.07.19 20:49, Samir wrote: As a follow-on to my earlier question, is there a way to pass a variable to the `map` function that specifies the column, rather than hard-coding it?  I'm thinking of something like:

Re: Finding Max Value of Column in Multi-Dimesional Array

2019-07-05 Thread dwdv via Digitalmars-d-learn
On 7/5/19 9:56 PM, ag0aep6g via Digitalmars-d-learn wrote: On 05.07.19 20:49, Samir wrote: As a follow-on to my earlier question, is there a way to pass a variable to the `map` function that specifies the column, rather than hard-coding it?  I'm thinking of something like:

Re: wordladder - code improvement

2020-01-30 Thread dwdv via Digitalmars-d-learn
From one noob to another: Not much of a difference, but levenshteinDistance seems to be a good fit here. About as fast as your solution, slightly lower memory usage. byCodeUnit/byChar might shave off a few more ms. For small scripts like these I'm usually not even bothering with const

Re: wordladder - code improvement

2020-01-31 Thread dwdv via Digitalmars-d-learn
On 2020-01-31 09:44, mark via Digitalmars-d-learn wrote: I can't use the levenshtien distance because although it is a better solution, [...] Nah, it isn't, sorry for the noise, should have slept before sending the message, was thinking of hamming distance: auto a = "abcd"; auto b =

Re: Reading a file of words line by line

2020-01-15 Thread dwdv via Digitalmars-d-learn
On 2020-01-15 16:34, mark via Digitalmars-d-learn wrote: Is this as compact as it _reasonably_ can be? How about this? auto uniqueWords(string filename, uint wordsize) { import std.algorithm, std.array, std.conv, std.functional, std.uni; return File(filename).byLine

Re: Reading a file of words line by line

2020-01-16 Thread dwdv via Digitalmars-d-learn
On 2020-01-16 04:54, Jesse Phillips via Digitalmars-d-learn wrote: [...] .map!(word => word.to!string.toUpper) .array .sort .uniq .map!(x => tuple (x, 0)) .assocArray ; .each!(word => words[word.to!string.toUpper] = 0); isn't far off, but could also be (sans imports): return

Re: Using tasks without GC?

2020-01-04 Thread dwdv via Digitalmars-d-learn
Creates a Task on the GC heap that calls an alias. If possible, there's also scopedTask, which allocates on the stack: https://dlang.org/phobos/std_parallelism.html#.scopedTask So my question is: Has anyone done any analysis over how "dangerous" it is to use GC'd tasks for _small_ tasks (in

Re: Best way to learn 2d games with D?

2020-03-15 Thread dwdv via Digitalmars-d-learn
On 2020-03-15 18:58, Steven Schveighoffer via Digitalmars-d-learn wrote: I'd prefer to do it with D. How about raylib in conjunction with thin d bindings? I prefer it over sdl, sfml and the like. https://www.raylib.com/examples.html (make sure to enable js for embedded examples)