Front page | perl.perl5.porters |
Postings from September 2002
Re: Collections
Thread Previous
|
Thread Next
From:
Nicholas Clark
Date:
September 29, 2002 14:47
Subject:
Re: Collections
Message ID:
20020929214514.GC291@Bagpuss.unfortu.net
On Sun, Sep 29, 2002 at 06:44:28AM +0200, Christian Jaeger wrote:
> Method 1:
> my $bucket={};
> sub add {
> my $obj=shift;
> $bucket->{$obj}=$obj;
> }
> sub remove {
> my $obj=shift;
> delete $bucket->{$obj}
> }
> sub check {
> my $obj=shift;
> exists $bucket->{$obj}
> }
> iteration:
> for(values %bucket) # hmm, does this create a potentially big list first?
> So I guess if I want fast checks, I even need this more complicated
> scheme with an incremental id.
Based on an idea H Merijn Brand told me, try using try using the string
generated by (pack 'I', $obj) as your hash key, and see if that helps.
(The I in pack will cause the $obj reference to be read in a numeric context,
which will give the address of the object (rather than the stringification
of the address of the object). Also unique, but faster.
The pack itself will convert that to a string representation which is both
shorter, and should hash more uniformly, than either the stringified
reference, or the numeric value of the reference)
Nicholas Clark
--
Even better than the real thing: http://nms-cgi.sourceforge.net/
Thread Previous
|
Thread Next