DEVELOPMENT EDITION · 769442725406
Library Reference
On this page

Verada.Containers.Unbounded.Vectors

A growable limited reclaimed vector with array-valued contents.

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

Length stays below Verada.Storage.Length_Bound (2⁶⁰), as memory holds no more; an operation that lengthens a vector raises Storage_Error when memory cannot hold the result, and none has a precondition on sizes. Copy is explicit; Move empties its source. Insertion and removal shift later positions. Python's list operations (Contains, Index, Count, Remove, Delete, the reversals, + and *) state their results through the model; the generic sort, minimum and maximum take the element order as a formal.

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.Unbounded.Vectors;
package Instance_Name is new Verada.Containers.Unbounded.Vectors (Integer);
import Verada.Containers.Unbounded.Vectors;
package Instance_Name = new Verada.Containers.Unbounded.Vectors<Integer>;

Vibe does not instantiate library generics; 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;

API 002

Element_Array (declaration) — Unconstrained Positive-indexed element value array for content snapshots/contracts. A particular Model result has its own lower-bound guarantee; the array type alone does not force every object to start at 1.

Declared interface:

type Element_Array is array (Positive range <>) of Element_Type;

API 003

Same_Except (declaration) — Ghost relation saying corresponding arrays have equal bounds and agree except at the named position.

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

API 004

Last_Of (declaration) — Ghost selector for the last element of a nonempty array.

Before this operation, establish:

A'Length > 0

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

API 005

Appended (declaration) — Ghost relation describing one appended item and unchanged earlier elements.

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

API 006

Inserted (declaration) — Ghost relation describing insertion into the model, including shifted suffix/preserved prefix.

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

API 007

Removed (declaration) — Ghost relation describing a deleted model element and the shifted surviving suffix.

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

API 008

Concatenated (declaration) — Ghost relation describing ordered concatenation of two array models.

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

API 009

Element_At (declaration) — Read the array/model element at a valid position; a ghost overload is a specification selector, not an exposed writable view.

Before this operation, establish:

Index in A'Range

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

API 010

Without_Last (declaration) — Ghost array slice excluding the last element; requires a nonempty source.

Before this operation, establish:

A'Length > 0

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

API 011

Reversal (declaration) — Ghost relation: A is B in the opposite order, element by element, both indexed from 1.

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

API 012

Count_Of (declaration) — Ghost count of the elements equal to Item among A's first Last elements; Count states its result with it.

Before this operation, establish:

Last <= A'Length and then (Last = 0 or else A'First = 1)

On normal return the declared contract establishes:

Count_Of'Result <= Last

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

API 013

Is_Permutation (declaration) — Ghost relation: A and B hold the same elements, each the same number of times (by Count_Of). The sorting generics state their results with it.

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

API 014

Vector (declaration) — Limited reclaimed growable vector, initially empty. Container aggregates use Empty/Append; explicit Copy and Move govern whole-value transfers.

Declared interface:

type Vector is limited private
  with Default_Initial_Condition => Length (Vector) = 0,
       Finalizable => (Finalize => Clear, Relaxed_Finalization => True),
       Iterable => (First => Iter_First, Next => Iter_Next, Has_Element => Iter_Has_Element, Element => Iter_Element),
       Aggregate => (Empty => Empty, Add_Unnamed => Append);

API 015

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

On normal return the declared contract establishes:

Length'Result < Verada.Storage.Length_Bound

API 016

Empty (declaration) — Construct a logical empty value for the supported container-aggregate path.

On normal return the declared contract establishes:

Length (Empty'Result) = 0

API 017

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:

Model'Result'Length = Length (Container)
               and then (Model'Result'Length = 0 or else Model'Result'First = 1)

API 018

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)

On normal return the declared contract establishes:

Element'Result = Model (Container) (Index)

API 019

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

On normal return the declared contract establishes:

