in reply to RE: RE: Re: Hash Internals
in thread Hash Internals
replacing an existing value would be simply:
would be implemented as:$my_ordered_hash{$old_key} = $newvalue;
...since replacing a value for an existing key should not (in this case) change its order. if you did want this behaviour ie STOREing a value *always* appends to the end, then the performance of STOREing with this implementation gets a little ugly -- O(n), for the array scan.sub STORE { my( $this, $key, $val ) = @_; if ( exists( $this->{hash}->{$key} ) ) { $this->{hash}->{$key} = $val; } else { $this->{hash}->{$key} = $val; push @{$this->{order}}, $key; } }
the only really messy problem with this implementation is DELETEing - since that requires array scanning and splicing.
is there any other complications?
|
---|
Replies are listed 'Best First'. | |
---|---|
RE: RE: RE: RE: Re: Hash Internals
by japhy (Canon) on Oct 24, 2000 at 16:06 UTC | |
by d_i_r_t_y (Monk) on Oct 25, 2000 at 07:48 UTC |