在数组查找中使用数组查找
Using an array find within an array find
有没有办法使用数组定位器函数作为数组定位器函数的条件?类似于以下内容:
我知道我可以简单地遍历数组,但我希望有一个更简洁的方法
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
find
returns 一个队列,所以这似乎可行
filtered_injectors = injectors.find with (
item.positions.find with (item.name == "hi") != {}
);
有没有办法使用数组定位器函数作为数组定位器函数的条件?类似于以下内容:
我知道我可以简单地遍历数组,但我希望有一个更简洁的方法
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
find
returns 一个队列,所以这似乎可行
filtered_injectors = injectors.find with (
item.positions.find with (item.name == "hi") != {}
);