DEVELOPMENT EDITION · 769442725406
Library Reference
On this page

Generic package Verada.Containers.Formal.Maps

Verada predefined library: bounded maps of at most Capacity entries from keys to elements, specified through Length, Key and Element at positions 1 .. Length (M): each key at most once. Lookup is by position (a linear search), which keeps the model the prover sees the same as what runs; for K of M gives the keys.

generic
   type Key_Type is private;
   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;

Map

type Map is private
  with Default_Initial_Condition => Length (Map) = 0,
       Iterable => (First => Iter_First, Next => Iter_Next, Has_Element => Iter_Has_Element, Element => Iter_Key);

Length

function Length (Container : Map) return Extended_Index
  with Global => null;

Key

function Key (Container : Map; Index : Index_Type) return Key_Type
  with Global => null,
       Pre => Index <= Length (Container);

Key_Models

package Key_Models is new Verada.Containers.Functional.Sequences (Key_Type);

the functional model: the keys in insertion order, as a sequence

Keys_Model

function Keys_Model (Container : Map) return Key_Models.Sequence
  with Ghost,
       Global => null,
       Post => Key_Models.Length (Keys_Model'Result) = Length (Container)
               and then (for all I in 1 .. Length (Container) => Key_Models.Get (Keys_Model'Result, I) = Key (Container, I));

Element

function Element (Container : Map; Index : Index_Type) return Element_Type
  with Global => null,
       Pre => Index <= Length (Container);

Find

function Find (Container : Map; K : Key_Type) return Extended_Index
  with Global => null,
       Post => (if Find'Result = 0 then (for all I in 1 .. Length (Container) => Key (Container, I) /= K)
                else Find'Result <= Length (Container) and then Key (Container, Find'Result) = K
                     and then (for all I in 1 .. Find'Result - 1 => Key (Container, I) /= K));

the position of K, or 0

Contains

function Contains (Container : Map; K : Key_Type) return Boolean is (Find (Container, K) /= 0);

Value

function Value (Container : Map; K : Key_Type) return Element_Type is
  (Element (Container, Find (Container, K)))
  with Pre => Contains (Container, K);

Clear

procedure Clear (Container : in out Map)
  with Global => null,
       Post => Length (Container) = 0;

Insert

procedure Insert (Container : in out Map; K : Key_Type; New_Item : Element_Type)
  with Global => null,
       Pre => not Contains (Container, K) and then Length (Container) < Capacity,
       Post => Length (Container) = Length (Container)'Old + 1
               and then Key (Container, Length (Container)) = K
               and then Element (Container, Length (Container)) = New_Item
               and then (for all I in 1 .. Length (Container'Old) => Key (Container, I) = Key (Container'Old, I) and then Element (Container, I) = Element (Container'Old, I));

a new entry for K, at the end

Replace

procedure Replace (Container : in out Map; K : Key_Type; New_Item : Element_Type)
  with Global => null,
       Pre => Contains (Container, K),
       Post => Length (Container) = Length (Container)'Old
               and then (for all I in 1 .. Length (Container) => Key (Container, I) = Key (Container'Old, I))
               and then Value (Container, K) = New_Item
               and then (for all I in 1 .. Length (Container) => (if Key (Container, I) /= K then Element (Container, I) = Element (Container'Old, I)));

K now maps to New_Item

Iter_First

function Iter_First (Container : Map) return Natural is (1);

Iter_Next

function Iter_Next (Container : Map; Position : Natural) return Natural is
  (if Position < Natural'Last then Position + 1 else Position);

Iter_Has_Element

function Iter_Has_Element (Container : Map; Position : Natural) return Boolean is
  (Position in 1 .. Length (Container));

Iter_Key

function Iter_Key (Container : Map; Position : Natural) return Key_Type is
  (Key (Container, Position))
  with Pre => Iter_Has_Element (Container, Position);