On this page
Bounded containers
The formal vector, map, ordered-set and doubly-linked-list packages store at most a positive generic Capacity. Choose them when a fixed storage budget and simple finite models matter. Their storage is inside the object rather than a growable heap buffer. Element copies, finalization and representation still depend on the chosen actual type.
Shared rules and instantiation
Vada and Varc declare explicit package instances. A map needs both key and element actuals; an ordered set additionally resolves a strict ordering operation. Example fragments:
with Verada.Containers.Formal.Maps;
package Table is new Verada.Containers.Formal.Maps (Integer, Integer, 8);import Verada.Containers.Formal.Maps;
package Table = new Verada.Containers.Formal.Maps<Integer, Integer, 8>;
Place the fragment in an appropriate declaration region and call mutable operations with Varc's & marker. Vada is case-insensitive; preserve declared member spelling in Varc. Vibe's list, dict and set annotations select the unbounded containers, not these packages. To use a bounded container from Vibe, wrap it in a Vada or Varc package that exports the operations the Vibe module needs.
All bounded families distinguish capacity from occupancy. A valid declared index can still refer to a slot above current Length. Prove the operation's Pre condition before reading or mutating; a strict program cannot use a capacity exception as its normal control flow. Nonlimited object assignment copies the value and follows its element/resource rules.
Formal vectors
Read the complete vector guide and unit entries. Positions are one-based, Length is zero through Capacity, default initialization is empty, and search uses zero as “no match.” Clear, Append, Replace_Element and Delete_Last have preservation contracts over the remaining sequence. Find_Index's postcondition describes only a nonzero result (a position holding an equal element); to prove that an item is absent, state it with a quantified expression over Element. Model is a ghost functional sequence; Models names its instance.
Formal maps
Formal.Maps is a bounded insertion-order association table, not a hashed map. Key/Element use a position in 1..Length; Value uses a present key. Find returns zero exactly when no matching key exists, or the first matching position under its full contract. Contains tests that search. Insert requires absence and spare capacity, adds the key/value last and preserves earlier pairs. Replace requires presence, preserves keys/length and other values, and updates the matching key. Clear empties the map. There is no declared key deletion operation in this API.
Keys_Model exposes only the ordered key sequence as a ghost model; it does not independently model all values. Iteration produces keys in insertion order through Iter_Key. An index is a position, not a stable handle to an association. Replacing a value preserves its position; clearing invalidates every old present index. Lookup compares keys one by one.
Formal ordered sets
Formal.Ordered_Sets uses equality for membership and a supplied strict < to insert values in order. Supply a strict ordering: the generic does not check that your < is one. Length, Is_Empty, Element and Model observe contents. Insert requires the item absent and room. Include is idempotent for present items and only needs room when inserting a missing value. Clear empties it; there is no declared removal-by-value, union or intersection operation here.
Model is a sequence in representation order, while membership is set-like. Insertion shifts following positions, so a saved numeric index can name a different value after insertion. Membership and insertion search and shift slots one by one; the set is a sorted array, not a search tree. The postconditions state which members are kept; they do not restate the ordering of the whole sequence.
Vector/map/set Iter_First uses candidate 1 and checks membership before reading. Iter_Next stops at Natural'Last, so a capacity below Natural'Last keeps the end of iteration distinct.
Formal doubly linked lists
Formal.Doubly_Linked_Lists has fixed node slots and explicit Cursor values. No_Element has Node=0. Length/Is_Empty/Is_Full measure occupancy. Node_Index and Index_Of map a node/cursor to its current one-based sequence place, or zero if absent, and the ghost Node_At gives the node at a place, in which Node_Index's contract says exactly which place it is. Has_Element is the safe membership test. Element requires membership.
First/Last return No_Element when empty. Next/Previous require a present cursor and return No_Element beyond the corresponding end. Find returns a matching cursor or proves no equal item exists; its implementation searches from the front. Contains is Find != No_Element.
Insert puts a new item before a present cursor, or at the end for No_Element, and returns its cursor through an out argument. Append/Prepend insert at the ends. Replace_Element keeps all cursor places and other values. Delete consumes an in-out cursor, removes its element and sets that argument to No_Element. Delete_First/Delete_Last require nonempty lists. Clear empties it. Inserted/Removed specify sequence changes; Same_Places and Places_Shifted_Up/Down specify surviving cursor places and are ghost predicates, not mutating operations.
A surviving cursor keeps its node identity as other nodes are inserted/deleted, although its sequence index changes. A deleted cursor must be discarded: this cursor is only a node number, without arena/container identity or a generation stamp. A later reused slot can make an old numeric cursor appear present again. Do not transfer cursors between list objects or treat invalidity as permanent. Use arenas for generation-protected graph handles.
List storage is a node array. Finding a free slot scans the capacity; search and sequence position queries follow links. Removing or clearing elements does not overwrite their slots. The preservation contracts define what a client may assume.
Ada's bounded containers
Ada.Containers.Bounded_Vectors, Bounded_Doubly_Linked_Lists, Bounded_Hashed_Maps, Bounded_Ordered_Maps, Bounded_Hashed_Sets and Bounded_Ordered_Sets take Ada's generic formals and give each object its capacity as a discriminant (Vector (8), and for the hashed forms Map (8, Default_Modulus (8))). They are built as the formal packages above are: the elements live in the object at places 1 .. Length, each operation's contract says what it does at every place, and a ghost functional model (Model, or Keys_Model and Elements_Model) gives the contents as sequences. Where Ada raises Constraint_Error or Capacity_Error, a precondition rules the case out: room for one more (Length (C) < C.Capacity), an index up to Last_Index, a key or element that is present (Contains) or absent for Insert.
The vector is indexed by its Index_Type from Index_Type'First; No_Index is the index before it, and Find_Index returns it when nothing matches. The list has cursors, numbers of nodes, and each operation that reads through one takes the list as well (Element (L, C), Next (L, C), Has_Element (L, C)), as the formal list does. Maps and sets have no cursors: they are reached by key or element (Contains, Element, Replace, Delete, Exclude) and by place (Key_At, Element_At, Index_Of), and for K of M gives the keys in their order. A hashed map or set keeps its entries in the order they were inserted and looks a key up with Equivalent_Keys (or Equivalent_Elements), one entry after another: Hash and the modulus are taken, as Ada's declarations give them, and not needed. An ordered map or set keeps its entries in increasing order of "<", which must be a strict order, and two keys are equivalent when neither is less than the other.
Each contract compares elements with Models.Equal_Elements (and keys with Key_Models.Equal_Elements), the type's own equality, so it holds whatever the generic "=" is; that "=" is the one Find, Contains and the containers' own "=" use, as in Ada. A predefined operator may be given for a formal of another name, as in Equivalent_Keys => "=". GNAT's formal containers (SPARK.Containers.Formal.Vectors and the others, or the older Ada.Containers.Formal_Vectors) are reported with a fix-it to these units (B0903), and the bounded multiway trees and indefinite holders are left out (B0501). Ada's unbounded containers are left out too: Verada's unbounded containers replace them.
with Ada.Containers.Bounded_Ordered_Maps;
with Ada.Containers.Bounded_Vectors;
with Ada.Text_IO; use Ada.Text_IO;
procedure Main is
package Letters is new Ada.Containers.Bounded_Vectors (Positive, Character);
package Scores is new Ada.Containers.Bounded_Ordered_Maps (Character, Natural);
use type Ada.Containers.Count_Type;
Word : Letters.Vector (8);
Totals : Scores.Map (8);
begin
Letters.Append (Word, 'x');
Letters.Append (Word, 'z');
Letters.Insert (Word, 2, 'y');
for C of Word loop
Put (C);
end loop;
New_Line;
Scores.Insert (Totals, 'b', 2);
Scores.Insert (Totals, 'a', 5);
Scores.Replace (Totals, 'b', 3);
for I in 1 .. Scores.Length (Totals) loop
Put_Line (Scores.Key_At (Totals, I) & Natural'Image (Scores.Element_At (Totals, I)));
end loop;
end Main;It writes xyz, then a 5 and b 3: the map keeps its keys in order, whichever came first.