This is the mail archive of the guile@cygnus.com mailing list for the guile project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Scheme style auto-resizing hashtable (fwd)



jglascoe@jay.giss.nasa.gov writes:
> On Tue, 3 Nov 1998, Ian Bicking wrote:
> 
> > Jay Glascoe writes:
> 
> > > dictionary-consume-alist!       -- delete alist while inserting pairs
> > 
> > Isn't it impossible to destroy an alist without doing a set! on the
> > thing that points to the alist?
> 
> this one's for Maciej.  Look! a tail-recursive imperative procedure!  :()
> 

Foolish mortal! Thou shalt not take my name in vain! :-)

> (define dictionary-consume-alist!
>   (lambda (dictionary alist)
>     (if (not (null? alist))
> 	(let* ((pair (car alist))
> 	       (key (car pair))
> 	       (value (cdr pair))
> 	       (alist-cdr (cdr alist)))
> 	  (dictionary-insert! dictionary key value)
> 	  (if (not (null? alist-cdr))
> 	      (begin
> 		(set-car! alist (car alist-cdr))
> 		(set-cdr! alist (cdr alist-cdr))
> 		(dictionary-consume-alist! dictionary alist)))))))
> 

This just has the effect of dropping the alist cons cells on the floor
as garbage gradually instead of all at once; I am not sure this is so
helpful. 

In fact, if you just cdr'd down the alist and the only live reference
to it is passing it to dictionary-insert-alist!, you'd have the exact
same effect, i.e. the cells of the alist would become garbage as soon
as the iteration does not need them any more. 

What would be more useful is the ability to insert the key-value cons
cells of the alist explicitly, sharing the memory, rather than having
to extract the keys and values and then insert them. That would help
both speed and memory usage.

 - Maciej