Back in the Ada 83 days I looked into creating a reusable set package, along
the lines of the SET type available for Pascal and Modula-2. What I quickly
discovered was that Ada's support for Boolean operations on arrays of booleans
made it completely unnessecary. For all intents and purposes, you *do* have a
set type in Ada!
Example:
type Color is (Red, Green, Blue, Black, Teal);
type Color_Set is array (Color) of Boolean;
Palette : Color_Set;
Inclusion:
if Palette(Red) then ...
Intersection:
Colorblind_Palette := Palette and Colorblind_Visible_Colors;
Union:
Palette := Palette or Colors_At_The_Artshop;
Negation:
Unavailable_Colors := not Palette;
etc.
Admittedly, an implementation of a very large sparse set using only boolean
arrays is not the best way to go. But I have yet to ever need that
functionality myself...
|