]> birchwood-abbey.net Git - mit-scheme.git/commitdiff
Fix bug in rb-tree/update!.
authorChris Hanson <org/chris-hanson/cph>
Sun, 20 Nov 2022 04:37:34 +0000 (20:37 -0800)
committerChris Hanson <org/chris-hanson/cph>
Sun, 20 Nov 2022 04:37:34 +0000 (20:37 -0800)
Also document some rb-tree operations, including that one.

doc/ref-manual/associations.texi
src/runtime/rbtree.scm

index ad6624ce3bf28b3c9308788ed575a8ba0a32201d..832cc372161fc4bb9afb743f03bc0ae4e33529cb 100644 (file)
@@ -1333,6 +1333,15 @@ this operation are proportional to the logarithm of the number of
 assocations in @var{rb-tree}.
 @end deffn
 
+@deffn procedure rb-tree/ref rb-tree key [fail [succeed]]
+Returns the datum associated with @var{key} in @var{rb-tree}.  If
+@var{rb-tree} doesn't contain an association for @var{key}, calls
+@var{fail} with argument @var{key} and returns that result; in this
+situation it is an error if @var{fail} is not provided.  If there is
+an associated datum and @var{succeed} is provided, then it is called
+with that datum and the resulting value returned.
+@end deffn
+
 @deffn procedure rb-tree/delete! rb-tree key
 If @var{rb-tree} contains an association for @var{key}, removes it.
 Returns an unspecified value.  The average and worst-case times required
@@ -1340,6 +1349,22 @@ by this operation are proportional to the logarithm of the number of
 assocations in @var{rb-tree}.
 @end deffn
 
+@deffn procedure rb-tree/update! rb-tree key updater [fail [succeed]]
+Updates the datum associated with @var{key} in @var{rb-tree}.  Calls
+@var{updater} with the current datum, and replaces that datum with the
+result of the call.  If there is no current datum, calls @var{fail}
+with argument @var{key} and uses the resulting value in its place; in
+this situation it is an error if @var{fail} is not provided.  If
+@var{succeed} is provided and there is an existing datum, then it is
+called with that datum and the resulting value is used in its place.
+@end deffn
+
+@deffn procedure rb-tree/intern! rb-tree key fail
+Guarantees that @var{rb-tree} contains an association for @var{key}.
+If there is none, then @var{fail} is called with no arguments and the
+resulting value is associated with @var{key}.
+@end deffn
+
 @deffn procedure rb-tree->alist rb-tree
 Returns the contents of @var{rb-tree} as a newly allocated alist.  Each
 element of the alist is a pair @code{(@var{key} . @var{datum})} where
index 9bb86d5b8a0d34e18720ecb2ac33a8b1b7bb657a..c38e540fb52248d6fa6392b25ab2b323f00717a4 100644 (file)
@@ -281,7 +281,7 @@ USA.
        (set-node-datum! node
                         (updater (apply-succeed succeed (node-datum node))))
        (rb-tree/insert! tree key
-                        (updater (apply-fail fail 'rb-tree/update!))))))
+                        (updater (apply-fail fail key 'rb-tree/update!))))))
 
 (define (find-node tree key)
   (let ((key=? (rb-tree/key=? tree))