|ASCL User's Guide: ASCL, ADA Standard Component Library; Version 0.1.0; Document Revision $Revision: 1.7 $|
|Prev||Chapter 25. ASCL.Data_Structures.Bag_Unbounded||Next|
package Implementation is new ASCL.Data_Structures.Bag_Unbounded_Unprotected (Element => Element, "=" => "="); type Find_Result (Found : Boolean := False) is record
Type returned by Find.
Used to provide context data to Iterate
type Action_Ptr is access procedure (Item : in out Element; Context : in out Context_Data'Class; Continue : out Boolean);
We can't have a generic protected subprogram, so we use this type to implement Iterate. This means that the actual procedure passed to Iterate must be declared at the library level to pass accessibility checks.
Makes the bag empty. All bags are initially empty.
procedure Add (Item : in Element);
Adds Item to the bag.
Raises Storage_Exhausted if we cannot obtain memory to store Item in the bag.
The bag is unchanged if Storage_Exhausted is raised.
procedure Delete (Item : in Element);
If the bag contains an Element X such that X = Item, deletes X from the bag; otherwise, has no effect.
If the bag contains more than one such Element, deletes one of these Elements.
procedure Update (Item : in Element);
If the bag contains an Element X such that X = Item, performs
X := Item;
otherwise, has no effect.
If the bag contains more than one such Element, updates one of these Elements.
function Find (Key : Element) return Find_Result;
If the bag contains an Element X such that X = Key, returns (Found => True, Item => X); otherwise, returns (Found => False). If the bag contains more than one such Element, returns one of these Elements as the Item component of the result.
function Empty return Boolean;
Returns True if the bag contains no elements; returns False otherwise.
function Size return Natural;
Returns the number of elements stored in the bag.
procedure Iterate (Action : in Action_Ptr; Context : in out Context_Data'Class);
Applies Action to each Element in the bag in some unspecified order, until either
1. Action sets Continue to False, or
2. Every Element in the bag has been processed.