Fine-tune skeleton-accumulator representations for persistency/reuse and for potential speed benefit

This commit is contained in:
Tony Garnock-Jones 2018-04-08 07:01:39 +01:00
parent c122add136
commit 7f65d9e452
1 changed files with 7 additions and 9 deletions

View File

@ -50,12 +50,12 @@
;; (MutableSet Assertion)
;; (MutableHash SkProj SkAcc))
;; SkAcc = (skeleton-accumulator
;; (MutableSet SkKey)
;; (MutableSet (... -> Any)))
;; (Set SkKey)
;; (MutableSeteq (... -> Any)))
;;
(struct skeleton-continuation (cache table) #:transparent)
(struct skeleton-matched-constant (cache table) #:transparent)
(struct skeleton-accumulator (cache handlers) #:transparent)
(struct skeleton-accumulator ([cache #:mutable] handlers) #:transparent)
;;
;; A `SkProj` is a *skeleton projection*, a specification of loci
;; within a tree-shaped assertion to collect into a flat list.
@ -111,9 +111,9 @@
(define cvt (hash-ref! (skeleton-continuation-table c) cs make-hash))
(define sc (hash-ref! cvt cv make-matched-constant))
(define (make-accumulator)
(skeleton-accumulator (for/mutable-set [(a (skeleton-matched-constant-cache sc))]
(skeleton-accumulator (for/set [(a (skeleton-matched-constant-cache sc))]
(apply-projection a vs))
(mutable-set)))
(mutable-seteq)))
(define acc (hash-ref! (skeleton-matched-constant-table sc) vs make-accumulator))
(set-add! (skeleton-accumulator-handlers acc) h)
(for [(vars (skeleton-accumulator-cache acc))] (apply-handler! h vars)))
@ -229,8 +229,7 @@
(define (add-term-to-skconst! skconst term)
(set-add! (skeleton-matched-constant-cache skconst) term))
(define (add-term-to-skacc! skacc vars _term)
(define cache (skeleton-accumulator-cache skacc))
(set-add! cache vars)
(set-skeleton-accumulator-cache! skacc (set-add (skeleton-accumulator-cache skacc) vars))
(for [(handler (skeleton-accumulator-handlers skacc))]
(apply handler '+ vars)))
@ -246,8 +245,7 @@
(define (remove-term-from-skconst! skconst term)
(set-remove! (skeleton-matched-constant-cache skconst) term))
(define (remove-term-from-skacc! skacc vars _term)
(define cache (skeleton-accumulator-cache skacc))
(set-remove! cache vars)
(set-skeleton-accumulator-cache! skacc (set-remove (skeleton-accumulator-cache skacc) vars))
(for [(handler (skeleton-accumulator-handlers skacc))]
(apply handler '- vars)))