Amajor feature of the predefined library of Ada 2012 is the container library. This is rather extensive and merits this separate chapter on its own.
The main part of the library comprises several generic packages for the manipulation of various kinds of important data structures. These structures are vectors, doubly linked lists, maps and sets (both hashed and ordered), multiway trees, a holder (or wrapper), and various task safe queues. There are also generic packages for sorting arrays and other general structures.
Organization of library
The container library comprises a root package Ada.Containers plus various child generic packages. The main generic packages form three groups. The first group concerns objects of definite types; the second group concerns indefinite types, and the third group has bounded capacity for objects of definite types.
It will be remembered that an indefinite (sub)type is one for which we cannot declare an object without giving a constraint (either directly or indirectly from its initial value).
The reason for distinct containers for definite and indefinite types concerns efficiency. It is much easier to manipulate definite types and although the packages for indefinite types can be used for definite types, this would be rather inefficient.
Another consideration is reliability. For high integrity applications it is generally unacceptable to use dynamic storage allocation. Accordingly, a separate group of containers with bounded capacity is provided for definite types.
Note that there are no bounded containers for indefinite types because objects of indefinite types (such as the type String) by their very nature are of variable size and thus inevitably need dynamic storage management.
The containers can also be categorized in other ways.
Sequence containers – these hold sequences of elements. There are packages for manipulating vectors and for manipulating linked lists. These packages have much in common. But they have different behaviours in terms of efficiency according to the pattern of use. In general (with some planning) it should be possible to change from one to the other with little effort.
Multiway tree containers – these hold elements as a multiway tree. They have much in common with the sequence containers.
Associative containers – these associate a key with each element and then store the elements in order of the keys. There are packages for manipulating hashed maps, ordered maps, hashed sets and ordered sets.