从位集到BITSET上提振无序(井)图 [英] Unordered (hash) map from bitset to bitset on boost
问题描述
我想使用的缓存,通过升压转换器的实施 unordered_map
,从来,dynamic_bitset
到来,dynamic_bitset
。的问题,当然,是有从位集没有默认哈希函数。它似乎并不像一个概念性的问题,但我不知道如何制定出的技术性。我应该怎么办呢?
I want to use a cache, implemented by boost's unordered_map
, from a dynamic_bitset
to a dynamic_bitset
. The problem, of course, is that there is no default hash function from the bitset. It doesn't seem to be like a conceptual problem, but I don't know how to work out the technicalities. How should I do that?
推荐答案
我发现了一个意想不到的解决方案。原来提升有一个选项的#define BOOST_DYNAMIC_BITSET_DONT_USE_FRIENDS
。当这个定义,私有成员包括 m_bits
成为公共的(我认为这是有需要处理旧的编译器或东西)。
I found an unexpected solution. It turns out boost has an option to #define BOOST_DYNAMIC_BITSET_DONT_USE_FRIENDS
. When this is defined, private members including m_bits
become public (I think it's there to deal with old compilers or something).
所以,现在我可以用@ KennyTM的回答,改了一下:
So now I can use @KennyTM's answer, changed a bit:
namespace boost {
template <typename B, typename A>
std::size_t hash_value(const boost::dynamic_bitset<B, A>& bs) {
return boost::hash_value(bs.m_bits);
}
}
这篇关于从位集到BITSET上提振无序(井)图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!