hashtable local iterator
François Dumont
frs.dumont@gmail.com
Tue Dec 20 20:38:00 GMT 2011
On 12/19/2011 09:43 PM, Jonathan Wakely wrote:
> If you use std::tuple to store the members it will automatically use
> EBO if possible. If two types might be the same use std::tuple<X,Y,X>
> where X might be empty and Y is not empty, that ensures the two X
> objects will not have the same address so can have zero size.
Thanks for the proposition but it was not exactly what I needed. In fact
I have this kind of use case:
struct A1
{};
struct A2
{};
struct A3
{};
struct B
{
A1 m_a1;
A2 m_a2;
A3 m_a3;
};
struct C : B
{
size_t m_size;
};
and I would like to have sizeof(C) == sizeof(size_t). I don't think
tuple can do anything for me here. Only having B inheriting from A1, A2
and A3 will give the expected result. And as I said there is no
ambiguity problem here. The only ambiguity could come from using the
same functor as a _Equal and _Hash functor but as I never inherit from
both _Equal and _Hash there won't ever be any ambiguity.
So here is my final patch with sizeof(local_iterator) == 2 *
size(size_t) + sizeof(void*).
2011-12-20 François Dumont <fdumont@gcc.gnu.org>
* include/bits/hashtable_policy.h (_Equal_helper<>): New,
change the
way the _Equal functor is used depending on whether hash code
is cache
or not. (_Hash_code_base): Move _Equal functor management...
(_Hashtable_base): ...here, new, use _Equal_helper.
(_Local_iterator_base<>, _Locale_iterator<>,
_Locale_const_iterator<>):
New, use _Hash_code_base, implementation of...
* include/bits/hashtable.h (_Hashtable<>::local_iterator,
_Hashtable<>::const_local_iterator): ...those. Add static
assertions
checking that some functors are empty depending on whether hash
code
is cache or not. (_Hashtable<>::_M_bucket_index): New overloads
using
current bucket count, use through out the _Hastable<>
implementation.
* include/bits/unordered_set.h (__unordered_set<>,
__unordered_multiset<>): Cache hash code if hash functor is not
empty.
* include/bits/unordere_map.H (__unordered_map<>,
__unordered_multimap<>): Likewise.
* include/debug/unordered_map
(unordered_map<>::_S_to_local, unordered_multimap<>::_S_to_local):
Adapt to match new local iterator implementation.
* include/debug/unordered_set (unordered_set<>::_S_to_local,
unordered_multiset<>::_S_to_local): Likewise.
* include/profile/unordered_map
(unordered_map<>::_M_profile_destruct,
unordered_multimap<>::_M_profile_destruct): Enhance thanks to
usage of
local iterators.
* include/profile/unordered_set
(unordered_set<>::_M_profile_destruct,
unordered_multiset<>::_M_profile_destruct): Likewise.
Tested under x86_64 linux, check, check-debug and check-profile.
Ok to commit ?
François
-------------- next part --------------
A non-text attachment was scrubbed...
Name: hashtable_local_iterator.patch
Type: text/x-patch
Size: 47009 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/libstdc++/attachments/20111220/b859cdb2/attachment.bin>
More information about the Libstdc++
mailing list