* pb_ds gp_hash_table resize strategy
@ 2024-06-21 1:26 CH HC
2024-06-21 8:10 ` Jonathan Wakely
0 siblings, 1 reply; 2+ messages in thread
From: CH HC @ 2024-06-21 1:26 UTC (permalink / raw)
To: gcc
[-- Attachment #1: Type: text/plain, Size: 811 bytes --]
Hi there,
In libstdc++/ext/pb_ds , I noticed that the (automatic) resize function for gp_hash_table does copy-and-destruct operations on old key-value pair (from the line resize_no_store_hash_fn_imps.hpp:58). Meanwhile, cc_hash_table simply moves the old pair as expected.
So for gp_hash_table, this strategy makes it impossible to have non-copyable values, e.g. __gnu_pbds::gp_hash_table<int, std::unique_ptr<int>>. And there exists potential bugs for scenarios like, keeping a gp_hash_table<int, std::list<int>> and saving some iterators of those lists elsewhere for quick access to specific elements in lists.
There could be some workarounds like using std::shared_ptr<T> as value type, but not so perfect.
I wonder if this is caused by some implementation difficulty or just a small bug?
Yours,
chhc
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: pb_ds gp_hash_table resize strategy
2024-06-21 1:26 pb_ds gp_hash_table resize strategy CH HC
@ 2024-06-21 8:10 ` Jonathan Wakely
0 siblings, 0 replies; 2+ messages in thread
From: Jonathan Wakely @ 2024-06-21 8:10 UTC (permalink / raw)
To: CH HC; +Cc: gcc, libstdc++
[-- Attachment #1: Type: text/plain, Size: 1241 bytes --]
On Fri, 21 Jun 2024, 02:28 CH HC via Gcc, <gcc@gcc.gnu.org> wrote:
> Hi there,
> In libstdc++/ext/pb_ds , I noticed that the (automatic) resize function
> for gp_hash_table does copy-and-destruct operations on old key-value pair
> (from the line resize_no_store_hash_fn_imps.hpp:58). Meanwhile,
> cc_hash_table simply moves the old pair as expected.
> So for gp_hash_table, this strategy makes it impossible to have
> non-copyable values, e.g. __gnu_pbds::gp_hash_table<int,
> std::unique_ptr<int>>. And there exists potential bugs for scenarios like,
> keeping a gp_hash_table<int, std::list<int>> and saving some iterators of
> those lists elsewhere for quick access to specific elements in lists.
> There could be some workarounds like using std::shared_ptr<T> as value
> type, but not so perfect.
> I wonder if this is caused by some implementation difficulty or just a
> small bug?
> Yours,
> chhc
>
Hi, this question would be more appropriate on the libstdc++@gcc.gnu.org
making list. I've Cc'd that list. Please take the gcc list out of any
future replies, thanks.
The pb_ds code was written pre-C++11 and not updated for move semantics.
All that code is completely unmaintained and my preference would be to
remove it completely.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-06-21 8:11 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-06-21 1:26 pb_ds gp_hash_table resize strategy CH HC
2024-06-21 8:10 ` Jonathan Wakely
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).