DEVELOPMENT EDITION · 769442725406
Library Reference
Generic package Verada.Containers.Arenas
Verada predefined library: arenas of at most Capacity elements reached through handles, for graphs that ownership alone cannot express: shared referents, cycles, parent links. A handle is a slot and a generation; removing an element makes its handles invalid, so that using one is a proof failure rather than a read of a reused slot. Each operation says that every other element is unchanged. Model gives the valid handles and their elements as a functional map.
generic
type Element_Type is private;
Capacity : Positive;Handle
subtype Handle is Long_Long_Integer range 0 .. Long_Long_Integer'Last;a handle: no handle (0), or a generation and a slot, as Generation * Capacity + Slot
No_Handle
No_Handle : constant Handle := 0;Arena
type Arena is private
with Default_Initial_Condition => (for all H in Handle => not Valid (Arena, H));Valid
function Valid (A : Arena; H : Handle) return Boolean
with Global => null,
Post => (if Valid'Result then H /= No_Handle);Element
function Element (A : Arena; H : Handle) return Element_Type
with Global => null,
Pre => Valid (A, H);Models
package Models is new Verada.Containers.Functional.Maps (Handle, Element_Type);the functional model: the valid handles and their elements, as a functional map
Model
function Model (A : Arena) return Models.Map
with Ghost,
Global => null,
Post => (for all G in Handle => Models.Has_Key (Model'Result, G) = Valid (A, G))
and then (for all I in 1 .. Models.Length (Model'Result) =>
Valid (A, Models.Key_At (Model'Result, I))
and then Models.Element_At (Model'Result, I) = Element (A, Models.Key_At (Model'Result, I)));Has_Room
function Has_Room (A : Arena) return Boolean
with Global => null;whether another element fits
Insert
procedure Insert (A : in out Arena; Item : Element_Type; H : out Handle)
with Global => null,
Pre => Has_Room (A),
Post => Valid (A, H) and then Element (A, H) = Item
and then not Valid (A'Old, H)
and then (for all G in Handle => (if G /= H then Valid (A, G) = Valid (A'Old, G)))
and then (for all G in Handle => (if G /= H and then Valid (A'Old, G) then Element (A, G) = Element (A'Old, G)));Replace_Element
procedure Replace_Element (A : in out Arena; H : Handle; Item : Element_Type)
with Global => null,
Pre => Valid (A, H),
Post => Valid (A, H) and then Element (A, H) = Item
and then Has_Room (A) = Has_Room (A'Old)
and then (for all G in Handle => Valid (A, G) = Valid (A'Old, G))
and then (for all G in Handle => (if G /= H and then Valid (A'Old, G) then Element (A, G) = Element (A'Old, G)));Remove
procedure Remove (A : in out Arena; H : Handle)
with Global => null,
Pre => Valid (A, H),
Post => not Valid (A, H)
and then (for all G in Handle => (if G /= H then Valid (A, G) = Valid (A'Old, G)))
and then (for all G in Handle => (if G /= H and then Valid (A'Old, G) then Element (A, G) = Element (A'Old, G)));the element goes; its handles become invalid for good