DEVELOPMENT EDITION · 769442725406
Library Reference
On this page

Verada.Containers.Formal.Vectors

An inline fixed-capacity sequence with one-based positions.

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

Capacity is positive; Length is separate from the index subtype. Find_Index's postcondition describes only a nonzero result. Iteration ends correctly for any capacity below Natural'Last.

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

Place the declaration in a declarative part, with the actuals your program needs.

with Verada.Containers.Formal.Vectors;
package Instance_Name is new Verada.Containers.Formal.Vectors (Integer, 8);
import Verada.Containers.Formal.Vectors;
package Instance_Name = new Verada.Containers.Formal.Vectors<Integer, 8>;

A Vibe module imports this unit's names with from Verada.Containers.Formal.Vectors 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

Generic formals (declaration) — Generic actuals establish this instance's nominal types and declared operations. Private formals require suitable definite nonlimited actuals; capacity/comparison/float restrictions are shown below. Defaulted comparison is resolved from the actual type, not an automatic proof of ordering laws.

Declared interface:

generic
   type Element_Type is private;
   Capacity : Positive;

API 002

Extended_Index (declaration) — Capacity-bounded length/search-result domain including zero. A nonzero search result still needs the declared existence property.

Declared interface:

subtype Extended_Index is Natural range 0 .. Capacity;

API 003

Index_Type (declaration) — Capacity-bounded positive position domain; a read must additionally establish the position is at most current Length.

Declared interface:

subtype Index_Type is Positive range 1 .. Capacity;

API 004

Vector (declaration) — Copyable inline fixed-capacity sequence, initially empty. Present positions remain bounded by Length as well as Index_Type.

Declared interface:

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);

A vector can be written as a container aggregate, [1, 2, 3]: it starts from Empty_Vector and appends each element in order (the Aggregate aspect), each Append with its precondition proved. The family guide's example uses one.

API 005

Length (declaration) — Observe the logical length/cardinality, not backing capacity or physical allocation size.

API 006

Empty_Vector (declaration) — A vector with no elements, the start of a container aggregate; its length is zero.

Declared interface:

function Empty_Vector return Vector
  with Global => null,
       Post => Length (Empty_Vector'Result) = 0;

API 007

Is_Empty (declaration) — Test whether logical length is zero; this is safe before an element selection.

API 008

Is_Full (declaration) — Test whether the bounded container has reached its generic Capacity.

API 009

Element (declaration) — Read an existing logical element; the required index/cursor/presence condition is distinct from the index type's capacity bound.

Before this operation, establish:

Index <= Length (Container)

API 010

Models (declaration) — The named functional-model generic instance used to state this concrete container's abstraction relation; use its own model operations and types.

API 011

Model (declaration) — Observe contents in the stated model type; a ghost functional model differs from an executable array-valued snapshot.

On normal return the declared contract establishes:

Models.Length (Model'Result) = Length (Container)
               and then (for all I in 1 .. Length (Container) => Models.Get (Model'Result, I) = Element (Container, I))

Ghost: for contracts and ghost code, and left out of the program.

API 012

First_Element (declaration) — Read the first present element; nonempty input is required.

Before this operation, establish:

not Is_Empty (Container)

On normal return the declared contract establishes:

First_Element'Result = Element (Container, 1)

API 013

Last_Element (declaration) — Read the last present element; nonempty input is required.

Before this operation, establish:

not Is_Empty (Container)

On normal return the declared contract establishes:

Last_Element'Result = Element (Container, Length (Container))

API 014

Clear (declaration) — Make the logical container empty. Storage release, cursor validity and inactive-slot contents follow this family's lifecycle rules, not a universal secure-erasure contract.

On normal return the declared contract establishes:

Length (Container) = 0

API 015

Append (declaration) — Append the item(s), subject to the exact finite capacity/length guard; preserve old logical contents as stated by the postcondition.

Before this operation, establish:

not Is_Full (Container)

On normal return the declared contract establishes:

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))

API 016

Replace_Element (declaration) — Replace one present value while preserving logical length and the other values/positions specified by the contract.

Before this operation, establish:

Index <= Length (Container)

On normal return the declared contract establishes:

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)))

API 017

Delete_Last (declaration) — Remove the last logical element; nonempty input is required. No removed value is returned.

Before this operation, establish:

not Is_Empty (Container)

On normal return the declared contract establishes:

Length (Container) = Length (Container)'Old - 1
               and then (for all I in 1 .. Length (Container) => Element (Container, I) = Element (Container'Old, I))

API 018

Find_Index (declaration) — Search by element equality. The bounded vector's public contract constrains nonzero results but does not promise the complete first-match/zero behavior of its implementation.

On normal return the declared contract establishes:

(if Find_Index'Result /= 0 then Find_Index'Result <= Length (Container) and then Element (Container, Find_Index'Result) = Item)

API 019

Contains (declaration) — Test the family's declared membership/search relation; it is not a mutation or a guarantee of constant-time lookup.

API 020

Iter_First (declaration) — Return the first candidate iteration position. Call Has_Element before selecting an element; empty input can still have a candidate.

API 021

Iter_Next (declaration) — Advance the candidate position under the declared sentinel/finite-bound behavior.

API 022

Iter_Has_Element (declaration) — Test whether an iteration candidate denotes a currently present logical element.

API 023

Iter_Element (declaration) — Read the iteration element after establishing Iter_Has_Element.

Before this operation, establish:

Iter_Has_Element (Container, Position)