Abstract base class for implementing a key/value pair cache.
A key/value cache is similar in nature to an associative array, however there are certain conditions under which a cache may choose to evict an element which has been previously stored. The eviction policy is specific to the implementation of the cache.
@uvm-contrib
uvm_cache(KEY_T,DATA_T) | ||||||||||||||||||||||
Abstract base class for implementing a key/value pair cache. | ||||||||||||||||||||||
Class Hierarchy | ||||||||||||||||||||||
| ||||||||||||||||||||||
Class Declaration | ||||||||||||||||||||||
| ||||||||||||||||||||||
Types | ||||||||||||||||||||||
this_type | Typedef representing this cache parameterization. | |||||||||||||||||||||
optional_data | The cache can be queried for data at a given key. | |||||||||||||||||||||
optional_keys | The optional_keys type is similar to the optional_data type, however it stores keys instead of data. | |||||||||||||||||||||
size_t | An unsigned data type used for size operations on the cache. | |||||||||||||||||||||
Methods | ||||||||||||||||||||||
new | Constructor, initializes the cache. | |||||||||||||||||||||
set_max_size | Sets the maximum size of the cache to max_size. | |||||||||||||||||||||
get_max_size | Returns the current maximum size of the cache. | |||||||||||||||||||||
size | Returns the current number of elements in the cache. | |||||||||||||||||||||
exists | Returns true if key exists in the cache, otherwise returns false. | |||||||||||||||||||||
get | Returns data associated with key. | |||||||||||||||||||||
put | Puts data in cache at index key. | |||||||||||||||||||||
evict | Removes the data at key from the cache. | |||||||||||||||||||||
evict_to_max | Hook for evicting all keys greater than maximum size. | |||||||||||||||||||||
keys | Returns a queue of all keys currently in the cache. | |||||||||||||||||||||
flush | Evicts all keys from the cache. |
Typedef representing this cache parameterization.
The cache can be queried for data at a given key. If the key exists within the cache then the data can be returned, but if the key does not exist then the cache needs to return “nothing”.
The optional_data type is a simple wrapper around a queue of DATA_T. If the key is found (ie. hit), then the first (and only) element of the queue stores the value. If the key is not found (ie. missed), then an empty queue is returned.
Note: SystemVerilog uses a similar pattern for the array locator methods.
The optional_keys type is similar to the optional_data type, however it stores keys instead of data. This is generally used by the keys method.
An unsigned data type used for size operations on the cache.
function new( string name = "unnamed-uvm_cache", size_t max_size = 256 )
Constructor, initializes the cache.
The max_size argument defines the initial maximum size of the cache. The default max_size shall be 256.
A max_size of 0 indicates that the cache is unsized, and will not evict any keys.
virtual function void set_max_size( size_t max_size = 256 )
Sets the maximum size of the cache to max_size.
The default value of max_size shall be 256.
If the new max_size value is less than the current number of keys stored in the cache, then evict_to_max is automatically called.
A max_size of 0 indicates that the cache is unsized, and will not evict any keys.
pure virtual function bit exists( KEY_T key )
Returns true if key exists in the cache, otherwise returns false.
pure virtual function optional_data get( KEY_T key )
Returns data associated with key.
If key exists within the cache, then the data is returned via optional_data.
If key does not existing within the cache, then this operation shall have no effect on the cache, and shall return empty optional_data.
pure virtual function void put( KEY_T key, DATA_T data )
Puts data in cache at index key.
If key exists within the cache, then the data associated key is updated. If key does not exists within the cache, then a new data value is added at key.
If putting the key in the cache causes the number of stored keys to exceed get_max_size, then the least recently used key shall be evicted via evict.
pure virtual function optional_data evict( KEY_T key )
Removes the data at key from the cache.
If key exists within the cache, then the data is returned via optional_data.
If key does not exist within the cache, then this operation shall have no effect on the cache, and shall return empty optional data.
pure virtual protected function void evict_to_max()
Hook for evicting all keys greater than maximum size.
This method is called by set_max_size when the new maximum size exceeds the current size of the cache.
If the current size of the cache is less than the maximium size, evict_to_max shall have no effect on the cache.
Abstract base class for implementing a key/value pair cache.
virtual class uvm_cache#( type KEY_T = int, type DATA_T = int ) extends uvm_object
Constructor, initializes the cache.
function new( string name = "unnamed-uvm_cache", size_t max_size = 256 )
Sets the maximum size of the cache to max_size.
virtual function void set_max_size( size_t max_size = 256 )
Returns the current maximum size of the cache.
virtual function size_t get_max_size()
Returns the current number of elements in the cache.
pure virtual function size_t size()
Returns true if key exists in the cache, otherwise returns false.
pure virtual function bit exists( KEY_T key )
Returns data associated with key.
pure virtual function optional_data get( KEY_T key )
Puts data in cache at index key.
pure virtual function void put( KEY_T key, DATA_T data )
Removes the data at key from the cache.
pure virtual function optional_data evict( KEY_T key )
Hook for evicting all keys greater than maximum size.
pure virtual protected function void evict_to_max()
Returns a queue of all keys currently in the cache.
pure virtual function optional_keys keys()
Evicts all keys from the cache.
virtual function void flush()