db with prim hash

This commit is contained in:
erana 2017-03-06 06:29:49 +01:00
parent 0daad86261
commit e8c98e56ff
2 changed files with 27 additions and 4 deletions

View File

@ -48,7 +48,7 @@
(set! *prime (getprime-rec *prime)))
(define (getprime-rec prime)
(if (or (/ prime 2) (/ prime 3) (/ prime 5) (/ prime 7) (/ prime 10))
(if (not (and (/ prime 2) (/ prime 3) (/ prime 5) (/ prime 7) (/ prime 10)))
(getpreime-rec (+ prime 1))))
(define (integer->ascii

View File

@ -15,11 +15,17 @@
(define (make-db)
(let ((*db '()))
(let ((*db '())
((*prime 1)))
(define (add key value)
(set! *db (append *db (list (list key value))))
)
(let ((*hash (list (list key value))))
(nextprime)
(do ((i 0 (+ i 1)))
((eq? i *prime)
(set! *db (append *db *hash)))
(set! *db (append *db '(0 0))))
))
(define (lookup key)
(let ((*result #f))
@ -30,6 +36,23 @@
(set! *result (cadr (list-ref *db i))))
)))
(define (key->hash key)
(let ((*hash 0))
(do ((i 0 (+ i 1)))
((= i (string-length key))
*hash)
(set! *hash (+ *hash (char->ascii (string-ref key i)))))
))
(define (nextprime)
(set! *prime (getprime-rec *prime)))
(define (getprime-rec prime)
(if (not (and (/ prime 2) (/ prime 3) (/ prime 5) (/ prime 7) (/ prime 10)))
(getpreime-rec (+ prime 1))))
(define (integer->ascii
(define (dispatch msg)
(cond ((eq? msg 'add) add)
((eq? msg 'lookup) lookup)