Guile Mailing List Archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Scheme style auto-resizing hashtable (fwd)
Jay Glascoe <jglascoe@jay.giss.nasa.gov> writes:
> > Of these three approaches, the iterator approach would be more memory
> > efficient, but probably a mess otherwise.
>
> actually, hash->alist would give you a list of pairs. These pairs would
> be the same objects as the pairs in the hash table, so creating the list
> wouldn't use up much memory at all. It's also probably the fastest
> approach (you'd only call hash->alist once: BANG! it's done. whereas with
> an iterator, you'd wind up calling it many times (bang!, bang!, bang!...).
Calling what many times? What's wrong with this:
(define (hashtable-foreach h f)
(do ((i 0 (1+ i))
(n (hashtable-length h))
(v (hashtable-vector h)))
((i >= n))
(for-each (lambda (data) (apply f (cdr data)))
(vector-ref v i))))
hash->alist (aka hashtable->list) still has to cons up the list that
points to all the pairs in the hashtable, so it's still a lot of
garbage - 1 cons cell for each object in the hash table.
--
Harvey J. Stein
BFM Financial Research
hjstein@bfr.co.il
Guile Home |
Main Index |
Thread Index