DEVELOPMENT EDITION · 769442725406
Library Reference
On this page

Generic package Verada.Containers.Linked_Lists

Verada predefined library: a doubly linked list, a proof enclave. Its cells are shared between the links each way, which ownership forbids; the heap engine proves its operations against the list's model, a sequence, and proves that each changes only its own list's cells, so that clients treat a list as the value its model is. Only memory limits the length: Append and Prepend raise Storage_Error when memory cannot hold one more element (Verada.Storage).

generic
   type Element_Type is private;

Element_Sequences

package Element_Sequences is new Verada.Containers.Functional.Sequences (Element_Type);

List

type List is limited private
  with Default_Initial_Condition => Length (List) = 0,
       Finalizable => (Finalize => Clear, Relaxed_Finalization => True);

Model

function Model (L : List) return Element_Sequences.Sequence with Ghost;

the elements, first to last

Length

function Length (L : List) return Natural
  with Post => Length'Result = Element_Sequences.Length (Model (L));

First_Element

function First_Element (L : List) return Element_Type
  with Pre => Length (L) > 0, Post => First_Element'Result = Element_Sequences.Get (Model (L), 1);

Last_Element

function Last_Element (L : List) return Element_Type
  with Pre => Length (L) > 0, Post => Last_Element'Result = Element_Sequences.Get (Model (L), Length (L));

Clear

procedure Clear (L : in out List)
  with Post => Length (L) = 0;

every element removed (and its cell freed: a list that ends is cleared)

Append

procedure Append (L : in out List; X : Element_Type)
  with Post => Model (L) = Element_Sequences.Add (Model (L)'Old, X);

Prepend

procedure Prepend (L : in out List; X : Element_Type)
  with Post => Model (L) = Element_Sequences.Prepend (Model (L)'Old, X);

Remove_Last

procedure Remove_Last (L : in out List; X : out Element_Type)
  with Always_Terminates,
       Pre => Length (L) > 0,
       Post => Model (L)'Old = Element_Sequences.Add (Model (L), X);

Remove_First

procedure Remove_First (L : in out List; X : out Element_Type)
  with Pre => Length (L) > 0,
       Post => Model (L)'Old = Element_Sequences.Prepend (Model (L), X);

Update_Element

generic
   with function Updated (E : Element_Type) return Element_Type with Ghost;
   with procedure Process (E : in out Element_Type)
     with Global => null, Post => E = Updated (E'Old);
procedure Update_Element (L : in out List; I : Positive)
  with Pre => I <= Length (L),
       Post => Model (L) = Element_Sequences.Set (Model (L)'Old, I, Updated (Element_Sequences.Get (Model (L)'Old, I)));

the I'th element changed in place by Process, which Updated describes: the element is not copied out and back, and no pointer into the list outlives the call