API Reference

type Find_Result (Found : Boolean := False)

  
   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

   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.

procedure Clear;

      procedure Clear;   

Makes the bag empty. All bags are initially empty.

Time: O(N).

procedure Add

      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.

Time: O(1).

procedure Delete

      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.

Time: O(N).

procedure Update

      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

      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

      function Empty return Boolean;   

Returns True if the bag contains no elements; returns False otherwise.

function Size

      function Size return Natural;   

Returns the number of elements stored in the bag.

procedure Iterate

      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.