Opened 14 years ago

Last modified 3 years ago

#2841 new Feature Requests

boost::hash to support boost::dynamic_bitset

Reported by: astukalov@… Owned by: James E. King, III
Milestone: Component: dynamic_bitset
Version: Boost 1.43.0 Severity: Not Applicable
Keywords: Cc: daniel_james@…

Description

IIUC, there's no out-of-box support for hashing of dynamic_bitset.

Could something as simple as

    template <typename B, typename A>
    friend std::size_t hash_value(const dynamic_bitset<B, A>& v) {
        return hash_value( v.m_bits );
    }

be added to boost::dynamic_bitset class?

Change History (13)

comment:1 by Daniel James, 14 years ago

Cc: daniel_james@… added
Component: hashdynamic_bitset
Owner: changed from Daniel James to Gennaro Prota

I don't know anything about dynamic_bitset, but I suspect the hash function will also need to include the length of the bitset so that '1', '10' and '01' all have different hash values.

Anyway, this needs to be implemented as part of dynamic_bitset so I'm passing it to it's maintainer. But I'm adding myself as a CC, so he can ask for assistance if needed.

in reply to:  1 comment:2 by anonymous, 14 years ago

Replying to danieljames:

I don't know anything about dynamic_bitset, but I suspect the hash function will also need to include the length of the bitset so that '1', '10' and '01' all have different hash values.

Well, yes, adding length may improve hashing quality. On the other hand, the length of m_bits array directly correlates with the length of bitset, so it's (kind of) already included.

comment:3 by Daniel James, 14 years ago

'0', '00', '000' and '0000' should have different hash values, but unless I've misunderstood dynamic_bitset m_bits will be the same for all of them.

in reply to:  3 comment:4 by astukalov@…, 14 years ago

Replying to danieljames:

'0', '00', '000' and '0000' should have different hash values, but unless I've misunderstood dynamic_bitset m_bits will be the same for all of them.

I think so too. It should be true for all zero bitsets with lengths <= bits per bitset block. For bigger lengths - two and more values would be hash_combined, resulting in different hash key.

Anyway, not including bitset length into hashing directly would have so small performance improvement, that I withdraw my previous comment. :)

comment:5 by cheapest Cialis next day delivery, 13 years ago

"Cogito ergo I'm right and you're wrong."

-- Blair Houghton

viagra prezzo online purchase fioricet buy order cialis online BgnAuHX tramadol buy cheap

comment:6 by jim@…, 9 years ago

It would also be great if dynamic_bitset supported std::hash, which exists beginning with C++11.

comment:7 by acharles, 9 years ago

Owner: changed from Gennaro Prota to acharles
Status: newassigned

comment:8 by acharles, 9 years ago

Milestone: Boost 1.39.0Boost 1.56.0

comment:9 by paulo@…, 8 years ago

What's needed to actually get this done?

comment:10 by XRumerTest, 8 years ago

Milestone: Boost 1.56.0Boost 1.58.0
Version: Boost 1.38.0Boost 1.43.0

Hello. And Bye.

comment:11 by akim.demaille@…, 8 years ago

Ping.

comment:12 by James E. King, III, 3 years ago

Milestone: Boost 1.58.0
Owner: changed from acharles to James E. King, III
Severity: OptimizationNot Applicable
Status: assignednew
Note: See TracTickets for help on using tickets.