db with prim hash
This commit is contained in:
parent
0daad86261
commit
e8c98e56ff
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue