DEVELOPMENT EDITION · 769442725406
Library Reference
On this page

Verada.Containers.Linked_Lists

A doubly linked list proved whole as a proof enclave.

Read the family guide for representation, ownership and cost rules. The complete declaration page retains exact signatures/contracts; the source specification is the implementation baseline.

Availability and ownership

Cells are linked both ways, which ownership forbids outside an enclave; the heap engine proves each operation against Model and proves that it changes only its own list's cells, so clients reason about a list as its model. Only memory limits the length: Append and Prepend raise Storage_Error when memory cannot hold one more element. A list is limited: it is not copied by assignment, and it is cleared when it ends.

Import and instantiate

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

with Verada.Containers.Linked_Lists;
package Instance_Name is new Verada.Containers.Linked_Lists (Integer);
import Verada.Containers.Linked_Lists;
package Instance_Name = new Verada.Containers.Linked_Lists<Integer>;

A Vibe module imports this unit's names with from Verada.Containers.Linked_Lists import Name; see library use across syntaxes. In Varc, keep each name's declared spelling and write & on arguments the call changes.

API 001

Generic formals (declaration) — The element type: any definite nonlimited private actual; elements are copied into and out of the list.

Declared interface:

generic
   type Element_Type is private;

API 002

Element_Sequences (declaration) — The functional sequences of elements this instance makes, in which Model states the list's contents.

API 003

List (declaration) — A doubly linked list: limited, empty by default, and cleared (every cell freed) when it ends; its cells are a proof enclave's, proved against its model.

Its default initial condition:

Length (List) = 0

API 004

Model (declaration) — The elements, first to last, as a ghost sequence: the value every other contract is stated in.

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

API 005

Length (declaration) — The number of elements.

On normal return the declared contract establishes:

Length'Result = Element_Sequences.Length (Model (L))

API 006

First_Element (declaration) — The first element.

Before this operation, establish:

Length (L) > 0

On normal return the declared contract establishes:

First_Element'Result = Element_Sequences.Get (Model (L), 1)

API 007

Last_Element (declaration) — The last element.

Before this operation, establish:

Length (L) > 0

On normal return the declared contract establishes:

Last_Element'Result = Element_Sequences.Get (Model (L), Length (L))

API 008

Clear (declaration) — Remove every element and free its cell.

On normal return the declared contract establishes:

Length (L) = 0

API 009

Append (declaration) — Add an element after the last.

On normal return the declared contract establishes:

Model (L) = Element_Sequences.Add (Model (L)'Old, X)

API 010

Prepend (declaration) — Add an element before the first.

On normal return the declared contract establishes:

Model (L) = Element_Sequences.Prepend (Model (L)'Old, X)

API 011

Remove_Last (declaration) — Remove the last element and give it in X; it always terminates.

Before this operation, establish:

Length (L) > 0

On normal return the declared contract establishes:

Model (L)'Old = Element_Sequences.Add (Model (L), X)

API 012

Remove_First (declaration) — Remove the first element and give it in X.

Before this operation, establish:

Length (L) > 0

On normal return the declared contract establishes:

Model (L)'Old = Element_Sequences.Prepend (Model (L), X)

API 013

Update_Element (declaration) — A generic procedure: instantiated with a procedure Process and a ghost function Updated that says what Process makes of an element, it changes the I'th element in place, in its cell. The element is not copied out and back, and no pointer into the list outlives the call. Process must not use global state (Global => null), so it cannot reach the list while it runs.

Before this operation, establish:

I <= Length (L)

On normal return the declared contract establishes:

Model (L) = Element_Sequences.Set (Model (L)'Old, I, Updated (Element_Sequences.Get (Model (L)'Old, I)))