guile-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Guile-commits] GNU Guile branch, stable-2.0, updated. v2.0.1-52-g19301d


From: Ludovic Courtès
Subject: [Guile-commits] GNU Guile branch, stable-2.0, updated. v2.0.1-52-g19301dc
Date: Sun, 08 May 2011 16:21:27 +0000

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GNU Guile".

http://git.savannah.gnu.org/cgit/guile.git/commit/?id=19301dc56d297a24eedc48928bb1b7df40cd4688

The branch, stable-2.0 has been updated
       via  19301dc56d297a24eedc48928bb1b7df40cd4688 (commit)
       via  bc00e06c7ec5575f405bee4e12a062d4269f4eab (commit)
      from  0a6506781ac1082d370b8359199a9d20eda74057 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 19301dc56d297a24eedc48928bb1b7df40cd4688
Author: Ludovic Courtès <address@hidden>
Date:   Sun May 8 18:19:52 2011 +0200

    Add `vhash-fold-right'.
    
    * module/ice-9/vlist.scm (vhash-fold-right): New procedure.
    
    * test-suite/tests/vlist.test ("vhash")["vhash-fold-right"]: New test.
    
    * doc/ref/api-compound.texi (VHashes): Document `vhash-fold-right'.

commit bc00e06c7ec5575f405bee4e12a062d4269f4eab
Author: Ludovic Courtès <address@hidden>
Date:   Sun May 8 18:15:10 2011 +0200

    Optimize `vlist-fold-right'.
    
    * module/ice-9/vlist.scm (vlist-fold-right): Avoid `vlist-reverse' and
      instead `vlist-ref' individual elements.  The result is about twice
      faster.  Thanks Andy for suggesting it indirectly.  :-)

-----------------------------------------------------------------------

Summary of changes:
 doc/ref/api-compound.texi   |    9 +++++----
 module/ice-9/vlist.scm      |   21 +++++++++++++++++++--
 test-suite/tests/vlist.test |    7 +++++++
 3 files changed, 31 insertions(+), 6 deletions(-)

diff --git a/doc/ref/api-compound.texi b/doc/ref/api-compound.texi
index 27ba437..da8813b 100644
--- a/doc/ref/api-compound.texi
+++ b/doc/ref/api-compound.texi
@@ -1,7 +1,7 @@
 @c -*-texinfo-*-
 @c This is part of the GNU Guile Reference Manual.
address@hidden Copyright (C)  1996, 1997, 2000, 2001, 2002, 2003, 2004, 2005, 
2006, 2007, 2009, 2010
address@hidden   Free Software Foundation, Inc.
address@hidden Copyright (C)  1996, 1997, 2000, 2001, 2002, 2003, 2004, 2005, 
2006,
address@hidden   2007, 2009, 2010, 2011  Free Software Foundation, Inc.
 @c See the file guile.texi for copying conditions.
 
 @node Compound Data Types
@@ -3294,8 +3294,9 @@ Again the choice of @var{hash-proc} must be consistent 
with previous calls to
 @end deffn
 
 @deffn {Scheme Procedure} vhash-fold proc vhash
-Fold over the key/pair elements of @var{vhash}.  For each pair call @var{proc}
-as @code{(@var{proc} key value result)}.
address@hidden {Scheme Procedure} vhash-fold-right proc vhash
+Fold over the key/value elements of @var{vhash} in the given direction.
+For each pair call @var{proc} as @code{(@var{proc} key value result)}.
 @end deffn
 
 @deffn {Scheme Procedure} vhash-fold* proc init key vhash [equal? [hash]]
diff --git a/module/ice-9/vlist.scm b/module/ice-9/vlist.scm
index 34c7c00..d5e28d5 100644
--- a/module/ice-9/vlist.scm
+++ b/module/ice-9/vlist.scm
@@ -33,7 +33,7 @@
             vhash? vhash-cons vhash-consq vhash-consv
             vhash-assoc vhash-assq vhash-assv
             vhash-delete vhash-delq vhash-delv
-            vhash-fold
+            vhash-fold vhash-fold-right
             vhash-fold* vhash-foldq* vhash-foldv*
             alist->vhash))
 
@@ -245,7 +245,14 @@ tail."
 (define (vlist-fold-right proc init vlist)
   "Fold over @var{vlist}, calling @var{proc} for each element, starting from
 the last element."
-  (vlist-fold proc init (vlist-reverse vlist)))
+  (define len (vlist-length vlist))
+
+  (let loop ((index  (1- len))
+             (result init))
+    (if (< index 0)
+        result
+        (loop (1- index)
+              (proc (vlist-ref vlist index) result)))))
 
 (define (vlist-reverse vlist)
   "Return a new @var{vlist} whose content are those of @var{vlist} in reverse
@@ -553,6 +560,16 @@ with @var{equal?}."
               seed
               vhash))
 
+(define (vhash-fold-right proc seed vhash)
+  "Fold over the key/pair elements of @var{vhash}, starting from the 0th
+element.  For each pair call @var{proc} as @code{(@var{proc} key value
+result)}."
+  (vlist-fold-right (lambda (key+value result)
+                      (proc (car key+value) (cdr key+value)
+                            result))
+                    seed
+                    vhash))
+
 (define* (alist->vhash alist #:optional (hash hash))
   "Return the vhash corresponding to @var{alist}, an association list."
   (fold-right (lambda (pair result)
diff --git a/test-suite/tests/vlist.test b/test-suite/tests/vlist.test
index b590bbd..d939284 100644
--- a/test-suite/tests/vlist.test
+++ b/test-suite/tests/vlist.test
@@ -301,6 +301,13 @@
            (alist  (fold alist-cons '() keys values)))
       (equal? alist (reverse (vhash-fold alist-cons '() vh)))))
 
+  (pass-if "vhash-fold-right"
+    (let* ((keys   '(a b c d e f g d h i))
+           (values '(1 2 3 4 5 6 7 0 8 9))
+           (vh     (fold vhash-cons vlist-null keys values))
+           (alist  (fold alist-cons '() keys values)))
+      (equal? alist (vhash-fold-right alist-cons '() vh))))
+
   (pass-if "alist->vhash"
     (let* ((keys   '(a b c d e f g d h i))
            (values '(1 2 3 4 5 6 7 0 8 9))


hooks/post-receive
-- 
GNU Guile



reply via email to

[Prev in Thread] Current Thread [Next in Thread]