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 09:57:16 -0800


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.
Obviously this is wasteful for large hashes,  and I'm sure that's why
you're asking in the first place. :)

Zbigniew is right but you could conditionally expand:

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


On 3/5/07, Graham Fawcett <address@hidden> wrote:
Hi folks,

Is it safe to delete keys hash-table from within a hash-table-walk
procedure? E.g.

(hash-table-walk my-hash-table
                 (lambda (k v)
                   (when (bad? v)
                         (hash-table-delete! my-hash-table k))))

If I'm reading the implementation correctly, it's safe, since a
deletion does not change the length of the storage vector, and the
tail of the current bucket-list (after the deleted item) is preserved
--- meaning that the iteration over the vector will not be
compromised, and neither will the iteration over any bucket-list.

Still, I thought I might get a second opinion. :-)

Thanks,
Graham


_______________________________________________
Chicken-users mailing list
address@hidden
http://lists.nongnu.org/mailman/listinfo/chicken-users



_______________________________________________
Chicken-users mailing list
address@hidden
http://lists.nongnu.org/mailman/listinfo/chicken-users





reply via email to

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