| ASCL User's Guide: ASCL, ADA Standard Component Library; Version 0.1.0; Document Revision $Revision: 1.7 $ | ||
|---|---|---|
| Prev | Chapter 26. ASCL.Data_Structures.Bag_Unbounded_Unprotected | Next |
type Handle is limited private; -- Intial value: Empty. procedure Assign (To : out Handle; From : in Handle);
Makes To a copy of From.
May raise Storage_Exhausted.
The state of To is undefined if Storage_Exhausted is raised.
procedure Clear (Bag : in out Handle);
Makes Bag empty. All bags are initially empty.
Time: O(N).
procedure Add (Item : in Element; Into : in out Handle);
Adds Item to Into.
Raises Storage_Exhausted if we cannot obtain memory to store Item in Into. Into is unchanged if Storage_Exhausted is raised.
Time: O(1).
procedure Delete (Item : in Element; From : in out Handle);
If From contains an Element X such that X = Item, deletes X from From; otherwise, has no effect.
If From contains more than one such Element, deletes one of these Elements.
Time: O(N).
procedure Update (Item : in Element; Bag : in out Handle);
If Bag contains an Element X such that X = Item, performs X := Item; otherwise, has no effect.
If Bag contains more than one such Element, updates one of these Elements.
function Find (Key : Element; Bag : Handle) return Find_Result;
If Bag contains an Element X such that X = Key, returns (Found => True, Item => X); otherwise, returns (Found => False). If Bag contains more than one such Element, returns one of these Elements as the Item component of the result.
function Empty (Bag : Handle) return Boolean;
Returns True if Bag contains no elements; returns False otherwise.
function Size (Bag : Handle) return Natural;
Returns the number of elements stored in Bag.
generic -- Iterate
type Context_Data (<>) is limited private;
with procedure Action (Item : in out Element;
Context : in out Context_Data;
Continue : out Boolean);
procedure Iterate (Over : in out Handle; Context : in out Context_Data); 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.