Ticket #4038 (closed Bugs: fixed)

Opened 7 years ago

Last modified 7 years ago

hash_value(float) collision

Reported by: dsharlet@… Owned by: danieljames
Milestone: Boost 1.43.0 Component: hash
Version: Boost 1.41.0 Severity: Problem
Keywords: hash_value collision float Cc:


the hash_value function for floats has at least one collision that is rather serious:

std::size_t zero = boost::hash_value(0.0f); std::size_t half = boost::hash_value(0.5f);

both of these have the same hash value. Why not just use reinterpret_cast <> for this hash function?


Change History

comment:1 Changed 7 years ago by danieljames

  • Status changed from new to assigned

Because in cross platform development there's no guarantee that two floats with different binary representations will be unequal, and there's no guarantee that the binary representation will be the same size as std::size_t. I do use a binary algorithm on a limited number of platforms, and could for others, but it has to be done carefully and there are more important things to do.

comment:2 Changed 7 years ago by danieljames

(In [60805]) Remove optimization which causes 0.5 to hash to 0. Refs #4038.

I have an internal requirement the 0 hashes to 0, a better solution might be to remove that, put the optimization back and hash 0 to another value. Or alternatively, use the main combine function instead.

comment:3 Changed 7 years ago by danieljames

  • Status changed from assigned to closed
  • Resolution set to fixed

(In [60980]) Merge from trunk.

  • Add quick_erase for unordered. erase_return_void is now deprecated. Fixes #3966
  • Avoid collision between 0 and 0.5. Fixes #4038

Add a comment

Modify Ticket

Change Properties
<Author field>
as closed
The resolution will be deleted. Next status will be 'reopened'

E-mail address and user name can be saved in the Preferences.

Note: See TracTickets for help on using tickets.