[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Chicken-users] Good way to code the equivalent to this?
From: |
Tobia Conforto |
Subject: |
Re: [Chicken-users] Good way to code the equivalent to this? |
Date: |
Mon, 25 Aug 2008 21:50:25 +0200 |
Matt Welland wrote:
the tactic of loading lots of data into a hierarchy of hash arrays
and then extracting the needed pieces in a myriad of ways, sometimes
on the fly in a meeting with management nervously looking on :-) has
been tremendously useful for me. I for one am hoping that there are
faster hash tables in the future of chicken.
Until there are, here's how you can have the best of both worlds,
especially considering:
1. the use you seem to make of hash tables (mainly setting new keys
and referencing them, rarely or never deleting them)
2. what has been said of alists vs. hash tables for small data sets
3. what has been said of alist->hash-table
Just use your own hash table-like structure, that starts as an alist
and only becomes a proper hash table when it grows over a certain
size, tuneable with a parameter.
Something like this should go a long way in letting you keep your
coding style and have good performance:
(define smart-hash-threshold (make-parameter 20))
(define (make-smart-hash)
(cons (list)
(void))) ;cdr currently unused
(define (smart-hash-ref table key)
(if (list? (car table))
(alist-ref key (car table))
(hash-table-ref (car table) key)))
(define (smart-hash-set! table key value)
(if (list? (car table))
(begin
(set-car! table (alist-update! key value (car table)))
(if (> (length (car table)) (smart-hash-threshold))
(set-car! table (alist->hash-table (car table)))))
(hash-table-set! (car table) key value)))
Tobia
- Re: [Chicken-users] Good way to code the equivalent to this?, (continued)
Re: [Chicken-users] Good way to code the equivalent to this?, Elf, 2008/08/24
Re: [Chicken-users] Good way to code the equivalent to this?, Elf, 2008/08/24
Re: [Chicken-users] Good way to code the equivalent to this?, Jim Ursetto, 2008/08/24
Re: [Chicken-users] Good way to code the equivalent to this?, Matt Welland, 2008/08/24
Re: [Chicken-users] Good way to code the equivalent to this?,
Tobia Conforto <=