DEVELOPMENT EDITION · 769442725406
Library Reference
On this page

Verada.Containers.Functional.Maps

Ghost extensional finite maps from unique keys to values.

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

Positions pair key/value but do not promise stable iteration order. Get/Set/Remove require a present key; Add requires absence. Choose returns a key.

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

A Vibe module imports this unit's names with from Verada.Containers.Functional.Maps import Name; 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.

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

Declared interface:

generic
   type Key_Type is private;
   type Element_Type is private;

API 002

Map (declaration) — Private ghost finite map with extensional pair equality; positional enumeration pairs keys/values but is not a stable public cursor protocol.

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

Declared interface:

type Map is private;

API 003

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

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

API 004

Key_At (declaration) — Read a key at an existing model/dictionary position; the family specifies whether that ordering carries meaning.

Before this operation, establish:

Position <= Length (Container)

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

API 005

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:

Position <= Length (Container)

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

API 006

Has_Key (declaration) — Test membership in the ghost map's key domain.

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

API 007

Is_Empty (declaration) — Test whether logical length is zero; this is safe before an element selection.

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

API 008

Get (declaration) — Read a present sequence position or map key, following the declared actual parameter type.

Before this operation, establish:

Has_Key (Container, Key)

On normal return the declared contract establishes:

(for all I in 1 .. Length (Container) => (if Key_At (Container, I) = Key then Get'Result = Element_At (Container, I)))

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

API 009

Empty_Map (declaration) — Construct the empty ghost map.

On normal return the declared contract establishes:

Length (Empty_Map'Result) = 0

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

API 010

Keys_Included (declaration) — State that every source key occurs in the destination, without asserting equal associated values.

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

API 011

Same_Keys (declaration) — State equal key domains using cardinality and inclusion.

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

API 012

Has_Pair (declaration) — State that the destination has the key/value pair at a particular source position.

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

API 013

"<=" (declaration) — The declared comparison: ordinary numeric order, sequence prefix, set inclusion or map-pair inclusion according to the parameter types.

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

API 014

"=" (declaration) — Equality in this declared value/model domain; the family defines whether sequence order, set membership, map pairs or logical text contents are compared.

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

API 015

Keys_Included_Except (declaration) — Permit the named key as the only exception to source-domain inclusion.

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

API 016

Add (declaration) — Return a new ghost model with an appended/new entry, leaving the input value unchanged; absence/capacity requirements still apply.

Before this operation, establish:

not Has_Key (Container, New_Key) and then Length (Container) < Natural'Last

On normal return the declared contract establishes:

Length (Add'Result) = Length (Container) + 1
               and then Key_At (Add'Result, Length (Add'Result)) = New_Key
               and then Element_At (Add'Result, Length (Add'Result)) = New_Item
               and then (for all I in 1 .. Length (Container) =>
                           Key_At (Add'Result, I) = Key_At (Container, I) and then Element_At (Add'Result, I) = Element_At (Container, I))

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

API 017

Set (declaration) — Return a new ghost model replacing a present value, or mutate an owned string to the supplied contents in that overload.

Before this operation, establish:

Has_Key (Container, Key)

On normal return the declared contract establishes:

Length (Set'Result) = Length (Container)
               and then (for all I in 1 .. Length (Container) =>
                           Key_At (Set'Result, I) = Key_At (Container, I)
                           and then Element_At (Set'Result, I) = (if Key_At (Container, I) = Key then New_Item else Element_At (Container, I)))

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

API 018

Remove (declaration) — Return/remove the selected present entry according to this family; ghost functional updates return a new value while arena mutation invalidates its handle.

Before this operation, establish:

Has_Key (Container, Key)

On normal return the declared contract establishes:

Length (Remove'Result) = Length (Container) - 1
               and then not Has_Key (Remove'Result, Key)
               and then Remove'Result <= Container
               and then Keys_Included_Except (Container, Remove'Result, Key)
               and then (for all I in 1 .. Length (Container) => Key_At (Container, I) = Key or else Has_Pair (Remove'Result, Container, I))

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

API 019

Choose (declaration) — Return a member/key from a nonempty ghost set/map; no selection order is promised.

Before this operation, establish:

not Is_Empty (Container)

On normal return the declared contract establishes:

Has_Key (Container, Choose'Result)

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