AdaPower Logged in as Guest
Ada Tools and Resources

Ada 95 Reference Manual
Ada Source Code Treasury
Bindings and Packages
Ada FAQ


Join >
Articles >
Ada FAQ >
Getting Started >
Home >
Books & Tutorials >
Source Treasury >
Packages for Reuse >
Latest Additions >
Ada Projects >
Press Releases >
Ada Audio / Video >
Home Pages >
Links >
Contact >
About >
Login >
Back
Sets in Ada (T.E.D)

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...


(c) 1998-2004 All Rights Reserved David Botton