2015-05-27 40 views
3

根據1800-2012 specs如何匹配和刪除隊列中的元素?

Queue::delete([input int index]) 

刪除隊列元素SystemVerilog中,此外,一個隊列可以執行相同的操作作爲一個解壓縮陣列,給它訪問:

Array::find_first_index() 

它返回第一個元素的索引匹配一定的標準。即

find_first_index(x) with (x == 3) 

現在我想從隊列中刪除一個唯一的項目,保證存在。將1和1給了我:

queue.delete(queue.find_first_index(x) with (x == obj_to_del)); 

編譯器不理解的是,雖然說,參數傳遞必須是整數或整數兼容。我大概可以拉兩個相距:

int index = queue.find_first_index(x) with (x == obj_to_del); 
queue.delete(index); 

或類型轉換find_first_index迫使整數:

queue.delete(int'(queue.find_first_index(x) with (x == obj_to_del))) //Just finished compiling, does not work. 

前者看起來不是很優雅的我,而後者似乎有點強迫這讓我很好奇如果有更合適的方法來實現這一點。 find_first_index是否可能返回一個大小爲1的數組,其索引位置爲0?

編輯:我傻傻的沒有提供一個自包含例如:

class parent_task; 
endclass; 

class child_taskA extends parent_task; 
endclass; 

class child_taskB extends parent_task; 
endclass;  

class task_collector; 

child_taskA A_queue[$]; 
child_taskB B_queue[$]; 

function delete_from_queue(parent_task task_to_del); 
     case (task_to_del.type): 
     A: A_queue.delete(A_queue.find_first_index(x) with (x == task_to_del)); 
     B: B_queue.delete(B_queue.find_first_index(x) with (x == task_to_del)); 
     default: $display("This shouldn't happen."); 
endfunction 
endclass 

錯誤消息,一個字一個字是:什麼我做看起來像一個剝例如

Error-[SV-IQDA] Invalid Queue delete argument 
"this.A_queue.find_first_index(iterator) with ((iterator == task))" 
Queue method delete can take optional integer argument. So, argument passed 
to it must be either integer or integer assignment compatible. 

在調用delete_from_queue之前,存在檢查以確保有問題的任務存在。

+0

進一步分析它的確看起來像find_first_index返回數組。 'int index = queue.find_first_index(x)其中(x == obj_to_del);' 抱怨將一個int $ [$]分配給int。 –

回答

0
queue.delete(int'(queue.find_first_index(x) with (x == obj_to_del))); 

適合我。如果你可以提供完整的自包含的例子,如下所示:

module top; 
    int queue[$] = {1,2,3,4,5}; 
    let object_to_del = 3; 
     initial begin 
     queue.delete(int'(queue.find_first_index(x) with (x == object_to_del))); 
     $display("%p", queue); 
     end 
endmodule 

但是如果沒有匹配呢?在刪除之前,你不需要測試find_first_index()的結果嗎?

+0

啊,我多麼傻。我在上面添加了一個包含的示例。在調用delete函數之前已經有了檢查,我相信只有在有問題的項目存在的情況下才會調用這個特定的刪除。 –

+0

對不起,我的意思是說使用int'()強制轉換的後一版本適用於我。 –

+0

Mh ...我的編譯器對typecast不滿意:'[IMEMCT]無效的內存使用。內存或內存片不允許在以下上下文中使用:/ *省略* /表達式:this。A_queue.find_first_index()'奇怪......我會先找到索引並將其存儲在int中,然後回報。 –

0

的int投並沒有對我的工作很好,但下面的工作

int index_to_del[$]; 

index_to_del = que.find_first_index(x) with (x == task_to_del); 
que.delete(index_to_del[0]); 
相關問題