DEVELOPMENT EDITION · 769442725406
Library Reference
On this page

Verada.Containers.Unbounded.Dictionaries

Insertion-order dictionaries used by Vibe dict.

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

Include inserts or replaces, keeping the order in which keys were first added; Delete and Pop remove a key, and the others keep their order. Update includes another dictionary's pairs. Lookup compares keys one by one. A Dictionary is limited: Copy makes an explicit copy, and there is no Move.

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

A Vibe module imports this unit's names with from Verada.Containers.Unbounded.Dictionaries 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.

Declared interface:

generic
   type Key_Type is private;
   type Element_Type is private;

API 002

Key_Array (declaration) — Unconstrained Positive-indexed key value array for content snapshots/contracts. A particular Model result has its own lower-bound guarantee; the array type alone does not force every object to start at 1.

Declared interface:

type Key_Array is array (Positive range <>) of Key_Type;

API 003

Element_Array (declaration) — Unconstrained Positive-indexed element value array for content snapshots/contracts. A particular Model result has its own lower-bound guarantee; the array type alone does not force every object to start at 1.

Declared interface:

type Element_Array is array (Positive range <>) of Element_Type;

API 004

Same_Except (declaration) — Ghost relation saying corresponding arrays have equal bounds and agree except at the named position.

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

API 005

Removed (declaration) — Ghost relation on key arrays: A is B without its key at At_Index, the later keys one place back.

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

API 006

Removed (declaration) — The same ghost relation on value arrays; Delete and Pop state the change to both models with these.

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

API 007

Dictionary (declaration) — Limited insertion-order dictionary state, initially empty, owning key/value vectors through its private composite. No public Copy/Move/Remove is declared.

Declared interface:

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

API 008

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

On normal return the declared contract establishes:

Length'Result < Verada.Storage.Length_Bound

API 009

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)

API 010

Value_At (declaration) — Read the dictionary value at a present insertion-order position.

Before this operation, establish:

Position <= Length (Container)

API 011

Key_Model (declaration) — Observe dictionary keys in first-insertion order, indexed from one.

On normal return the declared contract establishes:

Key_Model'Result'First = 1 and then Key_Model'Result'Last = Length (Container)
               and then (for all I in 1 .. Length (Container) => Key_Model'Result (I) = Key_At (Container, I))

API 012

Value_Model (declaration) — Observe dictionary values in the same positions as Key_Model.

On normal return the declared contract establishes:

Value_Model'Result'First = 1 and then Value_Model'Result'Last = Length (Container)
               and then (for all I in 1 .. Length (Container) => Value_Model'Result (I) = Value_At (Container, I))

API 013

Position (declaration) — Find a dictionary key's first position, zero iff absent; retain its finite range guarantee.

On normal return the declared contract establishes:

Position'Result <= Length (Container)
               and then (if Position'Result = 0
                         then (for all I in 1 .. Length (Container) => Key_At (Container, I) /= Key)
                         else Key_At (Container, Position'Result) = Key
                              and then (for all I in 1 .. Position'Result - 1 => Key_At (Container, I) /= Key))

API 014

Contains (declaration) — Test the family's declared membership/search relation; it is not a mutation or a guarantee of constant-time lookup.

API 015

Value (declaration) — Return the value for a present map/dictionary key; establish Contains before lookup.

Before this operation, establish:

Contains (Container, Key)

API 016

Include (declaration) — Ensure an item/key is present: preserve a duplicate set member or upsert a dictionary value. Only a genuinely new entry needs extra room.

On normal return the declared contract establishes:

(Contains (Container, Key) and then Value (Container, Key) = New_Item)
               and Length (Container) = Length (Container)'Old + (if Contains (Container, Key)'Old then 0 else 1)
               and Key_Model (Container) (1 .. Length (Container)'Old) = Key_Model (Container)'Old
               and Same_Except (Value_Model (Container) (1 .. Length (Container)'Old), Value_Model (Container)'Old, Position (Container, Key))

API 017

Kept_Unless (declaration) — Ghost predicate for Update: each value Old held at the first positions is kept, except those of keys that Other has.

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

API 018

Get (declaration) — Python's d.get(k, default): Key's value when it is a key, else Default.

API 019

Delete (declaration) — Python's del d[k] and the statement d.pop(k): remove a present key and its value; the other keys and values keep their order.

Before this operation, establish:

Contains (Container, Key)

On normal return the declared contract establishes:

not Contains (Container, Key)
               and Length (Container) = Length (Container)'Old - 1
               and Removed (Key_Model (Container), Key_Model (Container)'Old, Position (Container, Key)'Old)
               and Removed (Value_Model (Container), Value_Model (Container)'Old, Position (Container, Key)'Old)

API 020

Pop (declaration) — Python's v = d.pop(k): as Delete, with the removed value in Item.

Before this operation, establish:

Contains (Container, Key)

On normal return the declared contract establishes:

Item = Value (Container, Key)'Old
               and not Contains (Container, Key)
               and Length (Container) = Length (Container)'Old - 1
               and Removed (Key_Model (Container), Key_Model (Container)'Old, Position (Container, Key)'Old)
               and Removed (Value_Model (Container), Value_Model (Container)'Old, Position (Container, Key)'Old)

API 021

Update (declaration) — Python's d.update(other): each of Other's keys, in Other's order, takes its value there. Existing keys keep their positions, new keys follow them, and a key that Other lacks keeps its value. The precondition bounds the combined length.

On normal return the declared contract establishes:

(for all I in 1 .. Length (Other) =>
                  Contains (Container, Key_At (Other, I))
                  and then Value (Container, Key_At (Other, I)) = Value (Other, Key_At (Other, I)))
               and Length (Container) in Length (Container)'Old .. Length (Container)'Old + Length (Other)
               and Key_Model (Container) (1 .. Length (Container)'Old) = Key_Model (Container)'Old
               and (for all I in Length (Container)'Old + 1 .. Length (Container) => Contains (Other, Key_At (Container, I)))
               and Kept_Unless (Container, Other, Value_Model (Container)'Old)

API 022

Copy (declaration) — Python's d.copy(): make Target a separate dictionary with Source's keys and values in the same order.

On normal return the declared contract establishes:

Key_Model (Target) = Key_Model (Source) and Value_Model (Target) = Value_Model (Source)

API 023

Clear (declaration) — Make the logical container empty. Storage release, cursor validity and inactive-slot contents follow this family's lifecycle rules, not a universal secure-erasure contract.

On normal return the declared contract establishes:

Length (Container) = 0

API 024

Iter_First (declaration) — Return the first candidate iteration position. Call Has_Element before selecting an element; empty input can still have a candidate.

API 025

Iter_Next (declaration) — Advance the candidate position under the declared sentinel/finite-bound behavior.

API 026

Iter_Has_Element (declaration) — Test whether an iteration candidate denotes a currently present logical element.

API 027

Iter_Key (declaration) — Read the iteration key after establishing Iter_Has_Element; map/dictionary traversal yields keys.

Before this operation, establish:

Iter_Has_Element (Container, Position)

API 028

Is_Empty (declaration) — Whether the dictionary has no keys: Length (Container) = 0 (Varc's m.is_empty()).