Model (Container) = Model (Container)'Old & New_Item

         and Appended (Model (Container), Model (Container)'Old, New_Item)

API 020

Insert (declaration) — Add a new element/pair at the family's specified position/order. Absence, room and cursor/index requirements are independent caller obligations.

Before this operation, establish:

Before <= Length (Container) + 1

On normal return the declared contract establishes:

Inserted (Model (Container), Model (Container)'Old, Before, New_Item)

API 021

Pop (declaration) — Remove and return a logical element through its out argument. The indexed and last-element overloads have different index/nonempty requirements.

Before this operation, establish:

Index <= Length (Container)

On normal return the declared contract establishes:

Removed (Model (Container), Model (Container)'Old, Index)
               and Item = Element_At (Model (Container)'Old, Index)

API 022

Extend (declaration) — Append all source vector elements with the precise sum-of-lengths guard; overlapping mutable/source owners must satisfy alias analysis.

On normal return the declared contract establishes:

Concatenated (Model (Container), Model (Container)'Old, Model (Items))

API 023

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:

Same_Except (Model (Container), Model (Container)'Old, Index)
               and Element (Container, Index) = New_Item

API 024

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

Before this operation, establish:

Length (Container) > 0

On normal return the declared contract establishes:

Model (Container) = Without_Last (Model (Container)'Old)

API 025

Pop (declaration) — Remove and return a logical element through its out argument. The indexed and last-element overloads have different index/nonempty requirements.

Before this operation, establish:

Length (Container) > 0

On normal return the declared contract establishes:

Item = Last_Of (Model (Container)'Old)
               and Model (Container) = Without_Last (Model (Container)'Old)

API 026

Copy (declaration) — Explicitly create the source's logical contents in a mutable target. Observe language alias/ownership rules; this is not a shallow owner assignment.

On normal return the declared contract establishes:

Model (Target) = Model (Source)

API 027

Move (declaration) — Transfer the source value into the target and leave the source empty according to the contract; do not retain invalidated views.

On normal return the declared contract establishes:

Model (To) = Model (From)'Old and then Length (From) = 0

API 028

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 029

Contains (declaration) — Python's x in xs: whether some element equals Item, by the element type's equality.

API 030

Index (declaration) — Python's xs.index(x) with positions from 1: the position of the first element equal to Item, which must be present.

Before this operation, establish:

Contains (Container, Item)

On normal return the declared contract establishes:

Index'Result <= Length (Container)
               and then Element (Container, Index'Result) = Item
               and then (for all J in 1 .. Index'Result - 1 => Element (Container, J) /= Item)

API 031

Count (declaration) — Python's xs.count(x): how many elements equal Item, stated through Count_Of over the model.

On normal return the declared contract establishes:

Count'Result = Count_Of (Model (Container), Item, Length (Container))
               and then Count'Result <= Length (Container)
               and then (Count'Result = 0) = not Contains (Container, Item)

API 032

Remove (declaration) — Python's xs.remove(x): take out the first element equal to Item, which must be present; later elements move one place back.

Before this operation, establish:

Contains (Container, Item)

On normal return the declared contract establishes:

Removed (Model (Container), Model (Container)'Old, Index (Container, Item)'Old)

API 033

Delete (declaration) — Python's del xs[i] and the statement xs.pop(i): take out the element at Index without returning it; later elements move one place back.

Before this operation, establish:

Index <= Length (Container)

On normal return the declared contract establishes:

Removed (Model (Container), Model (Container)'Old, Index)

API 034

Reverse_Elements (declaration) — Python's xs.reverse(): reverse the elements in place.

On normal return the declared contract establishes:

Length (Container) = Length (Container)'Old
               and Reversal (Model (Container), Model (Container)'Old)

API 035

Reversed (declaration) — Python's list(reversed(xs)): a new vector of the elements in the opposite order; the argument is unchanged.

On normal return the declared contract establishes:

Length (Reversed'Result) = Length (Container)
               and then Reversal (Model (Reversed'Result), Model (Container))

API 036

"+" (declaration) — Python's xs + ys: a new vector of Left's elements followed by Right's, under the sum-of-lengths guard.

On normal return the declared contract establishes:

Length ("+"'Result) = Length (Left) + Length (Right)
               and then Concatenated (Model ("+"'Result), Model (Left), Model (Right))

API 037

"*" (declaration) — Python's xs * n: a new vector of Left's elements Right times over, empty when Right is not positive. The postcondition states each element a copy at a time: in the first copy Left's own, after it the one a copy before; Lemma_Repeat_Element gives an element by its place in its copy.

On normal return the declared contract establishes:

Length ("*"'Result) = (if Right > 0 then Length (Left) * Right else 0)
               and then (for all I in 1 .. Length ("*"'Result) =>
                           (if I <= Length (Left) then Element ("*"'Result, I) = Element (Left, I)
                            else Element ("*"'Result, I) = Element ("*"'Result, I - Length (Left))))

API 038

Lemma_Repeat_Element (declaration) — Ghost lemma: the element at I of Left * N is Left's at I's place in its copy, (I - 1) mod Length (Left) + 1. It is what the postcondition of "*" says a copy at a time, by place; call it where a proof wants that form. It is proved once, by induction on I, where a solver's search over mod by a length is not stable under mutation.

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

Before this operation, establish:

Length (Left) > 0 and then N > 0 and then I <= Length (Left * N)

On normal return the declared contract establishes:

Element (Left * N, I) = Element (Left, (I - 1) mod Length (Left) + 1)

API 039

"*" (declaration) — Python's n * xs: the same repetition with the count first.

On normal return the declared contract establishes:

Length ("*"'Result) = (if Left > 0 then Length (Right) * Left else 0)
               and then (for all I in 1 .. Length ("*"'Result) =>
                           (if I <= Length (Right) then Element ("*"'Result, I) = Element (Right, I)
                            else Element ("*"'Result, I) = Element ("*"'Result, I - Length (Right))))

API 040

Generic_Sort (declaration) — A generic procedure whose formal "<" (by default the visible one) orders the elements: it sorts the vector in place into nondescending order, as Python's xs.sort(), leaving a permutation of the old contents. The precondition asks only that "<" never hold both ways between the vector's elements. Equal elements keep their order, a fact the contract does not state.

Before this operation, establish:

(for all I in 1 .. Length (Container) =>
                 (for all J in 1 .. Length (Container) =>
                    (if Element (Container, I) < Element (Container, J)
                     then not (Element (Container, J) < Element (Container, I)))))

On normal return the declared contract establishes:

Length (Container) = Length (Container)'Old
               and (for all I in 1 .. Length (Container) - 1 =>
                           not (Element (Container, I + 1) < Element (Container, I)))
               and Is_Permutation (Model (Container), Model (Container)'Old)

API 041

Generic_Sorted (declaration) — A generic function: a new vector of the elements in the order Generic_Sort gives, as Python's sorted(xs); the argument is unchanged.

Before this operation, establish:

(for all I in 1 .. Length (Container) =>
                 (for all J in 1 .. Length (Container) =>
                    (if Element (Container, I) < Element (Container, J)
                     then not (Element (Container, J) < Element (Container, I)))))

On normal return the declared contract establishes:

Length (Generic_Sorted'Result) = Length (Container)
               and then (for all I in 1 .. Length (Generic_Sorted'Result) - 1 =>
                           not (Element (Generic_Sorted'Result, I + 1) < Element (Generic_Sorted'Result, I)))
               and then Is_Permutation (Model (Generic_Sorted'Result), Model (Container))

API 042

Generic_Minimum (declaration) — A generic function: Python's min(xs) of a nonempty vector, the first least element (no element is below it, and it is below every element before it). The precondition asks that "<" be a strict weak order over the vector's elements.

Before this operation, establish:

Length (Container) > 0
              and then (for all I in 1 .. Length (Container) =>
                          (for all J in 1 .. Length (Container) =>
                             (if Element (Container, I) < Element (Container, J)
                              then not (Element (Container, J) < Element (Container, I)))))
              and then (for all I in 1 .. Length (Container) =>
                          (for all J in 1 .. Length (Container) =>
                             (for all K in 1 .. Length (Container) =>
                                (if Element (Container, I) < Element (Container, J)
                                 then Element (Container, I) < Element (Container, K)
                                      or else Element (Container, K) < Element (Container, J)))))

On normal return the declared contract establishes:

(for all J in 1 .. Length (Container) => not (Element (Container, J) < Generic_Minimum'Result))
               and then (for some K in 1 .. Length (Container) =>
                           Element (Container, K) = Generic_Minimum'Result
                           and then (for all J in 1 .. K - 1 => Generic_Minimum'Result < Element (Container, J)))

API 043

Generic_Maximum (declaration) — A generic function: Python's max(xs) of a nonempty vector, the first greatest element (no element is above it, and it is above every element before it). The precondition asks that "<" be a strict weak order over the vector's elements.

Before this operation, establish:

Length (Container) > 0
              and then (for all I in 1 .. Length (Container) =>
                          (for all J in 1 .. Length (Container) =>
                             (if Element (Container, I) < Element (Container, J)
                              then not (Element (Container, J) < Element (Container, I)))))
              and then (for all I in 1 .. Length (Container) =>
                          (for all J in 1 .. Length (Container) =>
                             (for all K in 1 .. Length (Container) =>
                                (if Element (Container, I) < Element (Container, J)
                                 then Element (Container, I) < Element (Container, K)
                                      or else Element (Container, K) < Element (Container, J)))))

On normal return the declared contract establishes:

(for all J in 1 .. Length (Container) => not (Generic_Maximum'Result < Element (Container, J)))
               and then (for some K in 1 .. Length (Container) =>
                           Element (Container, K) = Generic_Maximum'Result
                           and then (for all J in 1 .. K - 1 => Element (Container, J) < Generic_Maximum'Result))

API 044

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

API 045

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

API 046

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

API 047

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

Before this operation, establish:

Iter_Has_Element (Container, Position)

API 048

Slice (declaration) — Return a new vector of the elements after position From up to position To, positions counted from 0 as Python's xs[From:To] counts them (Vibe's list slices, with their bounds already kept within the vector by Verada.Vibe.Slice_Bound). The source is unchanged.

Before this operation, establish:

From <= Length (Container) and then To <= Length (Container)

On normal return the declared contract establishes:

Length (Slice'Result) = (if From < To then To - From else 0)
and then (for all J in 1 .. Length (Slice'Result) => Element (Slice'Result, J) = Element (Container, From + J))

API 049

Is_Empty (declaration) — Whether the vector has no elements: Length (Container) = 0 (Varc's xs.is_empty()).