This queue is for tickets about the Set-Object CPAN distribution.

Report information
The Basics
Id:
69288
Status:
open
Priority:
Low/Low
Queue:

People
Owner:
Nobody in particular
Requestors:
CYCLES [...] cpan.org(email delivery suspended)
Cc:
AdminCc:

BugTracker
Severity:
Wishlist
Broken in:
(no value)
Fixed in:
(no value)



Subject: Add support for a custom equality routine/keying
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.
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
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
In particular I'd really love it if Set::Object respected overloaded ==/eq operators to determine equality. (Falling back to refaddr in the absence of overloading.)


This service runs on Request Tracker, is sponsored by The Perl Foundation, and maintained by Best Practical Solutions.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.