chicken-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Chicken-users] Good way to code the equivalent to this?


From: Matt Welland
Subject: Re: [Chicken-users] Good way to code the equivalent to this?
Date: Sat, 23 Aug 2008 22:22:35 -0700

Sorry for the overly brief problem statement. This is the two deep
sparse array code I threw together. BTW, in the test code I am using
numbers as the keys out of lazyness. The real code may use strings and
or numbers. I'm using chicken 2.740 and 3.3.0 if it matters.

I guess my question really has two parts.
1) How do chicken hash arrays compare in speed and memory usage with
hash arrays in perl?
2) Is there some more scheme oriented way to store data like this for
quick random lookup?

(define vv  (make-hash-table))

(define (sparse-array-set! a x y val)
  (let ((sh (hash-table-ref/default a x #f)))
    (if sh
        (hash-table-set! sh y val)
        (let ((h (make-hash-table)))
          (hash-table-set! a x h)
          (hash-table-set! h y val)))))

(define (sparse-array-ref a x y)
  (let ((h (hash-table-ref/default a x #f)))
    (if h
        (hash-table-ref/default h y #f)
        #f)))

(define maxval 500000)
(let loop ((x (random maxval))
           (y (random maxval))
           (n 0))
  (sparse-array-set! vv x y #t)
  (if (< n 250000)
      (loop (random maxval)(random maxval)(+ n 1))))


On Sat, Aug 23, 2008 at 2:35 PM, John Cowan <address@hidden> wrote:
> Matt Welland scripsit:
>
>> My attempts all use gigs of memory and run 10x as long.
>
> So show us the problematic code, then.
>
>
> --
> When I'm stuck in something boring              John Cowan
> where reading would be impossible or            (who loves Asimov too)
> rude, I often set up math problems for          address@hidden
> myself and solve them as a way to pass          http://www.ccil.org/~cowan
> the time.      --John Jenkins
>




reply via email to

[Prev in Thread] Current Thread [Next in Thread]