On Tue Jul 05 10:41:39 2011, CYCLES wrote:
Show quoted text> It would be great if I could somehow make this set have only 1 object:
>
> my $foo = set({ hello => 1 }, { hello => 1 });
>
> Smart matching, a keying function, or a custom equality routine could all
> allow this, I don't mind how it's implemented.
Sorry about not replying sooner, I only just saw this.
The logical problem with what you are asking for is that the members are not the same
object. If you subsequently modify one of the hashes then the assumption is violated: Perl
does not have 'const' values at that level.
This module is really based around reference addresses. It might be possible to add a slot for
a hash value alongside the pointer to the object, check if a special hash method function
exists, call it and index by the hash value instead (falling back to the reference address). Perl
doesn't have a special hash method (like Python's __hash__, for instance), but there's no
reason you couldn't make a suitable convention for this purpose. It would double the size of
the set hash table but probably nobody cares about that level of memory efficiency any more.
If you're interested in extending Set::Object to do this, I can assist in terms of code review:
submit a pull request via github (github.com/samv/Set-Object) and I will review. If you can
pull that off well, you can be the maintainer.
Cheers,
Sam