"="'Result =
(E_Elements_Included (Elements (Left), Elements (Right))
and E_Elements_Included (Elements (Right), Elements (Left)));
+ -- For each element in Left, set equality attempts to find the equal
+ -- element in Right; if a search fails, then set equality immediately
+ -- returns False. The search works by calling Hash to find the bucket in
+ -- the Right set that corresponds to the Left element. If the bucket is
+ -- non-empty, the search calls the generic formal element equality operator
+ -- to compare the element (in Left) to the element of each node in the
+ -- bucket (in Right); the search terminates when a matching node in the
+ -- bucket is found, or the nodes in the bucket are exhausted. (Note that
+ -- element equality is called here, not Equivalent_Elements. Set equality
+ -- is the only operation in which element equality is used. Compare set
+ -- equality to Equivalent_Sets, which does call Equivalent_Elements.)
function Equivalent_Sets (Left, Right : Set) return Boolean with
Global => null,
Post => Equivalent_Sets'Result = (Model (Left) = Model (Right));
+ -- Similar to set equality, with the difference that the element in Left is
+ -- compared to the elements in Right using the generic formal
+ -- Equivalent_Elements operation instead of element equality.
function To_Set (New_Item : Element_Type) return Set with
Global => null,
M.Is_Singleton (Model (To_Set'Result), New_Item)
and Length (To_Set'Result) = 1
and E.Get (Elements (To_Set'Result), 1) = New_Item;
+ -- Constructs a singleton set comprising New_Element. To_Set calls Hash to
+ -- determine the bucket for New_Item.
function Capacity (Container : Set) return Count_Type with
Global => null,
Post => Capacity'Result = Container.Capacity;
+ -- Returns the current capacity of the set. Capacity is the maximum length
+ -- before which rehashing in guaranteed not to occur.
procedure Reserve_Capacity
(Container : in out Set;
(Elements (Container), Elements (Container)'Old)
and E_Elements_Included
(Elements (Container)'Old, Elements (Container));
+ -- If the value of the Capacity actual parameter is less or equal to
+ -- Container.Capacity, then the operation has no effect. Otherwise it
+ -- raises Capacity_Error (as no expansion of capacity is possible for a
+ -- bounded form).
function Is_Empty (Container : Set) return Boolean with
Global => null,
Post => Is_Empty'Result = (Length (Container) = 0);
+ -- Equivalent to Length (Container) = 0
procedure Clear (Container : in out Set) with
Global => null,
Post => Length (Container) = 0 and M.Is_Empty (Model (Container));
+ -- Removes all of the items from the set. This will deallocate all memory
+ -- associated with this set.
procedure Assign (Target : in out Set; Source : Set) with
Global => null,
and E_Elements_Included (Elements (Target), Elements (Source))
and E_Elements_Included (Elements (Source), Elements (Target));
+ -- If Target denotes the same object as Source, then the operation has no
+ -- effect. If the Target capacity is less than the Source length, then
+ -- Assign raises Capacity_Error. Otherwise, Assign clears Target and then
+ -- copies the (active) elements from Source to Target.
function Copy
(Source : Set;
Copy'Result.Capacity = Source.Capacity
else
Copy'Result.Capacity = Capacity);
+ -- Constructs a new set object whose elements correspond to Source. If the
+ -- Capacity parameter is 0, then the capacity of the result is the same as
+ -- the length of Source. If the Capacity parameter is equal or greater than
+ -- the length of Source, then the capacity of the result is the specified
+ -- value. Otherwise, Copy raises Capacity_Error. If the Modulus parameter
+ -- is 0, then the modulus of the result is the value returned by a call to
+ -- Default_Modulus with the capacity parameter determined as above;
+ -- otherwise the modulus of the result is the specified value.
function Element
(Container : Set;
and E_Elements_Included (Elements (Target), Elements (Source)'Old)
and E_Elements_Included (Elements (Source)'Old, Elements (Target));
+ -- Clears Target (if it's not empty), and then moves (not copies) the
+ -- buckets array and nodes from Source to Target.
procedure Insert
(Container : in out Set;
(Positions (Container),
Positions (Container)'Old,
Position));
+ -- Conditionally inserts New_Item into the set. If New_Item is already in
+ -- the set, then Inserted returns False and Position designates the node
+ -- containing the existing element (which is not modified). If New_Item is
+ -- not already in the set, then Inserted returns True and Position
+ -- designates the newly-inserted node containing New_Item. The search for
+ -- an existing element works as follows. Hash is called to determine
+ -- New_Item's bucket; if the bucket is non-empty, then Equivalent_Elements
+ -- is called to compare New_Item to the element of each node in that
+ -- bucket. If the bucket is empty, or there were no equivalent elements in
+ -- the bucket, the search "fails" and the New_Item is inserted in the set
+ -- (and Inserted returns True); otherwise, the search "succeeds" (and
+ -- Inserted returns False).
procedure Insert (Container : in out Set; New_Item : Element_Type) with
Global => null,
(Positions (Container),
Positions (Container)'Old,
Find (Container, New_Item));
+ -- Attempts to insert New_Item into the set, performing the usual insertion
+ -- search (which involves calling both Hash and Equivalent_Elements); if
+ -- the search succeeds (New_Item is equivalent to an element already in the
+ -- set, and so was not inserted), then this operation raises
+ -- Constraint_Error. (This version of Insert is similar to Replace, but
+ -- having the opposite exception behavior. It is intended for use when you
+ -- want to assert that the item is not already in the set.)
procedure Include (Container : in out Set; New_Item : Element_Type) with
Global => null,
(Positions (Container),
Positions (Container)'Old,
Find (Container, New_Item)));
+ -- Attempts to insert New_Item into the set. If an element equivalent to
+ -- New_Item is already in the set (the insertion search succeeded, and
+ -- hence New_Item was not inserted), then the value of New_Item is assigned
+ -- to the existing element. (This insertion operation only raises an
+ -- exception if cursor tampering occurs. It is intended for use when you
+ -- want to insert the item in the set, and you don't care whether an
+ -- equivalent element is already present.)
procedure Replace (Container : in out Set; New_Item : Element_Type) with
Global => null,
(Elements (Container)'Old,
Elements (Container),
P.Get (Positions (Container), Find (Container, New_Item)));
+ -- Searches for New_Item in the set; if the search fails (because an
+ -- equivalent element was not in the set), then it raises
+ -- Constraint_Error. Otherwise, the existing element is assigned the value
+ -- New_Item. (This is similar to Insert, but with the opposite exception
+ -- behavior. It is intended for use when you want to assert that the item
+ -- is already in the set.)
procedure Exclude (Container : in out Set; Item : Element_Type) with
Global => null,
(Positions (Container)'Old,
Positions (Container),
Find (Container, Item)'Old));
+ -- Searches for Item in the set, and if found, removes its node from the
+ -- set and then deallocates it. The search works as follows. The operation
+ -- calls Hash to determine the item's bucket; if the bucket is not empty,
+ -- it calls Equivalent_Elements to compare Item to the element of each node
+ -- in the bucket. (This is the deletion analog of Include. It is intended
+ -- for use when you want to remove the item from the set, but don't care
+ -- whether the item is already in the set.)
procedure Delete (Container : in out Set; Item : Element_Type) with
Global => null,
(Positions (Container)'Old,
Positions (Container),
Find (Container, Item)'Old);
+ -- Searches for Item in the set (which involves calling both Hash and
+ -- Equivalent_Elements). If the search fails, then the operation raises
+ -- Constraint_Error. Otherwise it removes the node from the set and then
+ -- deallocates it. (This is the deletion analog of non-conditional
+ -- Insert. It is intended for use when you want to assert that the item is
+ -- already in the set.)
procedure Delete (Container : in out Set; Position : in out Cursor) with
Global => null,
(Positions (Container)'Old,
Positions (Container),
Position'Old);
+ -- Removes the node designated by Position from the set, and then
+ -- deallocates the node. The operation calls Hash to determine the bucket,
+ -- and then compares Position to each node in the bucket until there's a
+ -- match (it does not call Equivalent_Elements).
procedure Union (Target : in out Set; Source : Set) with
Global => null,
E_Right => Elements (Target),
P_Left => Positions (Target)'Old,
P_Right => Positions (Target));
+ -- Iterates over the Source set, and conditionally inserts each element
+ -- into Target.
function Union (Left, Right : Set) return Set with
Global => null,
Model (Left),
Elements (Right),
Elements (Union'Result));
+ -- The operation first copies the Left set to the result, and then iterates
+ -- over the Right set to conditionally insert each element into the result.
function "or" (Left, Right : Set) return Set renames Union;
E_Right => Elements (Target)'Old,
P_Left => Positions (Target),
P_Right => Positions (Target)'Old);
+ -- Iterates over the Target set (calling First and Next), calling Find to
+ -- determine whether the element is in Source. If an equivalent element is
+ -- not found in Source, the element is deleted from Target.
function Intersection (Left, Right : Set) return Set with
Global => null,
and E_Elements_Included
(Elements (Left), Model (Right),
Elements (Intersection'Result));
+ -- Iterates over the Left set, calling Find to determine whether the
+ -- element is in Right. If an equivalent element is found, it is inserted
+ -- into the result set.
function "and" (Left, Right : Set) return Set renames Intersection;
E_Right => Elements (Target)'Old,
P_Left => Positions (Target),
P_Right => Positions (Target)'Old);
+ -- Iterates over the Source (calling First and Next), calling Find to
+ -- determine whether the element is in Target. If an equivalent element is
+ -- found, it is deleted from Target.
function Difference (Left, Right : Set) return Set with
Global => null,
(Elements (Left),
Model (Difference'Result),
Elements (Difference'Result));
+ -- Iterates over the Left set, calling Find to determine whether the
+ -- element is in the Right set. If an equivalent element is not found, the
+ -- element is inserted into the result set.
function "-" (Left, Right : Set) return Set renames Difference;
and E_Elements_Included
(Elements (Source), Model (Target), Elements (Target));
+ -- The operation iterates over the Source set, searching for the element
+ -- in Target (calling Hash and Equivalent_Elements). If an equivalent
+ -- element is found, it is removed from Target; otherwise it is inserted
+ -- into Target.
function Symmetric_Difference (Left, Right : Set) return Set with
Global => null,
(Elements (Right),
Model (Symmetric_Difference'Result),
Elements (Symmetric_Difference'Result));
+ -- The operation first iterates over the Left set. It calls Find to
+ -- determine whether the element is in the Right set. If no equivalent
+ -- element is found, the element from Left is inserted into the result. The
+ -- operation then iterates over the Right set, to determine whether the
+ -- element is in the Left set. If no equivalent element is found, the Right
+ -- element is inserted into the result.
function "xor" (Left, Right : Set) return Set
renames Symmetric_Difference;
Global => null,
Post =>
Overlap'Result = not (M.No_Overlap (Model (Left), Model (Right)));
+ -- Iterates over the Left set (calling First and Next), calling Find to
+ -- determine whether the element is in the Right set. If an equivalent
+ -- element is found, the operation immediately returns True. The operation
+ -- returns False if the iteration over Left terminates without finding any
+ -- equivalent element in Right.
function Is_Subset (Subset : Set; Of_Set : Set) return Boolean with
Global => null,
Post => Is_Subset'Result = (Model (Subset) <= Model (Of_Set));
+ -- Iterates over Subset (calling First and Next), calling Find to determine
+ -- whether the element is in Of_Set. If no equivalent element is found in
+ -- Of_Set, the operation immediately returns False. The operation returns
+ -- True if the iteration over Subset terminates without finding an element
+ -- not in Of_Set (that is, every element in Subset is equivalent to an
+ -- element in Of_Set).
function First (Container : Set) return Cursor with
Global => null,
others =>
Has_Element (Container, First'Result)
and P.Get (Positions (Container), First'Result) = 1);
+ -- Returns a cursor that designates the first non-empty bucket, by
+ -- searching from the beginning of the buckets array.
function Next (Container : Set; Position : Cursor) return Cursor with
Global => null,
Has_Element (Container, Next'Result)
and then P.Get (Positions (Container), Next'Result) =
P.Get (Positions (Container), Position) + 1);
+ -- Returns a cursor that designates the node that follows the current one
+ -- designated by Position. If Position designates the last node in its
+ -- bucket, the operation calls Hash to compute the index of this bucket,
+ -- and searches the buckets array for the first non-empty bucket, starting
+ -- from that index; otherwise, it simply follows the link to the next node
+ -- in the same bucket.
procedure Next (Container : Set; Position : in out Cursor) with
Global => null,
Has_Element (Container, Position)
and then P.Get (Positions (Container), Position) =
P.Get (Positions (Container), Position'Old) + 1);
+ -- Equivalent to Position := Next (Position)
function Find
(Container : Set;
and Equivalent_Elements
(Element (Container, Find'Result), Item));
+ -- Searches for Item in the set. Find calls Hash to determine the item's
+ -- bucket; if the bucket is not empty, it calls Equivalent_Elements to
+ -- compare Item to each element in the bucket. If the search succeeds, Find
+ -- returns a cursor designating the node containing the equivalent element;
+ -- otherwise, it returns No_Element.
function Contains (Container : Set; Item : Element_Type) return Boolean with
Global => null,