DEVELOPMENT EDITION · 769442725406
Library Reference
On this page

Verada.Containers.Hash_Maps

A hash map from integers, 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

A generic over the element type; keys are integers. The table is a cell of the enclave, reached only through the map, and the heap engine proves each operation against Model and proves that it changes only its own map's cells, so clients reason about a map as its model. Only memory limits the keys: Include raises Storage_Error when memory cannot hold one more. It is limited: not copied by assignment, and cleared when it ends. Every operation is proved against its contract at the default proof budget, Include and the doubling of the table it may make among them.

Import

with Verada.Containers.Hash_Maps;
import Verada.Containers.Hash_Maps;

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

API 001

Element_Type (declaration) — The elements' type, any definite, non-limited type; keys are integers.

API 002

Key_Sequences (declaration) — The functional sequences of keys the model uses.

API 003

Element_Sequences (declaration) — The functional sequences of elements the model uses.

API 004

Map_Model (declaration) — A map's value: its keys, each once, in the order they were first added, and the element of each at the same position.

API 005

Has_Key (declaration) — Whether a model holds a key.

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

API 006

Position (declaration) — Where a key the model holds is in it.

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

Its precondition:

Has_Key (M, K)

On normal return the declared contract establishes:

Position'Result <= Key_Sequences.Length (M.Keys) and then Key_Sequences.Get (M.Keys, Position'Result) = K

API 007

Included_Keys (declaration) — The keys after including a key: the same if it is there, else the key added last.

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

Its precondition:

Key_Sequences.Length (M.Keys) < Verada.Storage.Length_Bound

API 008

Included_Elements (declaration) — The elements after including a key with an element: the key's element replaced if it is there, else the element added last.

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

Its precondition:

Key_Sequences.Length (M.Keys) < Verada.Storage.Length_Bound
and then Key_Sequences.Length (M.Keys) = Element_Sequences.Length (M.Elements)

API 009

Map (declaration) — A hash map from integers: limited, empty by default, cleared when it ends. Its entries live in one table with open addressing and linear probing, which doubles when half full; the heap engine proves its operations against Model.

Its default initial condition:

Key_Sequences.Length (Model (Map).Keys) = 0

API 010

Model (declaration) — The map's value, a ghost Map_Model, in which the other contracts are stated.

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

On normal return the declared contract establishes:

Key_Sequences.Length (Model'Result.Keys) = Element_Sequences.Length (Model'Result.Elements)

API 011

Length (declaration) — The number of keys.

On normal return the declared contract establishes:

Length'Result = Key_Sequences.Length (Model (M).Keys)

API 012

Contains (declaration) — Whether the map holds a key.

On normal return the declared contract establishes:

Contains'Result = Has_Key (Model (M), K)

API 013

Element (declaration) — The element of a key the map holds.

Its precondition:

Has_Key (Model (M), K)

On normal return the declared contract establishes:

(for all I in 1 .. Length (M) =>
(if Key_Sequences.Get (Model (M).Keys, I) = K then Element_Sequences.Get (Model (M).Elements, I) = Element'Result))

API 014

Include (declaration) — Add a key with its element, or replace the element of a key already there.

On normal return the declared contract establishes:

Model (M).Keys = Included_Keys (Model (M)'Old, K)
and Model (M).Elements = Included_Elements (Model (M)'Old, K, E)

API 015

Clear (declaration) — Remove every key and free the table.

On normal return the declared contract establishes:

Length (M) = 0