API Reference

type Handle , procedure Assign

   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

   procedure Clear (Bag : in out Handle);   

Makes Bag empty. All bags are initially empty.

Time: O(N).

procedure Add

   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

   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

   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

   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

   function Empty (Bag : Handle) return Boolean;   

Returns True if Bag contains no elements; returns False otherwise.

function Size

   function Size (Bag : Handle) return Natural;   

Returns the number of elements stored in Bag.

type Context_Data (<>) , with procedure Action , procedure Iterate

   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.