Commit 0347c01b by Raphael Amiard Committed by Pierre-Marie de Rodat

[Ada] Update Ada.Containers.Hashed_Maps documentation with Ada RM doc.

2018-05-24  Raphael Amiard  <amiard@adacore.com>

gcc/ada/

	* libgnat/a-cohama.ads: Add documentation.

From-SVN: r260656
parent 8f1b88f8
2018-05-24 Raphael Amiard <amiard@adacore.com> 2018-05-24 Raphael Amiard <amiard@adacore.com>
* libgnat/a-cohama.ads: Add documentation.
2018-05-24 Raphael Amiard <amiard@adacore.com>
* libgnat/a-convec.ads: Add documentation. * libgnat/a-convec.ads: Add documentation.
2018-05-24 Justin Squirek <squirek@adacore.com> 2018-05-24 Justin Squirek <squirek@adacore.com>
......
...@@ -37,14 +37,57 @@ private with Ada.Containers.Hash_Tables; ...@@ -37,14 +37,57 @@ private with Ada.Containers.Hash_Tables;
private with Ada.Finalization; private with Ada.Finalization;
private with Ada.Streams; private with Ada.Streams;
-- The language-defined generic package Containers.Hashed_Maps provides
-- private types Map and Cursor, and a set of operations for each type. A map
-- container allows an arbitrary type to be used as a key to find the element
-- associated with that key. A hashed map uses a hash function to organize the
-- keys.
--
-- A map contains pairs of keys and elements, called nodes. Map cursors
-- designate nodes, but also can be thought of as designating an element (the
-- element contained in the node) for consistency with the other containers.
-- There exists an equivalence relation on keys, whose definition is different
-- for hashed maps and ordered maps. A map never contains two or more nodes
-- with equivalent keys. The length of a map is the number of nodes it
-- contains.
--
-- Each nonempty map has two particular nodes called the first node and the
-- last node (which may be the same). Each node except for the last node has a
-- successor node. If there are no other intervening operations, starting with
-- the first node and repeatedly going to the successor node will visit each
-- node in the map exactly once until the last node is reached.
generic generic
type Key_Type is private; type Key_Type is private;
type Element_Type is private; type Element_Type is private;
with function Hash (Key : Key_Type) return Hash_Type; with function Hash (Key : Key_Type) return Hash_Type;
-- The actual function for the generic formal function Hash is expected to
-- return the same value each time it is called with a particular key
-- value. For any two equivalent key values, the actual for Hash is
-- expected to return the same value. If the actual for Hash behaves in
-- some other manner, the behavior of this package is unspecified. Which
-- subprograms of this package call Hash, and how many times they call it,
-- is unspecified.
with function Equivalent_Keys (Left, Right : Key_Type) return Boolean; with function Equivalent_Keys (Left, Right : Key_Type) return Boolean;
with function "=" (Left, Right : Element_Type) return Boolean is <>; -- The actual function for the generic formal function Equivalent_Keys on
-- Key_Type values is expected to return the same value each time it is
-- called with a particular pair of key values. It should define an
-- equivalence relationship, that is, be reflexive, symmetric, and
-- transitive. If the actual for Equivalent_Keys behaves in some other
-- manner, the behavior of this package is unspecified. Which subprograms
-- of this package call Equivalent_Keys, and how many times they call it,
-- is unspecified.
with function "=" (Left, Right : Element_Type) return Boolean is <>;
-- The actual function for the generic formal function "=" on Element_Type
-- values is expected to define a reflexive and symmetric relationship and
-- return the same result value each time it is called with a particular
-- pair of values. If it behaves in some other manner, the function "=" on
-- map values returns an unspecified value. The exact arguments and number
-- of calls of this generic formal function by the function "=" on map
-- values are unspecified.
package Ada.Containers.Hashed_Maps is package Ada.Containers.Hashed_Maps is
pragma Annotate (CodePeer, Skip_Analysis); pragma Annotate (CodePeer, Skip_Analysis);
pragma Preelaborate; pragma Preelaborate;
...@@ -71,21 +114,27 @@ package Ada.Containers.Hashed_Maps is ...@@ -71,21 +114,27 @@ package Ada.Containers.Hashed_Maps is
-- initialized to the value No_Element. -- initialized to the value No_Element.
function Has_Element (Position : Cursor) return Boolean; function Has_Element (Position : Cursor) return Boolean;
-- Equivalent to Position /= No_Element -- Returns True if Position designates an element, and returns False
-- otherwise.
package Map_Iterator_Interfaces is new package Map_Iterator_Interfaces is new
Ada.Iterator_Interfaces (Cursor, Has_Element); Ada.Iterator_Interfaces (Cursor, Has_Element);
function "=" (Left, Right : Map) return Boolean; function "=" (Left, Right : Map) return Boolean;
-- For each key/element pair in Left, equality attempts to find the key in -- If Left and Right denote the same map object, then the function returns
-- Right; if a search fails the equality returns False. The search works by -- True. If Left and Right have different lengths, then the function
-- calling Hash to find the bucket in the Right map that corresponds to the -- returns False. Otherwise, for each key K in Left, the function returns
-- Left key. If bucket is non-empty, then equality calls Equivalent_Keys -- False if:
-- to compare the key (in Left) to the key of each node in the bucket (in --
-- Right); if the keys are equivalent, then the equality test for this -- * a key equivalent to K is not present in Right; or
-- key/element pair (in Left) completes by calling the element equality --
-- operator to compare the element (in Left) to the element of the node -- * the element associated with K in Left is not equal to the
-- (in Right) whose key matched. -- element associated with K in Right (using the generic formal
-- equality operator for elements).
--
-- If the function has not returned a result after checking all of the
-- keys, it returns True. Any exception raised during evaluation of key
-- equivalence or element equality is propagated.
function Capacity (Container : Map) return Count_Type; function Capacity (Container : Map) return Count_Type;
-- Returns the current capacity of the map. Capacity is the maximum length -- Returns the current capacity of the map. Capacity is the maximum length
...@@ -111,31 +160,55 @@ package Ada.Containers.Hashed_Maps is ...@@ -111,31 +160,55 @@ package Ada.Containers.Hashed_Maps is
-- Removes all of the items from the map -- Removes all of the items from the map
function Key (Position : Cursor) return Key_Type; function Key (Position : Cursor) return Key_Type;
-- Returns the key of the node designated by the cursor -- Key returns the key component of the node designated by Position.
--
-- If Position equals No_Element, then Constraint_Error is propagated.
function Element (Position : Cursor) return Element_Type; function Element (Position : Cursor) return Element_Type;
-- Returns the element of the node designated by the cursor -- Element returns the element component of the node designated
-- by Position.
--
-- If Position equals No_Element, then Constraint_Error is propagated.
procedure Replace_Element procedure Replace_Element
(Container : in out Map; (Container : in out Map;
Position : Cursor; Position : Cursor;
New_Item : Element_Type); New_Item : Element_Type);
-- Assigns the value New_Item to the element designated by the cursor -- Replace_Element assigns New_Item to the element of the node designated
-- by Position.
--
-- If Position equals No_Element, then Constraint_Error is propagated; if
-- Position does not designate an element in Container, then Program_Error
-- is propagated.
procedure Query_Element procedure Query_Element
(Position : Cursor; (Position : Cursor;
Process : not null access Process : not null access
procedure (Key : Key_Type; Element : Element_Type)); procedure (Key : Key_Type; Element : Element_Type));
-- Calls Process with the key and element (both having only a constant -- Query_Element calls Process.all with the key and element from the node
-- view) of the node designed by the cursor. -- designated by Position as the arguments.
--
-- If Position equals No_Element, then Constraint_Error is propagated.
--
-- Tampering with the elements of the map that contains the element
-- designated by Position is prohibited during the execution of the call on
-- Process.all. Any exception raised by Process.all is propagated.
procedure Update_Element procedure Update_Element
(Container : in out Map; (Container : in out Map;
Position : Cursor; Position : Cursor;
Process : not null access Process : not null access
procedure (Key : Key_Type; Element : in out Element_Type)); procedure (Key : Key_Type; Element : in out Element_Type));
-- Calls Process with the key (with only a constant view) and element (with -- Update_Element calls Process.all with the key and element from the node
-- a variable view) of the node designed by the cursor. -- designated by Position as the arguments.
--
-- If Position equals No_Element, then Constraint_Error is propagated; if
-- Position does not designate an element in Container, then Program_Error
-- is propagated.
--
-- Tampering with the elements of Container is prohibited during the
-- execution of the call on Process.all. Any exception raised by
-- Process.all is propagated.
type Constant_Reference_Type type Constant_Reference_Type
(Element : not null access constant Element_Type) is private (Element : not null access constant Element_Type) is private
...@@ -150,29 +223,60 @@ package Ada.Containers.Hashed_Maps is ...@@ -150,29 +223,60 @@ package Ada.Containers.Hashed_Maps is
(Container : aliased Map; (Container : aliased Map;
Position : Cursor) return Constant_Reference_Type; Position : Cursor) return Constant_Reference_Type;
pragma Inline (Constant_Reference); pragma Inline (Constant_Reference);
-- This function (combined with the Constant_Indexing and
-- Implicit_Dereference aspects) provides a convenient way to gain read
-- access to an individual element of a map given a cursor.
-- Constant_Reference returns an object whose discriminant is an access
-- value that designates the element designated by Position.
--
-- If Position equals No_Element, then Constraint_Error is propagated; if
-- Position does not designate an element in Container, then Program_Error
-- is propagated.
--
-- Tampering with the elements of Container is prohibited
-- while the object returned by Constant_Reference exists and has not been
-- finalized.
function Reference function Reference
(Container : aliased in out Map; (Container : aliased in out Map;
Position : Cursor) return Reference_Type; Position : Cursor) return Reference_Type;
pragma Inline (Reference); pragma Inline (Reference);
-- This function (combined with the Variable_Indexing and
-- Implicit_Dereference aspects) provides a convenient way to gain read and
-- write access to an individual element of a map given a cursor.
-- Reference returns an object whose discriminant is an access value that
-- designates the element designated by Position.
--
-- If Position equals No_Element, then Constraint_Error is propagated; if
-- Position does not designate an element in Container, then Program_Error
-- is propagated.
--
-- Tampering with the elements of Container is prohibited while the object
-- returned by Reference exists and has not been finalized.
function Constant_Reference function Constant_Reference
(Container : aliased Map; (Container : aliased Map;
Key : Key_Type) return Constant_Reference_Type; Key : Key_Type) return Constant_Reference_Type;
pragma Inline (Constant_Reference); pragma Inline (Constant_Reference);
-- Equivalent to Constant_Reference (Container, Find (Container, Key)).
function Reference function Reference
(Container : aliased in out Map; (Container : aliased in out Map;
Key : Key_Type) return Reference_Type; Key : Key_Type) return Reference_Type;
pragma Inline (Reference); pragma Inline (Reference);
-- Equivalent to Reference (Container, Find (Container, Key)).
procedure Assign (Target : in out Map; Source : Map); procedure Assign (Target : in out Map; Source : Map);
-- If Target denotes the same object as Source, the operation has no
-- effect. Otherwise, the key/element pairs of Source are copied to Target
-- as for an assignment_statement assigning Source to Target.
function Copy (Source : Map; Capacity : Count_Type := 0) return Map; function Copy (Source : Map; Capacity : Count_Type := 0) return Map;
procedure Move (Target : in out Map; Source : in out Map); procedure Move (Target : in out Map; Source : in out Map);
-- Clears Target (if it's not empty), and then moves (not copies) the -- If Target denotes the same object as Source, then the operation has no
-- buckets array and nodes from Source to Target. -- effect. Otherwise, the operation is equivalent to Assign (Target,
-- Source) followed by Clear (Source).
procedure Insert procedure Insert
(Container : in out Map; (Container : in out Map;
...@@ -180,105 +284,86 @@ package Ada.Containers.Hashed_Maps is ...@@ -180,105 +284,86 @@ package Ada.Containers.Hashed_Maps is
New_Item : Element_Type; New_Item : Element_Type;
Position : out Cursor; Position : out Cursor;
Inserted : out Boolean); Inserted : out Boolean);
-- Conditionally inserts New_Item into the map. If Key is already in the -- Insert checks if a node with a key equivalent to Key is already present
-- map, then Inserted returns False and Position designates the node -- in Container. If a match is found, Inserted is set to False and Position
-- containing the existing key/element pair (neither of which is modified). -- designates the element with the matching key. Otherwise, Insert
-- If Key is not already in the map, the Inserted returns True and Position -- allocates a new node, initializes it to Key and New_Item, and adds it to
-- designates the newly-inserted node container Key and New_Item. The -- Container; Inserted is set to True and Position designates the
-- search for the key works as follows. Hash is called to determine Key's -- newly-inserted node. Any exception raised during allocation is
-- bucket; if the bucket is non-empty, then Equivalent_Keys is called to -- propagated and Container is not modified.
-- compare Key to each node in that bucket. If the bucket is empty, or
-- there were no matching keys in the bucket, the search "fails" and the
-- key/item pair is inserted in the map (and Inserted returns True);
-- otherwise, the search "succeeds" (and Inserted returns False).
procedure Insert procedure Insert
(Container : in out Map; (Container : in out Map;
Key : Key_Type; Key : Key_Type;
Position : out Cursor; Position : out Cursor;
Inserted : out Boolean); Inserted : out Boolean);
-- The same as the (conditional) Insert that accepts an element parameter, -- Insert inserts Key into Container as per the five-parameter Insert, with
-- with the difference that if Inserted returns True, then the element of -- the difference that an element initialized by default (see 3.3.1) is
-- the newly-inserted node is initialized to its default value. -- inserted.
procedure Insert procedure Insert
(Container : in out Map; (Container : in out Map;
Key : Key_Type; Key : Key_Type;
New_Item : Element_Type); New_Item : Element_Type);
-- Attempts to insert Key into the map, performing the usual search (which -- Insert inserts Key and New_Item into Container as per the five-parameter
-- involves calling both Hash and Equivalent_Keys); if the search succeeds -- Insert, with the difference that if a node with a key equivalent to Key
-- (because Key is already in the map), then it raises Constraint_Error. -- is already in the map, then Constraint_Error is propagated.
-- (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
-- Key is not already in the map.)
procedure Include procedure Include
(Container : in out Map; (Container : in out Map;
Key : Key_Type; Key : Key_Type;
New_Item : Element_Type); New_Item : Element_Type);
-- Attempts to insert Key into the map. If Key is already in the map, then -- Include inserts Key and New_Item into Container as per the
-- both the existing key and element are assigned the values of Key and -- five-parameter Insert, with the difference that if a node with a key
-- New_Item, respectively. (This version of Insert only raises an exception -- equivalent to Key is already in the map, then this operation assigns Key
-- if cursor tampering occurs. It is intended for use when you want to -- and New_Item to the matching node. Any exception raised during
-- insert the key/element pair in the map, and you don't care whether Key -- assignment is propagated.
-- is already present.)
procedure Replace procedure Replace
(Container : in out Map; (Container : in out Map;
Key : Key_Type; Key : Key_Type;
New_Item : Element_Type); New_Item : Element_Type);
-- Searches for Key in the map; if the search fails (because Key was not in -- Replace checks if a node with a key equivalent to Key is present in
-- the map), then it raises Constraint_Error. Otherwise, both the existing -- Container. If a match is found, Replace assigns Key and New_Item to the
-- key and element are assigned the values of Key and New_Item rsp. (This -- matching node; otherwise, Constraint_Error is propagated.
-- is similar to Insert, but with the opposite exception behavior. It is to
-- be used when you want to assert that Key is already in the map.)
procedure Exclude (Container : in out Map; Key : Key_Type); procedure Exclude (Container : in out Map; Key : Key_Type);
-- Searches for Key in the map, and if found, removes its node from the map -- Exclude checks if a node with a key equivalent to Key is present in
-- and then deallocates it. The search works as follows. The operation -- Container. If a match is found, Exclude removes the node from the map.
-- calls Hash to determine the key's bucket; if the bucket is not empty, it
-- calls Equivalent_Keys to compare Key to each key in the bucket. (This is
-- the deletion analog of Include. It is intended for use when you want to
-- remove the item from the map, but don't care whether the key is already
-- in the map.)
procedure Delete (Container : in out Map; Key : Key_Type); procedure Delete (Container : in out Map; Key : Key_Type);
-- Searches for Key in the map (which involves calling both Hash and -- Delete checks if a node with a key equivalent to Key is present in
-- Equivalent_Keys). If the search fails, then the operation raises -- Container. If a match is found, Delete removes the node from the map;
-- Constraint_Error. Otherwise it removes the node from the map and then -- otherwise, Constraint_Error is propagated.
-- 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 map.)
procedure Delete (Container : in out Map; Position : in out Cursor); procedure Delete (Container : in out Map; Position : in out Cursor);
-- Removes the node designated by Position from the map, and then -- Delete removes the node designated by Position from the map. Position is
-- deallocates the node. The operation calls Hash to determine the bucket, -- set to No_Element on return.
-- and then compares Position to each node in the bucket until there's a --
-- match (it does not call Equivalent_Keys). -- If Position equals No_Element, then Constraint_Error is propagated. If
-- Position does not designate an element in Container, then Program_Error
-- is propagated.
function First (Container : Map) return Cursor; function First (Container : Map) return Cursor;
-- Returns a cursor that designates the first non-empty bucket, by -- If Length (Container) = 0, then First returns No_Element. Otherwise,
-- searching from the beginning of the buckets array. -- First returns a cursor that designates the first node in Container.
function Next (Position : Cursor) return Cursor; function Next (Position : Cursor) return Cursor;
-- Returns a cursor that designates the node that follows the current one -- Returns a cursor that designates the successor of the node designated by
-- designated by Position. If Position designates the last node in its -- Position. If Position designates the last node, then No_Element is
-- bucket, the operation calls Hash to compute the index of this bucket, -- returned. If Position equals No_Element, then No_Element is returned.
-- 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 (Position : in out Cursor); procedure Next (Position : in out Cursor);
-- Equivalent to Position := Next (Position) -- Equivalent to Position := Next (Position)
function Find (Container : Map; Key : Key_Type) return Cursor; function Find (Container : Map; Key : Key_Type) return Cursor;
-- Searches for Key in the map. Find calls Hash to determine the key's -- If Length (Container) equals 0, then Find returns No_Element.
-- bucket; if the bucket is not empty, it calls Equivalent_Keys to compare -- Otherwise, Find checks if a node with a key equivalent to Key is present
-- Key to each key in the bucket. If the search succeeds, Find returns a -- in Container. If a match is found, a cursor designating the matching
-- cursor designating the matching node; otherwise, it returns No_Element. -- node is returned; otherwise, No_Element is returned.
function Contains (Container : Map; Key : Key_Type) return Boolean; function Contains (Container : Map; Key : Key_Type) return Boolean;
-- Equivalent to Find (Container, Key) /= No_Element -- Equivalent to Find (Container, Key) /= No_Element.
function Element (Container : Map; Key : Key_Type) return Element_Type; function Element (Container : Map; Key : Key_Type) return Element_Type;
-- Equivalent to Element (Find (Container, Key)) -- Equivalent to Element (Find (Container, Key))
...@@ -298,7 +383,11 @@ package Ada.Containers.Hashed_Maps is ...@@ -298,7 +383,11 @@ package Ada.Containers.Hashed_Maps is
procedure Iterate procedure Iterate
(Container : Map; (Container : Map;
Process : not null access procedure (Position : Cursor)); Process : not null access procedure (Position : Cursor));
-- Calls Process for each node in the map -- Iterate calls Process.all with a cursor that designates each node in
-- Container, starting with the first node and moving the cursor according
-- to the successor relation. Tampering with the cursors of Container is
-- prohibited during the execution of a call on Process.all. Any exception
-- raised by Process.all is propagated.
function Iterate function Iterate
(Container : Map) return Map_Iterator_Interfaces.Forward_Iterator'Class; (Container : Map) return Map_Iterator_Interfaces.Forward_Iterator'Class;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment