On Wed, Jul 17, 2002 at 03:29:46PM +0100, Alberto Manuel Brand?o Sim?es wrote: > Hi > > Some of you (Dan) knows that I'm working on a project to generate Parrot > code from a specification programming language. > > On these language, data-structures are very similar with mathematical > constructs. I will need a finite mapping (or finite function) which maps > objects (any type) to objects (any type). > > At the moment, PerlHash maps Strings to PMC's (well.. anything which can > be converted to string to PMC's). The question for comments is: will > perlHash do what I want, or should I investigate on a new PMC?
My opinion: rename the current PerlHash to Hash, and create a new PMC PerlHash that does PMC->PMC mappings. > And, if I should write a new PMC, some idea for the hash function? > (compare each with eachother is not efficient). Efficiency is the least of your concerns. Just because two PMC's hash to the same value doesn't mean they are equal. For correctness, you still have to do an equality check. (Unless you use a 128-bit cryptographically secure hash function, and somehow get every PMC to implement it correctly.) And then you have to figure out what to do about the problem of PMCs being mutable -- what happens if their hash values change after you've stuck them into the hashtable? If you cache a PMC's hash value, do you cache it in the hashtable or the PMC? And finally, a nitpicky issue that doesn't need to behave nicely but probably shouldn't crash: what happens if calling a PMC's ->hash or ->is_equal vtable entry mutates the PMC?