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
It would in some cases be useful to have an equivalent of the entry API available for HashSet. The case I ran into was wanting to remove values from two sets only if both sets contain the values. With the current API, this would be something like:
if set1.contains(&value1) && set2.remove(&value2){
set1.remove(&value1);}
which does two lookups in set1 in the case that the values should be removed: as far as I can see there is no way to avoid doing the duplicate lookup. A similar situation would arise in the case where values should only be inserted if neither set contains the values.
It is possible to emulate this with a HashMap<T, ()>, e.g.
It would in some cases be useful to have an equivalent of the entry API available for
HashSet
. The case I ran into was wanting to remove values from two sets only if both sets contain the values. With the current API, this would be something like:which does two lookups in
set1
in the case that the values should be removed: as far as I can see there is no way to avoid doing the duplicate lookup. A similar situation would arise in the case where values should only be inserted if neither set contains the values.It is possible to emulate this with a
HashMap<T, ()>
, e.g.but would be a nice-to-have for
HashSet
as well.The text was updated successfully, but these errors were encountered: