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: avl-trees vs. hashes


> On 20 Oct 1998, Harvey J. Stein wrote:
> 
> > Jay Glascoe <jglascoe@jay.giss.nasa.gov> writes:
> > 
> > You might want to make the shrinking part
> > optional.
> > 
> 
> good idea.  Right now my hash tables look like this
> 
<snip>
> 
> So, I'll just add a new association 'auto-shrink-flag, and modify
> make-hashtab to accept 3 optional arguments (max-bucket-size,
> number-buckets, and auto-shrink-flag).  I'll even add two new procedures:
> (hashtab-enable 'auto-shrink) and (hashtab-disable 'auto-shrink) so the
> user can easily turn it on/off as they please.
>

guile> (define foo (make-hashtab))
guile> foo
(((number-buckets . 4) (max-bucket-size . 5) (largest-bucket-size . 0)
(number-entries . 0) (largest-bucket-index . 0) (auto-shrink-flag . #f)) .
#((0) (0) (0) (0)))
guile> (do ((i 1 (+ i 1))) ((> i 100)) (hashtab-set! foo (/ i 23) i))
resizing from 4 to 8
resizing from 8 to 16
resizing from 16 to 32
resizing from 32 to 64
resizing from 64 to 128
guile> (do ((i 1 (+ i 1))) ((> i 100)) (hashtab-del! foo (/ i 23)))
guile> (do ((i 1 (+ i 1))) ((> i 100)) (hashtab-set! foo (/ i 23) i))
guile> (hashtab-enable foo 'auto-shrink)
#t
guile> (do ((i 1 (+ i 1))) ((> i 100)) (hashtab-del! foo (/ i 23)))
resizing from 128 to 64
resizing from 64 to 32
resizing from 32 to 16
resizing from 16 to 8
resizing from 8 to 4
guile> foo
(((number-buckets . 4) (max-bucket-size . 5) (largest-bucket-size . 0)
(number-entries . 0) (largest-bucket-index . 3) (auto-shrink-flag . #t)) . 
#((0) (0) (0) (0)))
guile> (exit)