public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "fdumont at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug libstdc++/95079] unorderd_map::insert_or_assign and try_emplace should only hash and mod once unless there is a rehash.
Date: Tue, 02 Mar 2021 16:49:26 +0000	[thread overview]
Message-ID: <bug-95079-4-467R0D52Mz@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-95079-4@http.gcc.gnu.org/bugzilla/>

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95079

--- Comment #6 from François Dumont <fdumont at gcc dot gnu.org> ---
Thanks for the feedback.

If this is still a problem for you after this enhancement you should perhaps
try the _Power2_rehash_policy provided as an extension. In
testsuite/23_containers/unordered_set/insert/hash_policy.cc you'll see an
example with a unordered_set like container defined as:

template<typename _Value, typename _Hash,
         typename _Pred, typename _Alloc>
  using unordered_set_power2_rehash =
  std::_Hashtable<_Value, _Value, _Alloc,
                  std::__detail::_Identity,
                  _Pred,
                  _Hash,
                  std::__detail::_Mask_range_hashing,
                  std::__detail::_Default_ranged_hash,
                  std::__detail::_Power2_rehash_policy,
                  std::__detail::_Hashtable_traits<false, true, true>>;

As stated by its name _Power2_rehash_policy will make sure that number buckets
is a power of 2 and so make the modulo much trivial.

      parent reply	other threads:[~2021-03-02 16:49 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-12 11:00 [Bug libstdc++/95079] New: " redbeard0531 at gmail dot com
2020-05-12 11:26 ` [Bug libstdc++/95079] " redi at gcc dot gnu.org
2020-05-24 10:00 ` fdumont at gcc dot gnu.org
2020-05-29 11:13 ` cvs-commit at gcc dot gnu.org
2021-02-28 14:39 ` fdumont at gcc dot gnu.org
2021-03-02 13:40 ` redbeard0531 at gmail dot com
2021-03-02 16:49 ` fdumont at gcc dot gnu.org [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-95079-4-467R0D52Mz@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).