The linked-list implementation in this package can store any data type in the simulator’s dynamic memory. It mimics the behavior of Python’s list class and supports positive and negative indexing.
The list is unidirectional, and you can read from, insert at, or delete any item. The oldest element is accessible as element number 0, while the newest element is at element -1. The negative indexing makes it easy to read from the list’s end, even as it grows.
Consequently, index 1 would refer to the second oldest element and -2 to the second newest. Any element in the list can be indexed from either end.
Refer to the user guide to see how to use the list as a FIFO (first-in, first-out) or LIFO (last-in, first-out).
Click here to download the Generic list – User manual:
This project is also available in the VHDLwhiz Membership.
The difference is that when you purchase this product, you get immediate access to the downloadable Zip file, while you can only join the membership at certain times every year.
Furthermore, the membership charges a monthly subscription fee, while this product is a one-time purchase.
The code listing below shows the declarative region of the generic_list.vhd package.
package generic_list is generic(type data_type); type generic_list is protected -- Add an item to the end of the list -- -- @param str The data to append -- procedure append(data : data_type); -- Add an item to the list -- -- @param index The list slot to insert <data> at. -- A zero or positive index counts from the start of the list. -- A negative index counts from the end of the list. -- Example: -- Insert at the first element: insert(0, my_data) -- Insert at the second last element: insert(-1, my_data) -- -- @param data The item to insert at <index>. -- procedure insert(index : integer; data : data_type); -- Get an item from the list without deleting it -- -- @param index The list index of the item to get. -- Like for insert(), the list index can be negative. -- But unlike insert(), insert(-1) returns the last object. -- -- @return The dynamically allocate data_type object -- impure function get(index : integer) return data_type; -- Remove an item from the list and free the memory it used -- -- @param index The list index of the object to delete. -- The behavor is identical to the get() index parameter. -- procedure delete(index : integer); -- Delete all items from the list and free the memory procedure clear; -- Get the number of items in the list -- -- @return The list's length -- impure function length return integer; end protected; end package;
Copyright (c) 2022 Jonas Julian Jensen
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.