michel
michel

Reputation: 43

When should we use Indefinite_Hashed_Maps or Hashed_Maps

I'm confused about when to use Ada.Containers.Indefinite_Hashed_Maps or Hashed_Maps.

What is the difference between the two generic packages?

Upvotes: 2

Views: 385

Answers (1)

ciceron
ciceron

Reputation: 586

The Ada.Containers.Indefinite_Hashed_Maps package supports types that are indefinite for the key and element. An indefinite type is a type that needs an additional constraint to declare an object. Example: String, T'Class, a type with a variant part.

The Hashed_Maps implementation is able to store the key and element within the map implementation records (be it a table or a tree). This is the most efficient implementation between the two.

The Indefinite_Hashed_Maps cannot store the key and element as easily due to the additional constraint. Most implementation will have to use an access to the key and to the element to store them. Each time an element is added, an additional memory allocation is required to store the key and element.

Although Indefinite_Hashed_Maps works for finite types, it is best to use Hashed_Maps if the key and element types are definite.

Upvotes: 3

Related Questions