chicken-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Chicken-users] hash-table-walk + hash-table-delete!


From: Kon Lovett
Subject: Re: [Chicken-users] hash-table-walk + hash-table-delete!
Date: Mon, 5 Mar 2007 11:05:07 -0800

On Mar 5, 2007, at 10:26 AM, Graham Fawcett wrote:

On 3/5/07, Kon Lovett <address@hidden> wrote:

On Mar 5, 2007, at 8:47 AM, Zbigniew wrote:

> SRFI-69 appears to provide no guarantee of safety, so for maximum
> portability (including to future implementations) you might want to
> iterate manually over a copy of the keys obtained via hash-table- keys.

Zbigniew is right but you could conditionally expand:

(cond-expand
   (chicken
     ... hash-table-walk delete ... )
   (else
     ... safe delete ... ) )

Right. (Kon, can I take this to mean that you also think a
"hash-table-walk delete" is safe in the current Chicken
implementation?)

Yes.

##sys#for-each doesn't care about the previous pair in the chain when looping, hash-table-walk passes the entire bucket chain on to for- each & the hash vector is not resized. (I think you already pointed this out.)

The only issue I see is if someone does a hash-table-delete! during a hash-table-walk where the bucket is the same as the currently "walked" bucket & the deleted entry is "ahead" of the current bucket link. i.e. deleting an arbitrary entry conditional on the currently "walked" entry.

However I think a '(hash-table-remove! hash-table (-> key value boolean))' procedure should be added to "extras.scm" just to be "safe". I suppose it could fluid-bind the hash-table-delete! procedure to avoid someone doing the above; although they could still cache the binding beforehand - perversity tends to the maximum.

Best Wishes,
Kon


Zbignew wrote:
I think this is an oversight in SRFI-69.

I agree; it's a surprising omission.

Graham





reply via email to

[Prev in Thread] Current Thread [Next in Thread]