1 Nov 2000 01:44
Re: ocaml to c variant hashes
Jacques Garrigue <garrigue <at> kurims.kyoto-u.ac.jp>
2000-11-01 00:44:35 GMT
2000-11-01 00:44:35 GMT
From: Chris Hecker <checker <at> d6.com> > Hi, I'm looking at the lablGL stuff, and came across a utility that > computes the ocaml hash value for a given variant name. The > var2def.ml file in the package preprocesses a variables file and > outputs a C header with the appropriate hash values. The ml file > contains a function, hash_variant that does this hash, but that > function is copied from the source code to the compiler. This > doesn't seem like a very robust way to do this, since the internal > hash function could change at any time (in fact, the comment in the > code says hash_variant is from ctype.ml, but it's now in btype.ml). > > What's the right way to do this? I can think of 3 ways: > > 1. Like var2def.ml, and just hope the internal hash function doesn't change. This is the right way. You can consider this as "the definition" of how to hash a variant. Basically it only assumes that all ocaml architectures support 31-bit integers efficiently. As I do not see any risk of this becoming false, and as 32-bit architectures are still around for a while, there is no compelling reason to change it. Only if 32-bit architectures disappear, and ocaml support 63-bit integers everywhere, there could be a discussion of changing this hashing function, but I suppose this would be publicized enough. As to whether you should use var2def.ml, or use the C hash_variant function, this is basically a question of efficiency: I prefer preprocessing because runtime cost is null, and you can put the values in static tables. You can also use switch, but beware of code size(Continue reading)
RSS Feed