Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hashing of custom blocks #5290

Closed
vicuna opened this issue Jun 16, 2011 · 3 comments

Comments

Projects
None yet
2 participants
@vicuna
Copy link

commented Jun 16, 2011

Original bug ID: 5290
Reporter: @yakobowski
Assigned to: @xavierleroy
Status: closed (set by @xavierleroy on 2015-07-24T08:39:01Z)
Resolution: fixed
Priority: normal
Severity: major
Version: 3.12.0
Fixed in version: 4.00.0
Category: ~DO NOT USE (was: OCaml general)
Monitored by: "Pascal Cuoq" @ygrek

Bug description

Hashtbl.hash returns 0 on custom blocks, at least those of the standard library (verified on bigints, channels, and by a cursory grep). This is consistent with its documentation "associates a positive integer to any value of any type". However, it is IMHO a very poor choice, as this will always silently lead to abysmal performances when this function is used on such values. It would be more logical to have this function fail, just as polymorphic equality and comparison. Since Hashtbl are about to undergo a massive rewrite in 3.13, please consider deprecating the old behavior and have the function fail.

(For the record, this really bit us. After some reorganization, we started using the polymorphic hashing function, and Frama-C performances dropped terribly. It took us one afternoon to track the culprit.)

(Also, providing a good hash function for bigints/nats, one bound in the custom block, would be great. For example, keep only the 2^(n-1) lowest or highest bits. This cannot be done efficiently in pure Caml.)

@vicuna

This comment has been minimized.

Copy link
Author

commented Jun 17, 2011

Comment author: @yakobowski

A precision: the custom blocks are on Nats, not on bigints.

@vicuna

This comment has been minimized.

Copy link
Author

commented Jun 20, 2011

Comment author: @xavierleroy

Some standard library types have proper hash functions, e.g. Int32.t, Nativeint.t and Int64.t, but you are correct that channels and nats don't while they should. I put that on my to do list.

@vicuna

This comment has been minimized.

Copy link
Author

commented Jul 23, 2011

Comment author: @xavierleroy

Tentative fix in SVN trunk, will go in 3.13.

@vicuna vicuna closed this Jul 24, 2015

@vicuna vicuna added the bug label Mar 20, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.