Navigation
GitHub
CoreLib
Links
Sponsors
Notes
This wiki uses icons from icons8.com licensed under CC BY-ND 3.0.
This wiki uses icons from icons8.com licensed under CC BY-ND 3.0.
Summary | Lists |
---|---|
Related issues | |
Current status | Proposal submitted |
Date submitted | 06/27/03 |
Author submission | Venkataramanan, Srinivasan |
Author email | srinivasan.venkataramanan@intel.com |
A list is an ordered collection of elements of the same type. A list is always indexed contiguously either in ascending order or in descending order. A list type is declared using the following declaration:
type list_type is list(<> or range) of another_type;
Example:
Type list_a_type is list (<>) of INTEGER; Type list_b_type is list (0 to 5) of BIT_VECTOR(0 to 3); Type list_c_type is list (3 downto 0) of STRING(0 to 5);
When a range of <>
is specified, the list is of an unspecified maximum
length (0 to INTEGER’HIGH-1 is default). When a range is specified, the
range specifies the MAX number of elements that can be contained in the
list. The range is only a constraint. The head of the list is always
the leftmost index.
'LEFT
and 'RIGHT
attributes can be used on a list type to access its
bounds – these attributes when used with a type that has range of <>
yield 0 and INTEGER’HIGH-1 respectively.
During list operations, the list is always anchored at the leftmost index and grows towards the right. Indices are adjusted to be always consecutive.
Examples of object decls:
Variable usb_fan: list_I_type; // empty by default. Signal usb_data: list_b_type := (“001”, “000”, “000”); // list // has three elements indexed from 0 to 2. Signal phy_recd: list_b_type := (”001”, ”000”); // will // create a 2 element list, indexed from 0 to 1.
The following attributes can be applied to objects of a list type to perform list operations.
List_object'DELETE [(index)]
– deletes the element at specified
index (and all indices adjusted appropriately). If index is not
in within list length, returns false, else returns true. If no
index specified, all elements in the list are deleted and a true
is returned. Deleting an empty list still returns a true.List_object'INSERT (value [, index])
– inserts a value at the
specified index. All other indices/values to the right are
adjusted appropriately. If list size becomes greater than
specified size, a value of false is returned and the insert does
not take place. A true is returned if the insert is successful.
If no index specified, insert occurs at end of list (tail).
To add to head of list, use list_type’LEFT as index.
The value could be a value of the list type or another list type.
If value is another list, the new list is inserted at the
specified position (always growing to the right). ).List_object'LENGTH
– returns the number of elements in the list.
0 if list is empty.List_object'SORT
– sorts the list based on the values in the list
in non-decreasing order based on the relational operator defined
for the value type. Returns true if successful (if list changed).List_object'UNIQUE
– deletes any duplicate values of the type in
the list. (not necessarily numerical values – so bit_vector “000”
is different from bit_vector “0000”). Returns true if successful
(if list changed).List_object'REVERSE
– reverses the order of elements in the list.
Returns true if successful (if list changed).List_object'EXISTS(value)
– Returns TRUE if the value being
passed as argument exists within the list, else FALSE.List_object'INDEX(value)
Returns an INTEGER denoting the index of
the element which matches with the value argument. Returns –1 if
the value doesn’t exist. The search happens from LEFT to RIGHT,
search stops at the first match, so if there are multiple
elements matching the value being searched, first index will be
returned. To search from RIGHT side, do a REVERSE first and then
perform a search.You can assign a list to another list with an assignment statement. This creates a completely new copy of the list.
Usb_data ⇐ phy_recd;
You can initialize a list using an aggregate constant as shown in the example earlier.
Usb_data ⇐ (“100”, “111”);
You can also pass lists as arguments to subprograms (similar to arrays).
To write out values in a list, iterate on the list and write out each value.
Note: You can always build your own lists by using the new operator and access pointers.