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)


On Fri, 6 Nov 1998, Maciej Stachowiak wrote:

> 
> jglascoe@jay.giss.nasa.gov writes:
> 
> > (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. 

woops, you're right, that is somewhat pointless.  let me change it a bit

(define dictionary-consume-alist!
  (lambda (dictionary alist)
    (if (not (null? alist)) 
	(let ((pair (car alist))
	      (alist-cdr (cdr alist)))
	  ;; (dictionary-add-pair! dictionary pair) ;; more efficient
	  (dictionary-add-list! dictionary (list pair))
	  (if (not (null? alist-cdr))
	      (begin
		(set-car! alist (car alist-cdr))
		(set-cdr! alist (cdr alist-cdr))
		(dictionary-consume-alist! dictionary alist)))))))

> 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.

right.  I think I will add a "dictionary-add-pair!", could be called by
"dictionary-add-list!".

> 
>  - Maciej
> 

	Jay Glascoe
	jglascoe@jay.giss.nasa.gov