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
- API 034
- API 035
- API 036
- API 037
- API 038
Ada.Containers.Bounded_Doubly_Linked_Lists
Doubly linked lists of at most Capacity elements, with cursors that stay valid (RM A.18.20).
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_Doubly_Linked_Lists (Integer);, and declare objects with their capacity. A cursor is a node's number; operations that read through one take the list too.
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_Doubly_Linked_Lists;import Ada.Containers.Bounded_Doubly_Linked_Lists;
A Vibe module imports this unit's names with from Ada.Containers.Bounded_Doubly_Linked_Lists 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
Element_Type (declaration) — The generic formals, as Ada's: the instance's types and the operations it compares with.
Declared interface:
generic
type Element_Type is private;
with function "=" (Left, Right : Element_Type) return Boolean is <>;API 002
Positive_Count (declaration) — A place in a list, from 1.
Declared interface:
subtype Positive_Count is Count_Type range 1 .. Count_Type'Last;API 003
List (declaration) — The list type, with its capacity as a discriminant; a new list is empty.
Declared interface:
type List (Capacity : Count_Type) is private
with Default_Initial_Condition => Length (List) = 0;API 004
Cursor (declaration) — A node of a list; No_Element designates none.
Declared interface:
type Cursor is record
Node : Count_Type := 0;
end record;API 005
No_Element (declaration) — The cursor that designates no element.
Declared interface:
No_Element : constant Cursor := (Node => 0);API 006
Length (declaration) — The number of elements (or entries) the container holds now.
Declared interface:
function Length (Container : List) return Count_Type
with Global => null;API 007
Is_Empty (declaration) — Whether the container holds nothing.
Declared interface:
function Is_Empty (Container : List) return Boolean is (Length (Container) = 0);API 008
Models (declaration) — The functional model: the elements in order, as a sequence.
Declared interface:
package Models is new Verada.Containers.Functional.Sequences (Element_Type);API 009
Model_Length (declaration) — (proof only) a model's length and its element at a place, counted as the list is.
Declared interface:
function Model_Length (S : Models.Sequence) return Count_Type is (Count_Type (Models.Length (S)))
with Ghost;API 010
Model_Get (declaration) — Ghost: a model's element at a place, counted as the list is.
Declared interface:
function Model_Get (S : Models.Sequence; I : Count_Type) return Element_Type is (Models.Get (S, Natural (I)))
with Ghost,
Pre => I in 1 .. Model_Length (S);API 011
Model (declaration) — Ghost: the functional model of the contents, in order, for contracts.
Declared interface:
function Model (Container : List) return Models.Sequence
with Ghost,
Global => null,
Post => Model_Length (Model'Result) = Length (Container);API 012
Node_At (declaration) — The node of the list's element at a place, from 1 (proof only).
Declared interface:
function Node_At (Container : List; Index : Positive_Count) return Count_Type
with Ghost,
Global => null,
Pre => Index <= Length (Container);API 013
Node_Index (declaration) — The place of a node's element in the list, from 1, or 0 when the list does not use it.
Declared interface:
function Node_Index (Container : List; Node : Count_Type) return Count_Type
with Global => null,
Post => Node_Index'Result <= Length (Container)
and then (if Node = 0 then Node_Index'Result = 0)
and then (if Node_Index'Result /= 0 then Node_At (Container, Node_Index'Result) = Node)
and then (for all I in 1 .. Length (Container) => (Node_At (Container, I) = Node) = (I = Node_Index'Result));API 014
Index_Of (declaration) — The place of a cursor's element in the list, from 1, or 0 when it designates none.
Declared interface:
function Index_Of (Container : List; Position : Cursor) return Count_Type is
(Node_Index (Container, Position.Node));API 015
Has_Element (declaration) — Whether a cursor designates an element of this list.
Declared interface:
function Has_Element (Container : List; Position : Cursor) return Boolean is
(Index_Of (Container, Position) /= 0);API 016
Element (declaration) — The element at the given index, cursor or key; the precondition requires one to be there.
Declared interface:
function Element (Container : List; Position : Cursor) return Element_Type
with Global => null,
Pre => Has_Element (Container, Position),
Post => Models.Equal_Elements (Element'Result, Model_Get (Model (Container), Index_Of (Container, Position)));API 017
Same_Places (declaration) — Every cursor keeps its place.
Declared interface:
function Same_Places (Left, Right : List) return Boolean is
(for all N in 1 .. Left.Capacity => Node_Index (Left, N) = Node_Index (Right, N))
with Ghost;API 018
Places_Shifted_Up (declaration) — The cursors of Old keep their place in New, those from At on one further.
Declared interface:
function Places_Shifted_Up (Old, New_List : List; At_Index : Positive_Count) return Boolean is
(for all N in 1 .. Old.Capacity =>
(if Node_Index (Old, N) /= 0 then
Node_Index (New_List, N) - (if Node_Index (Old, N) < At_Index then 0 else 1) = Node_Index (Old, N)))
with Ghost;API 019
Places_Shifted_Down (declaration) — The cursors of Old other than the one at At_Index keep their place in New, those after it one nearer.
Declared interface:
function Places_Shifted_Down (Old, New_List : List; At_Index : Positive_Count) return Boolean is
(for all N in 1 .. Old.Capacity =>
(if Node_Index (Old, N) /= 0 and then Node_Index (Old, N) /= At_Index then
Node_Index (New_List, N)
= (if Node_Index (Old, N) < At_Index then Node_Index (Old, N) else Node_Index (Old, N) - 1)))
with Ghost;API 020
Inserted (declaration) — New is Old with Item at At_Index.
Declared interface:
function Inserted (Old, New_Model : Models.Sequence; At_Index : Positive_Count; Item : Element_Type) return Boolean is
(Model_Length (Old) < Count_Type'Last
and then At_Index <= Model_Length (Old) + 1
and then Model_Length (New_Model) = Model_Length (Old) + 1
and then Models.Equal_Elements (Model_Get (New_Model, At_Index), Item)
and then (for all I in 1 .. At_Index - 1 => Models.Equal_Elements (Model_Get (New_Model, I), Model_Get (Old, I)))
and then (for all I in At_Index .. Model_Length (Old) => Models.Equal_Elements (Model_Get (New_Model, I + 1), Model_Get (Old, I))))
with Ghost;API 021
Removed (declaration) — New is Old without the element at At_Index.
Declared interface:
function Removed (Old, New_Model : Models.Sequence; At_Index : Positive_Count) return Boolean is
(At_Index <= Model_Length (Old)
and then Model_Length (New_Model) = Model_Length (Old) - 1
and then (for all I in 1 .. At_Index - 1 => Models.Equal_Elements (Model_Get (New_Model, I), Model_Get (Old, I)))
and then (for all I in At_Index .. Model_Length (Old) => (if I > At_Index then Models.Equal_Elements (Model_Get (New_Model, I - 1), Model_Get (Old, I)))))
with Ghost;API 022
First (declaration) — The cursor of the first element, or No_Element.
Declared interface:
function First (Container : List) return Cursor
with Global => null,
Post => (if Is_Empty (Container) then First'Result = No_Element else Index_Of (Container, First'Result) = 1);API 023
Last (declaration) — The cursor of the last element, or No_Element.
Declared interface:
function Last (Container : List) return Cursor
with Global => null,
Post => (if Is_Empty (Container) then Last'Result = No_Element else Index_Of (Container, Last'Result) = Length (Container));API 024
Next (declaration) — The cursor after a present one, or No_Element at the end.
Declared interface:
function Next (Container : List; Position : Cursor) return Cursor
with Global => null,
Pre => Has_Element (Container, Position),
Post => (if Index_Of (Container, Position) = Length (Container) then Next'Result = No_Element
else Index_Of (Container, Next'Result) = Index_Of (Container, Position) + 1);API 025
Previous (declaration) — The cursor before a present one, or No_Element at the start.
Declared interface:
function Previous (Container : List; Position : Cursor) return Cursor
with Global => null,
Pre => Has_Element (Container, Position),
Post => (if Index_Of (Container, Position) = 1 then Previous'Result = No_Element
else Index_Of (Container, Previous'Result) = Index_Of (Container, Position) - 1);API 026
First_Element (declaration) — The first element; the container must not be empty.
Declared interface:
function First_Element (Container : List) return Element_Type
with Global => null,
Pre => not Is_Empty (Container),
Post => Models.Equal_Elements (First_Element'Result, Model_Get (Model (Container), 1));API 027
Last_Element (declaration) — The last element; the container must not be empty.
Declared interface:
function Last_Element (Container : List) return Element_Type
with Global => null,
Pre => not Is_Empty (Container),
Post => Models.Equal_Elements (Last_Element'Result, Model_Get (Model (Container), Length (Container)));API 028
Find (declaration) — The first cursor of Item, or No_Element.
Declared interface:
function Find (Container : List; Item : Element_Type) return Cursor
with Global => null,
Post => (if Find'Result = No_Element then
(for all I in 1 .. Length (Container) => not (Model_Get (Model (Container), I) = Item))
else Has_Element (Container, Find'Result) and then Element (Container, Find'Result) = Item);API 029
Contains (declaration) — Whether the container holds an element (or key) matching the argument.
Declared interface:
function Contains (Container : List; Item : Element_Type) return Boolean is
(Find (Container, Item) /= No_Element);API 030
Clear (declaration) — Empties the container; its capacity is unchanged.
Declared interface:
procedure Clear (Container : in out List)
with Global => null,
Post => Length (Container) = 0;API 031
Insert (declaration) — New_Item before Before (at the end when Before is No_Element); Position designates it.
Declared interface:
procedure Insert (Container : in out List; Before : Cursor; New_Item : Element_Type; Position : out Cursor)
with Global => null,
Pre => Length (Container) < Container.Capacity and then (Before = No_Element or else Has_Element (Container, Before)),
Post => Inserted (Model (Container'Old), Model (Container),
(if Before = No_Element then Length (Container'Old) + 1 else Index_Of (Container'Old, Before)), New_Item)
and then Index_Of (Container, Position) = (if Before = No_Element then Length (Container'Old) + 1 else Index_Of (Container'Old, Before))
and then Places_Shifted_Up (Container'Old, Container, Index_Of (Container, Position));API 032
Insert (declaration) — New_Item before Before (at the end when Before is No_Element).
Declared interface:
procedure Insert (Container : in out List; Before : Cursor; New_Item : Element_Type)
with Global => null,
Pre => Length (Container) < Container.Capacity and then (Before = No_Element or else Has_Element (Container, Before)),
Post => Inserted (Model (Container'Old), Model (Container),
(if Before = No_Element then Length (Container'Old) + 1 else Index_Of (Container'Old, Before)), New_Item)
and then Places_Shifted_Up (Container'Old, Container,
(if Before = No_Element then Length (Container'Old) + 1 else Index_Of (Container'Old, Before)));API 033
Append (declaration) — Adds New_Item at the end; the precondition requires room.
Declared interface:
procedure Append (Container : in out List; New_Item : Element_Type)
with Global => null,
Pre => Length (Container) < Container.Capacity,
Post => Inserted (Model (Container'Old), Model (Container), Length (Container), New_Item)
and then Places_Shifted_Up (Container'Old, Container, Length (Container));API 034
Prepend (declaration) — Adds New_Item at the start; the precondition requires room.
Declared interface:
procedure Prepend (Container : in out List; New_Item : Element_Type)
with Global => null,
Pre => Length (Container) < Container.Capacity,
Post => Inserted (Model (Container'Old), Model (Container), 1, New_Item)
and then Places_Shifted_Up (Container'Old, Container, 1);API 035
Replace_Element (declaration) — Puts New_Item in place of the element there; everything else is unchanged.
Declared interface:
procedure Replace_Element (Container : in out List; Position : Cursor; New_Item : Element_Type)
with Global => null,
Pre => Has_Element (Container, Position),
Post => Length (Container) = Length (Container'Old)
and then Models.Equal_Elements (Element (Container, Position), New_Item)
and then Same_Places (Container'Old, Container)
and then (for all I in 1 .. Length (Container) =>
(if I /= Index_Of (Container, Position) then Models.Equal_Elements (Model_Get (Model (Container), I), Model_Get (Model (Container'Old), I))));API 036
Delete (declaration) — The element Position designates is gone, and so is Position.
Declared interface:
procedure Delete (Container : in out List; Position : in out Cursor)
with Global => null,
Pre => Has_Element (Container, Position),
Post => Removed (Model (Container'Old), Model (Container), Index_Of (Container'Old, Position'Old))
and then Position = No_Element
and then not Has_Element (Container, Position'Old)
and then Places_Shifted_Down (Container'Old, Container, Index_Of (Container'Old, Position'Old));API 037
Delete_First (declaration) — Removes the first element; the container must not be empty.
Declared interface:
procedure Delete_First (Container : in out List)
with Global => null,
Pre => not Is_Empty (Container),
Post => Removed (Model (Container'Old), Model (Container), 1)
and then Places_Shifted_Down (Container'Old, Container, 1);API 038
Delete_Last (declaration) — Removes the last element; the container must not be empty.
Declared interface:
procedure Delete_Last (Container : in out List)
with Global => null,
Pre => not Is_Empty (Container),
Post => Removed (Model (Container'Old), Model (Container), Length (Container'Old))
and then Places_Shifted_Down (Container'Old, Container, Length (Container'Old));