Re: Elegant way to test if members of array A are present in array B?

2019-06-14 Thread Robert M. Münch via Digitalmars-d-learn
On 2019-06-12 13:58:49 +, Meta said: There are two versions of find that can find a range within another: https://dlang.org/phobos/std_algorithm_searching.html#.find https://dlang.org/phobos/std_algorithm_searching.html#.find.3 Thanks, that looks good. I read the find docs, but somehow

Re: Elegant way to test if members of array A are present in array B?

2019-06-12 Thread Paul Backus via Digitalmars-d-learn
On Wednesday, 12 June 2019 at 06:57:55 UTC, Robert M. Münch wrote: If you use an associative array or a set, it's O(n) time and O(n) space. I don't see how this is the case. The AA itself has some overhead too. So, the checking loop is O(n) but the AA lookups not. Hash table insertion and

Re: Elegant way to test if members of array A are present in array B?

2019-06-12 Thread Meta via Digitalmars-d-learn
On Tuesday, 11 June 2019 at 17:12:17 UTC, Robert M. Münch wrote: Is there a simple and elegant way to do this? Or is just using a foreach(...) with canFind() the best way? There are two versions of find that can find a range within another:

Re: Elegant way to test if members of array A are present in array B?

2019-06-12 Thread Robert M. Münch via Digitalmars-d-learn
On 2019-06-11 17:34:00 +, Paul Backus said: It's a space/time tradeoff. foreach with canFind is O(n^2) time and O(1) space. Yes, that's why I asekd. They haystack is most likely >10 times larger than the needles. Speed has priority. If you use an associative array or a set, it's O(n)

Re: Elegant way to test if members of array A are present in array B?

2019-06-11 Thread Murilo via Digitalmars-d-learn
On Tuesday, 11 June 2019 at 17:12:17 UTC, Robert M. Münch wrote: Is there a simple and elegant way to do this? Or is just using a foreach(...) with canFind() the best way? I made it this way, I consider it elegant. I don't know if others will like it. Here it is: import std.stdio : writeln;

Re: Elegant way to test if members of array A are present in array B?

2019-06-11 Thread KnightMare via Digitalmars-d-learn
On Tuesday, 11 June 2019 at 18:39:38 UTC, KnightMare wrote: probably strstr https://dlang.org/library/core/stdc/string/strstr.html implemented over it. there is a tendency to remove dependency from C-runtime. *FIX* strpbrk https://dlang.org/phobos/core_stdc_string.html#.strpbrk

Re: Elegant way to test if members of array A are present in array B?

2019-06-11 Thread KnightMare via Digitalmars-d-learn
On Tuesday, 11 June 2019 at 17:12:17 UTC, Robert M. Münch wrote: Is there a simple and elegant way to do this? Or is just using a foreach(...) with canFind() the best way? not elegant, not simple. for byte/short/ubye/ushort only https://www.strchr.com/strcmp_and_strlen_using_sse_4.2

Re: Elegant way to test if members of array A are present in array B?

2019-06-11 Thread Paul Backus via Digitalmars-d-learn
On Tuesday, 11 June 2019 at 17:12:17 UTC, Robert M. Münch wrote: Is there a simple and elegant way to do this? Or is just using a foreach(...) with canFind() the best way? It's a space/time tradeoff. foreach with canFind is O(n^2) time and O(1) space. If you use an associative array or a set,

Re: Elegant way to test if members of array A are present in array B?

2019-06-11 Thread Alex via Digitalmars-d-learn
On Tuesday, 11 June 2019 at 17:12:17 UTC, Robert M. Münch wrote: Is there a simple and elegant way to do this? Or is just using a foreach(...) with canFind() the best way? There is also find_among, but the performance is the same, I assume.

Elegant way to test if members of array A are present in array B?

2019-06-11 Thread Robert M. Münch via Digitalmars-d-learn
Is there a simple and elegant way to do this? Or is just using a foreach(...) with canFind() the best way? -- Robert M. Münch http://www.saphirion.com smarter | better | faster