in reply to RFC - inplace upgrade for Tie::SortHash
I cant help but wonder if your use of autovivification to create the various elements of the object is dangerous. I wouldnt do it personally. I have a feeling at least some of your code will die if somebody calls the wrong function at the wrong time. For instance, when I turn warnings on (why arent you using them?!) the following snippet produces warnings and also doesnt work as expected:
tie my %hash,'Tie::SortHash',{a=>1,b=>2}; delete $hash{'x'}; print join "\t",keys %hash;
Use of uninitialized value in splice at D:\Temp\tie_sorthash.pl line 4 +3. b
Where did the 'a' key go? Also delete() doesnt set the CHANGED flag, and will not play nicely with keys. (It should always be possible to delete the last visited key while iterating the hash without disrupting the hash.)
sub _ReOrder { my $self = shift; $self->[LOOKUP] = (); $self->[ARRAY] = ();
If you intend to set these two to undef then I can think of more obvious ways. Otherwise this is a bug.
defined $self->[ARRAY][$index] ? $self->[ARRAY][$index] : undef;
What exactly is the purpose of this line? Isnt the conditional totally redundant?
I think you need to revisit the code and build up a big set of tests. I have a feeling there are other whammies in there as well. Another question I have is why the iterator requires a hash lookup each time?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: RFC - inplace upgrade for Tie::SortHash
by Limbic~Region (Chancellor) on Sep 05, 2003 at 04:51 UTC | |
by demerphq (Chancellor) on Sep 05, 2003 at 16:56 UTC | |
by Limbic~Region (Chancellor) on Sep 05, 2003 at 17:01 UTC | |
by demerphq (Chancellor) on Sep 05, 2003 at 22:26 UTC | |
by Limbic~Region (Chancellor) on Sep 05, 2003 at 22:38 UTC |