From 7f65d9e452986fd81b695781dbf482bc65c4a480 Mon Sep 17 00:00:00 2001 From: Tony Garnock-Jones Date: Sun, 8 Apr 2018 07:01:39 +0100 Subject: [PATCH] Fine-tune skeleton-accumulator representations for persistency/reuse and for potential speed benefit --- syndicate/skeleton.rkt | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/syndicate/skeleton.rkt b/syndicate/skeleton.rkt index 2723096..0dcf77d 100644 --- a/syndicate/skeleton.rkt +++ b/syndicate/skeleton.rkt @@ -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)))