Package Overview

The Prg_Vector package provides a powerful abstraction for storing and accessing items in containers. The “vector” construct combines the advantageous performance and random-access features of arrays with the flexibility and extensibility of lists. In other words, with a vector, you can:

  • replace, remove, or access items in any position simply by specifying that position as an integer (array-like behavior)
  • place new items beyond the last item in the vector without any limits on how large the vector can grow (list-like behavior)
  • insert/remove an item between other items, causing the pre-existing items to “shift” (list-like) to create/fill the space.

Vectors can contain arbitrary types of data items. The package refers to these as “elements”, and they are passed into and out of the package as pointers to generic memory addresses, and declared as (void *). This is the same approach used in the Prg_List package. In fact, the APIs of Prg_Vector closely parallel the semantics of Prg_List.

The positions of elements in vectors are zero-indexed. The first element in a vector has position 0, the second has position 1, etc. If there are 10 elements in a vector, the last element has position 9. It is not possible to insert a new element more than one position beyond the last element. In other words, in a vector currently containing 10 elements, the highest index for adding a new element would be 10. Again, the semantics and rules for position indices are the same as those of Prg_List.

WARNING: For efficiency reasons, the APIs in this package have not been made MT-safe. Thus, in parallel simulations, access to vectors must be externally serialized.