Changeset 13880 in project


Ignore:
Timestamp:
03/23/09 18:42:19 (11 years ago)
Author:
Jim Ursetto
Message:

Changes applied for zbigniew (71.201.84.72) through svnwiki:

lru-cache: add example

File:
1 edited

Legend:

Unmodified
Added
Removed
  • wiki/eggref/4/lru-cache

    r13866 r13880  
    8080=== Example
    8181
    82 Forthcoming...
    83 
     82 (use lru-cache)
     83 (define C (make-lru-cache 4 string=?
     84                           (lambda (k v) (printf "deleting (~S ~S)\n" k v))))
     85 (lru-cache-set! C "a" 1) ; a
     86 (lru-cache-set! C "b" 2) ; b a
     87 (lru-cache-set! C "c" 3) ; c b a
     88 (lru-cache-set! C "d" 4) ; d c b a
     89 (lru-cache-walk C print)
     90 ;; d4
     91 ;; c3
     92 ;; b2
     93 ;; a1
     94 (lru-cache-set! C "e" 5) ; e d c b
     95 ;; deleting (a 1)
     96 (lru-cache-ref C "b")    ; 2, b e d c
     97 (lru-cache-ref C "d")    ; 4, d b e c
     98 (lru-cache-walk C print)
     99 ;; d4
     100 ;; b2
     101 ;; e5
     102 ;; c3
     103 (lru-cache-delete! C "e") ; d b c
     104 ;; deleting ("e" 5)
     105 (lru-cache-set! C "a" 6) ; a d b c
     106 (lru-cache-flush! C)
     107 ;; deleting ("a" 6)
     108 ;; deleting ("d" 4)
     109 ;; deleting ("b" 2)
     110 ;; deleting ("c" 3)
     111 (lru-cache-walk C print)
    84112=== Author
    85113
Note: See TracChangeset for help on using the changeset viewer.