Associative array/Creation: Difference between revisions

Line 4,314:
(export avl-empty?)
(export avl-insert)
(export avl-search)
(export avl-search-values)
(export avl-check-usage)
Line 4,347 ⟶ 4,346:
"avl-empty? expects an AVL tree as argument")
(not (%bal tree)))
 
(define (avl-search pred<? tree key)
;; Return the data matching a key, or #f if the key is not
;; found. (Note that the data matching the key might be #f.)
(define (search p)
(and p
(let ((k (%key p)))
(cond ((pred<? key k) (search (%left p)))
((pred<? k key) (search (%right p)))
(else (%data p))))))
(avl-check-usage
(procedure? pred<?)
"avl-search expects a procedure as first argument")
(and (not (avl-empty? tree))
(search tree)))
 
(define (avl-search-values pred<? tree key)
Line 4,530 ⟶ 4,514:
;; having a hash function that *always* collides. At a nearly
;; opposite extreme are ideal hash trees, which never have
;; collisions, but which, totowards dothat soend, require hash values to ‘grow’ on
;; ‘grow’ on the fly.
;;
;; Perhaps the simplest form of associative array having all three
1,448

edits