Intersection of two sets

ikod igor.khasilev at gmail.com
Tue Dec 3 15:14:03 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]`?
> 2) Are there some build-in function for handling such sets?

Never tried, but depending of the nature of your "something" you 
can try bit sets. There are efficient algorithms for large bit 
arrays (see "roaring" for example).


More information about the Digitalmars-d-learn mailing list