unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: Joris van der Hoeven <TeXmacs@math.u-psud.fr>
Cc: Roland Orre <orre@nada.kth.se>
Subject: Re: Efficiency and flexibility of hash-tables
Date: Tue, 11 Feb 2003 12:14:33 +0100 (MET)	[thread overview]
Message-ID: <Pine.GSO.3.96.1030211120528.3755D-100000@anh> (raw)
In-Reply-To: <xy7k7gawzzx.fsf@nada.kth.se>


> > So does there exist an adaptive-number-of-slots solution in guile?
> 
> No.  We'd be happy to include adaptation in the standard Guile
> hash-tables, though.  Would it be possible for you to contribute a
> patch?

I don't have much knowledge about how to write low-level guile functions.
In the meantime, you might want to use the following code.
I only use the equal?-based access methods, but it would be easy
to add the eq?- and eqv?-based methods.

The 'adaptive hash tables' are stored as a pair with a usual hashtable and
its number of entries. I have tested the code a bit and it seems to work.
If you find any bugs, then please let me know.

Best wishes, Joris

-----------------------------------------------------------
Joris van der Hoeven <vdhoeven@texmacs.org>
http://www.texmacs.org: GNU TeXmacs scientific text editor
http://www.math.u-psud.fr/~vdhoeven: personal homepage
-----------------------------------------------------------



;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; MODULE      : ahash-table.scm (part of GNU TeXmacs)
;; DESCRIPTION : adaptive hash tables
;; COPYRIGHT   : (C) 2003  Joris van der Hoeven
;;
;; This software falls under the GNU general public license and comes WITHOUT
;; ANY WARRANTY WHATSOEVER. See the file $TEXMACS_PATH/LICENSE for details.
;; If you don't have this file, write to the Free Software Foundation, Inc.,
;; 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Adaptive hash tables
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(define (make-ahash-table)
  (cons (make-hash-table 1) 0))

(define (ahash-ref h key)
  (hash-ref (car h) key))

(define (ahash-size h)
  (cdr h))

(define (ahash-slots! h new-size)
  (let ((new-h (make-hash-table new-size)))
    (hash-fold (lambda (key value dummy) (hash-set! new-h key value))
	       #f (car h))
    (set-car! h new-h)))

(define (ahash-set! h key value)
  (if (hash-ref (car h) key)
      (hash-set! (car h) key value)
      (begin
	(if (>= (cdr h) (vector-length (car h)))
	    (ahash-slots! h (+ (* 2 (vector-length (car h))) 1)))
	(set-cdr! h (+ (cdr h) 1))
	(hash-set! (car h) key value))))

(define (ahash-remove! h key)
  (let ((removed (hash-remove! (car h) key)))
    (if removed
	(begin
	  (set-cdr! h (- (cdr h) 1))
	  (if (< (+ (* 4 (cdr h)) 1) (vector-length (car h)))
	      (ahash-slots! h (quotient (vector-length (car h)) 2)))))
    removed))

(define (ahash-fold h)
  (hash-fold (car h)))



_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-user


  reply	other threads:[~2003-02-11 11:14 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-02-08 11:00 Efficiency and flexibility of hash-tables Joris van der Hoeven
2003-02-08 13:57 ` Roland Orre
2003-02-08 14:14   ` Joris van der Hoeven
2003-02-08 14:55     ` Roland Orre
2003-02-08 15:14       ` Joris van der Hoeven
2003-02-08 15:31         ` Mikael Djurfeldt
2003-02-11 11:14           ` Joris van der Hoeven [this message]
2003-02-11 11:28             ` Joris van der Hoeven
2003-02-11 12:50               ` Mikael Djurfeldt
2003-02-08 15:44         ` Roland Orre
2003-02-10  9:55           ` Andreas Rottmann
2003-02-10 14:24             ` Greg Troxel
2003-02-10 15:00               ` Roland Orre
2003-02-10 16:52                 ` Mikael Djurfeldt
2003-02-10 17:09                   ` Roland Orre
2003-02-10 17:11                   ` Mikael Djurfeldt
2003-02-11 13:59                     ` Resizing hash tables in Guile Mikael Djurfeldt
2003-02-11 17:34                       ` Roland Orre
2003-02-12 11:41                         ` Marius Vollmer
2003-02-12 16:10                       ` Marius Vollmer
2003-02-12 17:53                         ` Mikael Djurfeldt
2003-02-12 20:17                           ` Roland Orre
2003-02-13  9:35                             ` Mikael Djurfeldt
2003-02-13 13:55                               ` Harvey J. Stein
2003-02-13 14:24                                 ` Joris van der Hoeven
2003-02-13 18:30                                   ` Harvey J. Stein
2003-02-13 20:02                                     ` Paul Jarc
2003-02-13  9:52                             ` Joris van der Hoeven
2003-02-12 20:55                       ` Rob Browning
2003-02-13 10:43                         ` Mikael Djurfeldt
2003-02-12 20:47       ` Efficiency and flexibility of hash-tables Paul Jarc
2003-02-12 21:58         ` Roland Orre

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Pine.GSO.3.96.1030211120528.3755D-100000@anh \
    --to=texmacs@math.u-psud.fr \
    --cc=orre@nada.kth.se \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).