首页 > 解决方案 > 在数组查找中使用数组查找

问题描述

有没有办法使用数组定位器函数作为数组定位器函数的条件?类似于以下内容:

我知道我可以简单地遍历数组,但我希望有一个更简洁的方法

module tb;
  typedef struct {
    string name;
    int id;
  } positions_t;

  typedef struct {
    positions_t positions[];
    string unit_name;
  } injector_t;

  injector_t injectors[$] = '{
    '{
      unit_name: "unit1",
      positions: '{
        '{name: "ha", id:0},
        '{name: "he", id:0},
        '{name: "hi", id:0}
      }
    }
  };

  injector_t filtered_injectors[$];

  initial begin
    // LIKE THIS!
    filtered_injectors = injectors.find with (
      item.positions.find with (item.name == "hi")
    );
    $display("filtered list = %p", filtered_injectors);
  end
endmodule

标签: system-verilog

解决方案


find返回一个队列,所以这似乎有效

filtered_injectors = injectors.find with (
  item.positions.find with (item.name == "hi") != {}
);

推荐阅读