DEVELOPMENT EDITION · 769442725406
Library Reference
On this page
Generic package Verada.Containers.Unbounded.Maps
Verada.Containers.Unbounded.Maps: maps of any size from keys to elements, on the heap and freed where the map dies (a reclaimed type), the unbounded twin of the bounded maps. The map is limited: copies are made explicitly. Its models are the arrays of its keys (each once, in insertion order) and of their elements, from 1. Only memory limits the size: Insert raises Storage_Error when memory cannot hold the result (Verada.Storage).
generic
type Key_Type is private;
type Element_Type is private;Key_Array
type Key_Array is array (Positive range <>) of Key_Type;Element_Array
type Element_Array is array (Positive range <>) of Element_Type;Map
type Map is limited private
with Default_Initial_Condition => Length (Map) = 0,
Finalizable => (Finalize => Clear, Relaxed_Finalization => True);Length
function Length (Container : Map) return Natural
with Global => null,
Post => Length'Result < Verada.Storage.Length_Bound;Keys_Model
function Keys_Model (Container : Map) return Key_Array
with Global => null,
Post => Keys_Model'Result'Length = Length (Container)
and then (Keys_Model'Result'Length = 0 or else Keys_Model'Result'First = 1);Elements_Model
function Elements_Model (Container : Map) return Element_Array
with Global => null,
Post => Elements_Model'Result'Length = Length (Container)
and then (Elements_Model'Result'Length = 0 or else Elements_Model'Result'First = 1);Key
function Key (Container : Map; Index : Positive) return Key_Type
with Global => null,
Pre => Index <= Length (Container),
Post => Key'Result = Keys_Model (Container) (Index);Element
function Element (Container : Map; Index : Positive) return Element_Type
with Global => null,
Pre => Index <= Length (Container),
Post => Element'Result = Elements_Model (Container) (Index);Find
function Find (Container : Map; K : Key_Type) return Natural
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 first position of K, or 0 when no key is K
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);Same_Elements_Except
function Same_Elements_Except (Container : Map; Old : Element_Array; K : Key_Type) return Boolean is
(Old'Length = Length (Container)
and then (Old'Length = 0 or else Old'First = 1)
and then (for all I in 1 .. Length (Container) => Key (Container, I) = K or else Element (Container, I) = Old (I)))
with Ghost;the elements of Container are those of Old, except perhaps for 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),
Post => Keys_Model (Container) = Keys_Model (Container)'Old & K
and Elements_Model (Container) = Elements_Model (Container)'Old & New_Item;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 => Keys_Model (Container) = Keys_Model (Container)'Old
and Length (Container) = Length (Container)'Old
and (for all I in 1 .. Length (Container) => (if Key (Container, I) = K then Element (Container, I) = New_Item))
and Same_Elements_Except (Container, Elements_Model (Container)'Old, K);K now maps to New_Item
Copy
procedure Copy (Source : Map; Target : in out Map)
with Global => null,
Post => Keys_Model (Target) = Keys_Model (Source) and then Elements_Model (Target) = Elements_Model (Source);