Vengineerの妄想(準備期間)

人生は短いけど、長いです。人生を楽しみましょう!

連想配列(Associative Array)

Verification Engineerの戯言

連想配列には、次のメソッドがあります。

function int num();
function void delete( [input index] );
function int exists( input index );
function int first( ref index );
function int last( ref index );
function int next( ref index );
function int prev( ref index );

enumと同じようなメソッドがほとんどですね!


existsを使えば、引数で指定したインデックスの値があるかがわかります。

if ( words.exists( "first" ))
words[ "first" ] += 1;
else
words[ "first" ] = 0;

便利ですね。。

P.S

ちなみに、ModelSim XEのexamples/systemverilogのディレクトリにある
「classes/associative_array」は、連想配列の例題です。
ModelSim XEで実行できます。コードの中では、firstとnextを使っています。



この例題では、連想配列の例ですが、コード内ではclassも使っています。