DEVELOPMENT EDITION · 769442725406
Library Reference
On this page
Generic package Verada.Containers.Formal.Ordered_Sets
Verada predefined library: bounded sets of at most Capacity elements, kept in increasing order of "<" (which must be a strict order), specified through Length and Element like the bounded vectors: the elements are Element (S, 1) .. Element (S, Length (S)).
generic
type Element_Type is private;
Capacity : Positive;
with function "<" (Left, Right : Element_Type) return Boolean is <>;Extended_Index
subtype Extended_Index is Natural range 0 .. Capacity;Index_Type
subtype Index_Type is Positive range 1 .. Capacity;Set
type Set is private
with Default_Initial_Condition => Length (Set) = 0,
Iterable => (First => Iter_First, Next => Iter_Next, Has_Element => Iter_Has_Element, Element => Iter_Element);Length
function Length (Container : Set) return Extended_Index
with Global => null;Is_Empty
function Is_Empty (Container : Set) return Boolean is (Length (Container) = 0);Element
function Element (Container : Set; Index : Index_Type) return Element_Type
with Global => null,
Pre => Index <= Length (Container);Models
package Models is new Verada.Containers.Functional.Sequences (Element_Type);the functional model: the elements in increasing order, as a sequence
Model
function Model (Container : Set) return Models.Sequence
with Ghost,
Global => null,
Post => Models.Length (Model'Result) = Length (Container)
and then (for all I in 1 .. Length (Container) => Models.Get (Model'Result, I) = Element (Container, I));Contains
function Contains (Container : Set; Item : Element_Type) return Boolean is
(for some I in 1 .. Length (Container) => Element (Container, I) = Item);Clear
procedure Clear (Container : in out Set)
with Global => null,
Post => Length (Container) = 0;Insert
procedure Insert (Container : in out Set; Item : Element_Type)
with Global => null,
Pre => not Contains (Container, Item) and then Length (Container) < Capacity,
Post => Length (Container) = Length (Container)'Old + 1
and then Contains (Container, Item)
and then (for all I in 1 .. Length (Container'Old) => Contains (Container, Element (Container'Old, I)))
and then (for all I in 1 .. Length (Container) => Element (Container, I) = Item or else Contains (Container'Old, Element (Container, I)));Item joins the set, in its place in the order
Include
procedure Include (Container : in out Set; Item : Element_Type)
with Global => null,
Pre => Contains (Container, Item) or else Length (Container) < Capacity,
Post => Contains (Container, Item)
-- (the same in the model, so that callers need not carry the witness there)
and then Models.Contains (Model (Container), Item)
and then (for all I in 1 .. Length (Container'Old) => Contains (Container, Element (Container'Old, I)))
and then (for all I in 1 .. Length (Container) => Element (Container, I) = Item or else Contains (Container'Old, Element (Container, I)));Item joins the set unless it is there already
Iter_First
function Iter_First (Container : Set) return Natural is (1);for E of S and quantifiers over S: in increasing order
Iter_Next
function Iter_Next (Container : Set; Position : Natural) return Natural is
(if Position < Natural'Last then Position + 1 else Position);Iter_Has_Element
function Iter_Has_Element (Container : Set; Position : Natural) return Boolean is
(Position in 1 .. Length (Container));Iter_Element
function Iter_Element (Container : Set; Position : Natural) return Element_Type is
(Element (Container, Position))
with Pre => Iter_Has_Element (Container, Position);