DEVELOPMENT EDITION · 769442725406
Library Reference
On this page
Generic package Verada.Containers.Formal.Vectors
Verada predefined library: bounded vectors of at most Capacity elements, indexed from 1, with contracts that say what each operation does to every element.
generic
type Element_Type is private;
Capacity : Positive;Extended_Index
subtype Extended_Index is Natural range 0 .. Capacity;Index_Type
subtype Index_Type is Positive range 1 .. Capacity;Vector
type Vector is private
with Default_Initial_Condition => Length (Vector) = 0,
Iterable => (First => Iter_First, Next => Iter_Next, Has_Element => Iter_Has_Element, Element => Iter_Element),
Aggregate => (Empty => Empty_Vector, Add_Unnamed => Append);Length
function Length (Container : Vector) return Extended_Index
with Global => null;Empty_Vector
function Empty_Vector return Vector
with Global => null,
Post => Length (Empty_Vector'Result) = 0;the vector of no elements, from which [A, B, C] is built by Append
Is_Empty
function Is_Empty (Container : Vector) return Boolean is (Length (Container) = 0);Is_Full
function Is_Full (Container : Vector) return Boolean is (Length (Container) = Capacity);Element
function Element (Container : Vector; Index : Index_Type) return Element_Type
with Global => null,
Pre => Index <= Length (Container);Models
package Models is new Verada.Containers.Functional.Sequences (Element_Type);the functional model: the elements in order, as a sequence
Model
function Model (Container : Vector) return Models.Sequence
with Ghost,
Global => null,
Post => Models.Length (Model'Result) = Length (Container)
and then (for all I in 1 .. Length (Container) => Models.Get (Model'Result, I) = Element (Container, I));First_Element
function First_Element (Container : Vector) return Element_Type
with Global => null,
Pre => not Is_Empty (Container),
Post => First_Element'Result = Element (Container, 1);Last_Element
function Last_Element (Container : Vector) return Element_Type
with Global => null,
Pre => not Is_Empty (Container),
Post => Last_Element'Result = Element (Container, Length (Container));Clear
procedure Clear (Container : in out Vector)
with Global => null,
Post => Length (Container) = 0;Append
procedure Append (Container : in out Vector; New_Item : Element_Type)
with Global => null,
Pre => not Is_Full (Container),
Post => Length (Container) = Length (Container)'Old + 1
and then Element (Container, Length (Container)) = New_Item
and then (for all I in 1 .. Length (Container'Old) => Element (Container, I) = Element (Container'Old, I));Replace_Element
procedure Replace_Element (Container : in out Vector; Index : Index_Type; New_Item : Element_Type)
with Global => null,
Pre => Index <= Length (Container),
Post => Length (Container) = Length (Container)'Old
and then Element (Container, Index) = New_Item
and then (for all I in 1 .. Length (Container) => (if I /= Index then Element (Container, I) = Element (Container'Old, I)));Delete_Last
procedure Delete_Last (Container : in out Vector)
with Global => null,
Pre => not Is_Empty (Container),
Post => Length (Container) = Length (Container)'Old - 1
and then (for all I in 1 .. Length (Container) => Element (Container, I) = Element (Container'Old, I));Find_Index
function Find_Index (Container : Vector; Item : Element_Type) return Extended_Index
with Global => null,
Post => (if Find_Index'Result = 0
then (for all I in 1 .. Length (Container) => Element (Container, I) /= Item)
else Find_Index'Result <= Length (Container)
and then Element (Container, Find_Index'Result) = Item
and then (for all I in 1 .. Find_Index'Result - 1 => Element (Container, I) /= Item));the first index of Item, or 0 when no element is Item
Contains
function Contains (Container : Vector; Item : Element_Type) return Boolean is (Find_Index (Container, Item) /= 0);Iter_First
function Iter_First (Container : Vector) return Natural is (1);for E of V and for all E of V =>...: positions 1.. Length (V)
Iter_Next
function Iter_Next (Container : Vector; Position : Natural) return Natural is
(if Position < Natural'Last then Position + 1 else Position);Iter_Has_Element
function Iter_Has_Element (Container : Vector; Position : Natural) return Boolean is
(Position in 1 .. Length (Container));Iter_Element
function Iter_Element (Container : Vector; Position : Natural) return Element_Type is
(Element (Container, Position))
with Pre => Iter_Has_Element (Container, Position);