Intersection of two sets
Alex
sascha.orlov at gmail.com
Tue Dec 3 13:55:51 UTC 2019
On Tuesday, 3 December 2019 at 13:43:26 UTC, Jan Hönig wrote:
> It seems i don't google the right keywords.
>
> What i want to do: I have two sets. (I didn't find how to do
> sets, so i have two associative boolean arrays
> `bool[<something>]`). And i want to join them, via an
> intersection.
>
> I know how to code this. Loop over one AA, if the key is also
> in the other one, we add that to the third array which is going
> to be returned.
>
> pseudocode:
> alias set = bool[<something>]
> set foo = ...
> set bar = ...
> set result;
>
> foreach(key; foo)
> {
> if (key in bar)
> {
> result[key] = true;
> }
> }
> return result;
>
>
> 1) Is there a better way for creating a set, other then `alias
> set = bool[keyClass]`?
This depends on the available accesses on your sets. In terms of
ranges:
Are your sets InputRanges, ForwardRange, ... ?
> 2) Are there some build-in function for handling such sets?
This is maybe what you are looking for:
https://dlang.org/phobos/std_algorithm_setops.html
More information about the Digitalmars-d-learn
mailing list