Too slow readln

2017-07-16 Thread unDEFER via Digitalmars-d-learn
Hello, there! I have the next "grep" code: https://dpaste.dzfl.pl/7b7273f96ab2 And I have the directory to run it: $ time /home/undefer/MyFiles/Projects/TEST/D/grep "HELLO" . ./strace.log: [pid 18365] write(1, "HELLO\n", 6HELLO real1m17.096s user0m54.828s sys 0m13.340s The same

Re: Too slow readln

2017-07-16 Thread unDEFER via Digitalmars-d-learn
On Sunday, 16 July 2017 at 17:37:34 UTC, Jon Degenhardt wrote: On Sunday, 16 July 2017 at 17:03:27 UTC, unDEFER wrote: [snip] How to write in D grep not slower than GNU grep? GNU grep is pretty fast, it's tough to beat it reading one line at a time. That's because it can play a bit of a

Re: Too slow readln

2017-07-16 Thread Jon Degenhardt via Digitalmars-d-learn
On Sunday, 16 July 2017 at 17:03:27 UTC, unDEFER wrote: [snip] How to write in D grep not slower than GNU grep? GNU grep is pretty fast, it's tough to beat it reading one line at a time. That's because it can play a bit of a trick and do the initial match ignoring line boundaries and

Re: Avoid if statements for checking neighboring indexes in a 2D array

2017-07-16 Thread Timon Gehr via Digitalmars-d-learn
On 16.07.2017 19:10, Timon Gehr wrote: ... (This works even if there are * at the border.) Well, not really. :) Version that actually works if there are * at the border: import std.stdio, std.range, std.algorithm, std.array; char[][] arr; int componentSize(int row,int col){

Re: Avoid if statements for checking neighboring indexes in a 2D array

2017-07-16 Thread Timon Gehr via Digitalmars-d-learn
On 16.07.2017 12:37, kerdemdemir wrote: My goal is to find connected components in a 2D array for example finding connected '*' chars below. x x x x x x x x x x x x x x * * x x x x * * x x x x x * * x * x x x x x There are two connected '*' group in

Re: Avoid if statements for checking neighboring indexes in a 2D array

2017-07-16 Thread Timon Gehr via Digitalmars-d-learn
On 16.07.2017 18:55, Timon Gehr wrote: On 16.07.2017 12:37, kerdemdemir wrote: My goal is to find connected components in a 2D array for example finding connected '*' chars below. x x x x x x x x x x x x x x * * x x x x * * x x x x x * * x * x x x x x

Re: Too slow readln

2017-07-16 Thread unDEFER via Digitalmars-d-learn
I understand the main problem. dirEntries by default follows symlinks. Without it my first grep works only 28.338s. That really cool!

Re: Avoid if statements for checking neighboring indexes in a 2D array

2017-07-16 Thread Nicholas Wilson via Digitalmars-d-learn
On Sunday, 16 July 2017 at 10:37:39 UTC, kerdemdemir wrote: My goal is to find connected components in a 2D array for example finding connected '*' chars below. x x x x x x x x x x x x x x * * x x x x * * x x x x x * * x * x x x x x There are two connected

Re: Avoid if statements for checking neighboring indexes in a 2D array

2017-07-16 Thread Ivan Kazmenko via Digitalmars-d-learn
On Sunday, 16 July 2017 at 10:37:39 UTC, kerdemdemir wrote: My goal is to find connected components in a 2D array for example finding connected '*' chars below. x x x x x x x x x x x x x x * * x x x x * * x x x x x * * x * x x x x x ... Is there any

Re: Avoid if statements for checking neighboring indexes in a 2D array

2017-07-16 Thread kerdemdemir via Digitalmars-d-learn
Hi Guys, @Nicholas , thanks a lot for cool solution but actually I weren't working on image processing. I was trying to solve "http://codeforces.com/contest/828/problem/B;. I really needed finding connected components this time. @Ivan, your solution is much more elegant than what I did. But

Re: Avoid if statements for checking neighboring indexes in a 2D array

2017-07-16 Thread kerdemdemir via Digitalmars-d-learn
Of course now I will try to have it work first. Than replace for loops with Cartesian product calls. Than I will make 2D array template and even maybe with random access range. And finally for being able to use this class later in the some other coding challenge I will make Searching( == 'W'

Re: Too slow readln

2017-07-16 Thread Ali Çehreli via Digitalmars-d-learn
On 07/16/2017 10:37 AM, Jon Degenhardt wrote: There's a good discussion in this thread ("Why GNU grep is fast" by Mike Haertel): https://lists.freebsd.org/pipermail/freebsd-current/2010-August/019310.html --Jon Another fast GNU utility was on Reddit a month ago:

Re: stacktrace for InvalidMemoryOperationError

2017-07-16 Thread crimaniak via Digitalmars-d-learn
On Saturday, 15 July 2017 at 18:14:13 UTC, Joakim wrote: core.exception.InvalidMemoryOperationError@src/core/exception.d(696): Invalid memory operation ... See the wiki page about this: https://wiki.dlang.org/InvalidMemoryOperationError If you can't do all that, look for places you might be

Re: Add property setting to chain

2017-07-16 Thread closescreen via Digitalmars-d-learn
Thanks for reply, Ali.

Avoid if statements for checking neighboring indexes in a 2D array

2017-07-16 Thread kerdemdemir via Digitalmars-d-learn
My goal is to find connected components in a 2D array for example finding connected '*' chars below. x x x x x x x x x x x x x x * * x x x x * * x x x x x * * x * x x x x x There are two connected '*' group in this example. First group is composes of six