develooper Front page | perl.perl5.porters | Postings from July 2001

Re: [PATCH for discussion] new feature: clamp %hash

Thread Previous | Thread Next
From:
Jeffrey Friedl
Date:
July 20, 2001 15:03
Subject:
Re: [PATCH for discussion] new feature: clamp %hash
Message ID:
200107202203.PAA03311@ventrue.corp.yahoo.com

Michael G Schwern <schwern@pobox.com> wrote:
|> On Fri, Jul 20, 2001 at 03:16:35AM -0700, Jeffrey Friedl wrote:
|> > What I've done so far is certainly not complete, but it shows the idea:
|> > 
|> >    * When an element is deleted from a clamped hash, rather than simply
|> >      remove the whole key/value pair, I keep the key in there with a
|> >      special placeholder value. Internally, this is distinct from
|> >      undef or any possible scalar. (I created "PL_sv_placehold", which
|> >      is similar to "PL_sv_undef").
|> > 
|> >    * exists(), keys(), values(), hash access, etc., all know to ignore
|> >      this placeholder value, so for their purposes it's as if the key
|> >      doesn't exist.
|> 
|> Okay, I had a worry that this would slow down exists() in general
|> (since it would be necessary to look at the value before determining
|> existence), but you could do that extra logic only if its clamped.

The "looking at the value" is pretty light weight -- it's one pointer
dereference and a word compare (and a branch based upon the result of that
compare). It's not a string comparison or anything like that.

|> Then again, since exists() has to go through the trouble of looking up
|> the key *anyway* it shouldn't be much extra work for it to look at the
|> value and see if its PL_sv_placehold.  The difference, hopefully,
|> should not be noticable.  Benchmarking is in order.

I don't think you could benchmark for a time sufficiently long enough to
find any descernable difference between execuation speed for normal hashes
with and without this patch. The only time you'll be able to find any real
difference is when you actually have a clamped hash with many (many many)
allowed-but-not-exists keys. And that's an issue only when you're actually
using the extra functionality.

Two things that have not been discussed yet are how (or if) clamping should
work with tied hashes and pseudo hashes. I know sufficiently little about
these issues to know that I don't know enough to have an opinion.....

	Jeffrey

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About