You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Description
Recently me and @matekelemen (and many other also have complained in past: refer #9227) that there are some inconsistencies in the PointerVectorSet and how it is supposed to behave. The followings are the points which we discovered:
Not guranteed to be ordered or unique.
Has a confusing interface with mixed responsibilities.
1: Not guranteed to be ordered or unique
The underlying storage of the PointerVectorSet can be mutated and can lose its Set properties in the following cases.
PointerVectorSet::GetContainer - The container can be freely mutated without triggering an update (sort and unique)
PointerVectorSet::push_back - Array is appended but not sorted or made unique.
PointerVectorSet::find - Mutates the data structure if not sorted. (Problematic in OpenMP as well)
2: Has a confusing interface with mixed responsibilities
The PointerVectorSet has following methods which give the impression it does not gurantee the Set properties.
PointerVectorSet::IsSorted, PointerVectorSet::Sort, PointerVectorSet::Unique - Is giving wrong impressions about the assumed set properties.
Mixed responsibilities (separating them would allow using the features individually as well):
a. ordered set data structure
b. value-like access to an array of pointers
Necessary changes
Remove PointerVectorSet::GetContainer (both mutable and immutable)
Replace push_back with insert(begin, end)
Remove sorting in the mutable find
Remove pop_back
Remove Sort, Unique, IsSorted
Remove mSortedPartSize, mMaxBufferSize and their getters and setters.
This would require multiple PRs with incremental changes, specially when replacing push_back.
Suggestion
Instead of rolling our own implementation, we suggest using a 3rd party implementation, because this is a solved problem. One possible library is tessil ordered_set. It is ordered and contiguous in memory and is header-only (3 files).
Just to be clear, this isn't a quality-of-life issue. It is a potential source of bugs that are difficult to track down but result in soft errors. It's critical that we fix this, and doing so may help us fix bugs that we didn't know about or had no idea that they originated from here.
Description
Recently me and @matekelemen (and many other also have complained in past: refer #9227) that there are some inconsistencies in the
PointerVectorSet
and how it is supposed to behave. The followings are the points which we discovered:1: Not guranteed to be ordered or unique
The underlying storage of the
PointerVectorSet
can be mutated and can lose itsSet
properties in the following cases.PointerVectorSet::GetContainer
- The container can be freely mutated without triggering an update (sort and unique)PointerVectorSet::push_back
- Array is appended but not sorted or made unique.PointerVectorSet::find
- Mutates the data structure if not sorted. (Problematic in OpenMP as well)2: Has a confusing interface with mixed responsibilities
The
PointerVectorSet
has following methods which give the impression it does not gurantee theSet
properties.PointerVectorSet::IsSorted
,PointerVectorSet::Sort
,PointerVectorSet::Unique
- Is giving wrong impressions about the assumed set properties.a.
ordered set
data structureb. value-like access to an array of pointers
Necessary changes
PointerVectorSet::GetContainer
(both mutable and immutable)push_back
withinsert(begin, end)
find
pop_back
Sort
,Unique
,IsSorted
mSortedPartSize
,mMaxBufferSize
and their getters and setters.insert(position, value)
=>insert(hint, value)
This would require multiple PRs with incremental changes, specially when replacing
push_back
.Suggestion
Instead of rolling our own implementation, we suggest using a 3rd party implementation, because this is a solved problem. One possible library is tessil
ordered_set
. It is ordered and contiguous in memory and is header-only (3 files).FYI @philbucher @loumalouomega
The text was updated successfully, but these errors were encountered: