[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Guile-commits] 03/09: Add intmap-fold.
From: |
Andy Wingo |
Subject: |
[Guile-commits] 03/09: Add intmap-fold. |
Date: |
Wed, 08 Apr 2015 15:21:05 +0000 |
wingo pushed a commit to branch master
in repository guile.
commit b7668bd9498ec93cbb1ddb5f57b6e2bf05faabda
Author: Andy Wingo <address@hidden>
Date: Wed Apr 1 10:45:31 2015 +0200
Add intmap-fold.
* module/language/cps/intmap.scm (intmap-fold): New function.
---
module/language/cps/intmap.scm | 28 ++++++++++++++++++++++++++++
1 files changed, 28 insertions(+), 0 deletions(-)
diff --git a/module/language/cps/intmap.scm b/module/language/cps/intmap.scm
index abaf459..467a63d 100644
--- a/module/language/cps/intmap.scm
+++ b/module/language/cps/intmap.scm
@@ -40,6 +40,7 @@
intmap-ref
intmap-next
intmap-prev
+ intmap-fold
intmap-union
intmap-intersect))
@@ -233,6 +234,33 @@
(let ((i (visit-node root shift i)))
(and i (+ min i))))))))
+(define (intmap-fold f map seed)
+ (define (visit-branch node shift min seed)
+ (let ((shift (- shift *branch-bits*)))
+ (if (zero? shift)
+ (let lp ((i 0) (seed seed))
+ (if (< i *branch-size*)
+ (let ((elt (vector-ref node i)))
+ (lp (1+ i)
+ (if elt
+ (f (+ i min) elt seed)
+ seed)))
+ seed))
+ (let lp ((i 0) (seed seed))
+ (if (< i *branch-size*)
+ (let ((elt (vector-ref node i)))
+ (lp (1+ i)
+ (if elt
+ (visit-branch elt shift (+ min (ash i shift)) seed)
+ seed)))
+ seed)))))
+ (match map
+ (($ <intmap> min shift root)
+ (cond
+ ((not root) seed)
+ ((zero? shift) (f min root seed))
+ (else (visit-branch root shift min seed))))))
+
(define* (intmap-union a b #:optional (meet meet-error))
;; Union A and B from index I; the result will be fresh.
(define (union-branches/fresh shift a b i fresh)
- [Guile-commits] branch master updated (50fcdfe -> eb9d442), Andy Wingo, 2015/04/08
- [Guile-commits] 01/09: Default "meet" operator is meet-error for intmap, Andy Wingo, 2015/04/08
- [Guile-commits] 02/09: Add intmap-prev, Andy Wingo, 2015/04/08
- [Guile-commits] 03/09: Add intmap-fold.,
Andy Wingo <=
- [Guile-commits] 04/09: Add intset-fold, intset-fold2, Andy Wingo, 2015/04/08
- [Guile-commits] 06/09: 32-way branching in intmap.scm, not 16-way, Andy Wingo, 2015/04/08
- [Guile-commits] 07/09: Add "transient" intmap interface, Andy Wingo, 2015/04/08
- [Guile-commits] 08/09: Transient intsets, Andy Wingo, 2015/04/08
- [Guile-commits] 05/09: Intset-next micro-optimizations, Andy Wingo, 2015/04/08
- [Guile-commits] 09/09: Add "cps2" experiment, Andy Wingo, 2015/04/08