On this page
- Availability and ownership
- Import and instantiate
- Contract and lifecycle reading
- API 001
- API 002
- API 003
- API 004
- API 005
- API 006
- API 007
- API 008
- API 009
- API 010
- API 011
- API 012
- API 013
- API 014
- API 015
- API 016
- API 017
- API 018
- API 019
- API 020
- API 021
- API 022
- API 023
- API 024
- API 025
- API 026
- API 027
- API 028
- API 029
- API 030
- API 031
- API 032
- API 033
Ada.Containers.Bounded_Ordered_Maps
Maps of at most Capacity entries, in increasing order of their keys (RM A.18.22).
Read the family guide for representation, selection and resource rules. The complete declaration page retains exact signatures/contracts; the source specification is the implementation baseline.
Availability and ownership
Ada's generic formals and a capacity discriminant, in the design of Verada.Containers.Formal: contracts at every place over a ghost functional model; preconditions where Ada raises Constraint_Error or Capacity_Error. Instantiate it as Ada's, as in package P is new Ada.Containers.Bounded_Ordered_Maps (Character, Integer);, and declare objects with their capacity. Entries are reached by key or place; "<" must be a strict order.
A client proof uses these contracts without proving the body again (see library assurance). Global => null excludes package-global effects, not changes made through an in out argument.
Import and instantiate
with Ada.Containers.Bounded_Ordered_Maps;import Ada.Containers.Bounded_Ordered_Maps;
A Vibe module imports this unit's names with from Ada.Containers.Bounded_Ordered_Maps import Name; see library use across syntaxes. In Varc, keep each name's declared spelling and write & on arguments the call changes.
Contract and lifecycle reading
A Pre condition is the caller's obligation; a Post is what a normal return guarantees. What a postcondition does not state, a client cannot assume. Ghost functions are for contracts and ghost code. The family guide describes copying, lifetime, order and cost.
API 001
Key_Type (declaration) — The generic formals, as Ada's: the instance's types and the operations it compares with.
Declared interface:
generic
type Key_Type is private;
type Element_Type is private;
with function "<" (Left, Right : Key_Type) return Boolean is <>;
with function "=" (Left, Right : Element_Type) return Boolean is <>;API 002
Map (declaration) — The map type, with its capacity (and modulus) as discriminants; a new map is empty.
Declared interface:
type Map (Capacity : Count_Type) is private
with Default_Initial_Condition => Length (Map) = 0,
Iterable => (First => Iter_First, Next => Iter_Next, Has_Element => Iter_Has_Element, Element => Iter_Key);API 003
Equivalent_Keys (declaration) — Neither key is less than the other.
Declared interface:
function Equivalent_Keys (Left, Right : Key_Type) return Boolean is (not (Left < Right) and then not (Right < Left));API 004
Length (declaration) — The number of elements (or entries) the container holds now.
Declared interface:
function Length (Container : Map) return Count_Type
with Global => null,
Post => Length'Result <= Container.Capacity;API 005
Is_Empty (declaration) — Whether the container holds nothing.
Declared interface:
function Is_Empty (Container : Map) return Boolean is (Length (Container) = 0);API 006
Key_At (declaration) — The key and the element of the entry at a place, from 1.
Declared interface:
function Key_At (Container : Map; Index : Count_Type) return Key_Type
with Global => null,
Pre => Index in 1 .. Length (Container);API 007
Element_At (declaration) — The element at a place, from 1; the precondition requires one there.
Declared interface:
function Element_At (Container : Map; Index : Count_Type) return Element_Type
with Global => null,
Pre => Index in 1 .. Length (Container);API 008
Key_Models (declaration) — The functional models: the keys and the elements in order, as sequences.
Declared interface:
package Key_Models is new Verada.Containers.Functional.Sequences (Key_Type);API 009
Element_Models (declaration) — The instance of Verada.Containers.Functional.Sequences for the elements' model.
Declared interface:
package Element_Models is new Verada.Containers.Functional.Sequences (Element_Type);API 010
Keys_Model (declaration) — Ghost: the keys in order, as a functional sequence.
Declared interface:
function Keys_Model (Container : Map) return Key_Models.Sequence
with Ghost,
Global => null,
Post => Key_Models.Length (Keys_Model'Result) = Natural (Length (Container))
and then (for all I in 1 .. Length (Container) =>
Key_Models.Equal_Elements (Key_Models.Get (Keys_Model'Result, Natural (I)), Key_At (Container, I)));API 011
Elements_Model (declaration) — Ghost: the elements in order, as a functional sequence.
Declared interface:
function Elements_Model (Container : Map) return Element_Models.Sequence
with Ghost,
Global => null,
Post => Element_Models.Length (Elements_Model'Result) = Natural (Length (Container))
and then (for all I in 1 .. Length (Container) =>
Element_Models.Equal_Elements (Element_Models.Get (Elements_Model'Result, Natural (I)), Element_At (Container, I)));API 012
Same_Entries (declaration) — The entry at each place of Right is Left's at the same place, or, from Skip on when Skip is not 0, at the next place (proof only).
Declared interface:
function Same_Entries (Left, Right : Map; Skip : Count_Type) return Boolean is
(for all I in 1 .. Length (Right) =>
(if Skip = 0 or else I < Skip
then I <= Length (Left)
and then Key_Models.Equal_Elements (Key_At (Right, I), Key_At (Left, I))
and then Element_Models.Equal_Elements (Element_At (Right, I), Element_At (Left, I))
else I < Length (Left)
and then Key_Models.Equal_Elements (Key_At (Right, I), Key_At (Left, I + 1))
and then Element_Models.Equal_Elements (Element_At (Right, I), Element_At (Left, I + 1))))
with Ghost;API 013
Index_Of (declaration) — The place of the entry whose key is equivalent to Key, or 0.
Declared interface:
function Index_Of (Container : Map; Key : Key_Type) return Count_Type
with Global => null,
Post => Index_Of'Result <= Length (Container)
and then (if Index_Of'Result = 0
then (for all I in 1 .. Length (Container) => not Equivalent_Keys (Key_At (Container, I), Key))
else Equivalent_Keys (Key_At (Container, Index_Of'Result), Key)
and then (for all I in 1 .. Index_Of'Result - 1 => not Equivalent_Keys (Key_At (Container, I), Key)));API 014
Contains (declaration) — Whether the container holds an element (or key) matching the argument.
Declared interface:
function Contains (Container : Map; Key : Key_Type) return Boolean is (Index_Of (Container, Key) /= 0);API 015
Element (declaration) — The element of Key's entry.
Declared interface:
function Element (Container : Map; Key : Key_Type) return Element_Type is
(Element_At (Container, Index_Of (Container, Key)))
with Pre => Contains (Container, Key);API 016
Insert_Place (declaration) — The place a new entry for Key takes: before the first entry whose key is greater, or at the end.
Declared interface:
function Insert_Place (Container : Map; Key : Key_Type) return Count_Type
with Global => null,
Pre => Length (Container) < Container.Capacity,
Post => Insert_Place'Result in 1 .. Length (Container) + 1
and then (for all I in 1 .. Insert_Place'Result - 1 => not (Key < Key_At (Container, I)))
and then (if Insert_Place'Result <= Length (Container) then Key < Key_At (Container, Insert_Place'Result));API 017
First_Key (declaration) — The first (least) key; the map must not be empty.
Declared interface:
function First_Key (Container : Map) return Key_Type
with Global => null,
Pre => not Is_Empty (Container),
Post => Key_Models.Equal_Elements (First_Key'Result, Key_At (Container, 1));API 018
Last_Key (declaration) — The last (greatest) key; the map must not be empty.
Declared interface:
function Last_Key (Container : Map) return Key_Type
with Global => null,
Pre => not Is_Empty (Container),
Post => Key_Models.Equal_Elements (Last_Key'Result, Key_At (Container, Length (Container)));API 019
First_Element (declaration) — The first element; the container must not be empty.
Declared interface:
function First_Element (Container : Map) return Element_Type
with Global => null,
Pre => not Is_Empty (Container),
Post => Element_Models.Equal_Elements (First_Element'Result, Element_At (Container, 1));API 020
Last_Element (declaration) — The last element; the container must not be empty.
Declared interface:
function Last_Element (Container : Map) return Element_Type
with Global => null,
Pre => not Is_Empty (Container),
Post => Element_Models.Equal_Elements (Last_Element'Result, Element_At (Container, Length (Container)));API 021
Clear (declaration) — Empties the container; its capacity is unchanged.
Declared interface:
procedure Clear (Container : in out Map)
with Global => null,
Post => Length (Container) = 0;API 022
Insert (declaration) — A new entry for Key, in its place.
Declared interface:
procedure Insert (Container : in out Map; Key : Key_Type; New_Item : Element_Type)
with Global => null,
Pre => not Contains (Container, Key) and then Length (Container) < Container.Capacity,
Post => Length (Container) = Length (Container'Old) + 1
and then Key_Models.Equal_Elements (Key_At (Container, Insert_Place (Container'Old, Key)), Key)
and then Element_Models.Equal_Elements (Element_At (Container, Insert_Place (Container'Old, Key)), New_Item)
and then Same_Entries (Container, Container'Old, Insert_Place (Container'Old, Key));API 023
Replace (declaration) — Key's entry now has Key and New_Item.
Declared interface:
procedure Replace (Container : in out Map; Key : Key_Type; New_Item : Element_Type)
with Global => null,
Pre => Contains (Container, Key),
Post => Length (Container) = Length (Container'Old)
and then Key_Models.Equal_Elements (Key_At (Container, Index_Of (Container'Old, Key)), Key)
and then Element_Models.Equal_Elements (Element_At (Container, Index_Of (Container'Old, Key)), New_Item)
and then (for all I in 1 .. Length (Container) =>
(if I /= Index_Of (Container'Old, Key) then
Key_Models.Equal_Elements (Key_At (Container, I), Key_At (Container'Old, I))
and then Element_Models.Equal_Elements (Element_At (Container, I), Element_At (Container'Old, I))));API 024
Include (declaration) — Key's entry has Key and New_Item, replaced or new in its place.
Declared interface:
procedure Include (Container : in out Map; Key : Key_Type; New_Item : Element_Type)
with Global => null,
Pre => Contains (Container, Key) or else Length (Container) < Container.Capacity,
Post => (if Contains (Container'Old, Key) then
Length (Container) = Length (Container'Old)
and then Key_Models.Equal_Elements (Key_At (Container, Index_Of (Container'Old, Key)), Key)
and then Element_Models.Equal_Elements (Element_At (Container, Index_Of (Container'Old, Key)), New_Item)
and then (for all I in 1 .. Length (Container) =>
(if I /= Index_Of (Container'Old, Key) then
Key_Models.Equal_Elements (Key_At (Container, I), Key_At (Container'Old, I))
and then Element_Models.Equal_Elements (Element_At (Container, I), Element_At (Container'Old, I))))
else
Length (Container) = Length (Container'Old) + 1
and then Key_Models.Equal_Elements (Key_At (Container, Insert_Place (Container'Old, Key)), Key)
and then Element_Models.Equal_Elements (Element_At (Container, Insert_Place (Container'Old, Key)), New_Item)
and then Same_Entries (Container, Container'Old, Insert_Place (Container'Old, Key)));API 025
Delete (declaration) — Key's entry is gone; those after it move one place nearer.
Declared interface:
procedure Delete (Container : in out Map; Key : Key_Type)
with Global => null,
Pre => Contains (Container, Key),
Post => Length (Container) = Length (Container'Old) - 1
and then Same_Entries (Container'Old, Container, Index_Of (Container'Old, Key));API 026
Exclude (declaration) — Key's entry is gone, if there was one.
Declared interface:
procedure Exclude (Container : in out Map; Key : Key_Type)
with Global => null,
Post => (if Contains (Container'Old, Key)
then Length (Container) = Length (Container'Old) - 1
and then Same_Entries (Container'Old, Container, Index_Of (Container'Old, Key))
else Length (Container) = Length (Container'Old)
and then Same_Entries (Container'Old, Container, 0));API 027
"=" (declaration) — The same length, and each key of Left in Right with an element equal to Left's ("=").
Declared interface:
function "=" (Left, Right : Map) return Boolean
with Global => null,
Post => "="'Result = (Length (Left) = Length (Right)
and then (for all I in 1 .. Length (Left) =>
Contains (Right, Key_At (Left, I))
and then Element_At (Left, I) = Element (Right, Key_At (Left, I))));API 028
Assign (declaration) — Target holds Source's entries.
Declared interface:
procedure Assign (Target : in out Map; Source : Map)
with Global => null,
Pre => Length (Source) <= Target.Capacity,
Post => Length (Target) = Length (Source) and then Same_Entries (Source, Target, 0);API 029
Copy (declaration) — A map of Source's entries with room for Capacity, or for Source's length when Capacity is 0.
Declared interface:
function Copy (Source : Map; Capacity : Count_Type := 0) return Map
with Global => null,
Pre => Capacity = 0 or else Capacity >= Length (Source),
Post => Copy'Result.Capacity = (if Capacity = 0 then Length (Source) else Capacity)
and then Length (Copy'Result) = Length (Source)
and then Same_Entries (Source, Copy'Result, 0);API 030
Iter_First (declaration) — for K of M and for all K of M =>...: the keys, in their order.
Declared interface:
function Iter_First (Container : Map) return Count_Type is (1);API 031
Iter_Next (declaration) — Iteration support: the position after another.
Declared interface:
function Iter_Next (Container : Map; Position : Count_Type) return Count_Type is
(if Position < Count_Type'Last then Position + 1 else Position);API 032
Iter_Has_Element (declaration) — Iteration support: whether a position holds an element.
Declared interface:
function Iter_Has_Element (Container : Map; Position : Count_Type) return Boolean is
(Position in 1 .. Length (Container));API 033
Iter_Key (declaration) — Iteration support: the key at a position.
Declared interface:
function Iter_Key (Container : Map; Position : Count_Type) return Key_Type is
(Key_At (Container, Position))
with Pre => Iter_Has_Element (Container, Position);