Fix unique_index method on assoc arrays with values differing from the keys (#7616)

Signed-off-by: Pawel Klopotek <pklopotek@internships.antmicro.com>
This commit is contained in:
Pawel Klopotek 2026-05-19 15:51:23 +02:00 committed by GitHub
parent 662cd43348
commit efdc8d1cbf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 9 additions and 1 deletions

View File

@ -218,6 +218,7 @@ Paul Bowen-Huggett
Paul Swirhun
Paul Wright
Pawel Jewstafjew
Pawel Klopotek
Pawel Kojma
Pawel Sagan
Pengcheng Xu

View File

@ -1090,7 +1090,7 @@ public:
}
VlQueue<T_Key> unique_index() const {
VlQueue<T_Key> out;
std::set<T_Key> saw;
std::set<T_Value> saw;
for (const auto& i : m_map) {
auto it = saw.find(i.second);
if (it == saw.end()) {

View File

@ -23,6 +23,7 @@ module t;
int qv[$]; // Value returns
int qi[$]; // Index returns
point points_q[int];
point points_qe[int]; // Empty points
point points_qv[$];
int i;
bit b;
@ -58,6 +59,12 @@ module t;
qi.sort;
`checkp(qi, "'{'h0, 'h1, 'h5}");
qi = points_qe.unique_index();
`checkp(qi, "'{}");
qi = points_q.unique_index();
`checkh(qi.size, 3);
qi = points_q.find_first_index with (item.x == 1);
`checkp(qi, "'{'h0}");
qi = points_q.find_first_index with (item.x == 10);