aboutsummaryrefslogtreecommitdiffstats
path: root/mcgoron
diff options
context:
space:
mode:
authorGravatar Peter McGoron 2025-02-17 00:30:44 -0500
committerGravatar Peter McGoron 2025-02-17 00:30:44 -0500
commite1622eadb63e7fa1e7ea901fa9b30b7d25ff1b6f (patch)
treed50d887515771e1ebe5adacf7a8890033d87330d /mcgoron
parentmember, adjoin and find tests (diff)
change set-disjoint?, test set-intersection
Diffstat (limited to 'mcgoron')
-rw-r--r--mcgoron/weight-balanced-trees/srfi/113/sets.scm43
1 files changed, 34 insertions, 9 deletions
diff --git a/mcgoron/weight-balanced-trees/srfi/113/sets.scm b/mcgoron/weight-balanced-trees/srfi/113/sets.scm
index 20f01d9..2fdf0ed 100644
--- a/mcgoron/weight-balanced-trees/srfi/113/sets.scm
+++ b/mcgoron/weight-balanced-trees/srfi/113/sets.scm
@@ -19,9 +19,11 @@
(comparator set-element-comparator)
(node get-node))
-(define (check-compatible! set1 set2)
- (when (not (binary-compatible? set1 set2))
- (error "sets have different comparators" set1 set2)))
+(define (check-compatible set1 set2)
+ (let ((val (binary-compatible set1 set2)))
+ (if (not val)
+ (error "sets have different comparators" set1 set2)
+ val)))
;;; ;;;;;;;;;;;;;;;;
;;; Constructors
@@ -56,7 +58,28 @@
(null? (get-node set)))
(define (set-disjoint? set1 set2)
- (set-empty? (set-intersection set1 set2)))
+ #;(set-empty? (set-intersection set1 set2))
+ ;; More optimized version.
+ ;;
+ ;; List the values of the sets in order. If any set is exhausted, then
+ ;; the sets are disjoint. If any element is equal, then the sets are
+ ;; not disjoint.
+ ;;
+ ;; If the element from set 1 is less than the element from set 2, then
+ ;; get the next element from set 1 (if any) and repeat. Since the
+ ;; elements are obtained in order, any elements after the current
+ ;; element of set 2 must be greater than the seen elements from set 1.
+ (let ((gen1 (set->in-order-generator set1))
+ (gen2 (set->in-order-generator set2))
+ (cmp (check-compatible set1 set2)))
+ (let loop ((value1 (gen1))
+ (value2 (gen2)))
+ (if (or (eof-object? value1) (eof-object? value2))
+ #t
+ (comparator-if<=> cmp value1 value2
+ (loop (gen1) value2)
+ #f
+ (loop value1 (gen2)))))))
;;; ;;;;;;;;;;;;;;;;;;;
;;; Accessors
@@ -250,7 +273,7 @@
(if (null? arg-rest)
#t
(let ((arg2 (car arg-rest)))
- (check-compatible! arg1 arg2)
+ (check-compatible arg1 arg2)
(if (binary cmp arg1 arg2)
(loop arg2 (cdr arg-rest))
#f)))))))
@@ -303,7 +326,7 @@
(if (null? arg-rest)
arg1
(let ((arg2 (car arg-rest)))
- (check-compatible! arg1 arg2)
+ (check-compatible arg1 arg2)
(loop (binary cmp arg1 arg2)
(cdr arg-rest))))))))
@@ -369,10 +392,12 @@
(raw-set comparator
(in-order-container->node container ref length)))
-(define (binary-compatible? s1 s2)
- (eq? (set-element-comparator s1) (set-element-comparator s2)))
+(define (binary-compatible s1 s2)
+ (let ((cmp (set-element-comparator s1)))
+ (and (eq? cmp (set-element-comparator s2))
+ cmp)))
(define compatible-sets?
(apply-nary-predicate (lambda (cut set1 set2)
- (binary-compatible? set1 set2))))
+ (binary-compatible set1 set2))))
23Add ldconfig in deb postinst for Debian policy conformance.Gravatar aeb 2-2/+17 2000-11-23Removed acconfig.h, which wasn't needed for some time.Gravatar aeb 1-13/+0 2000-11-22Added ieee1394.h header.Gravatar aeb 3-1/+38 2000-09-13Fix raw1394_start_iso_write() which uses wrong variable.Gravatar aeb 1-1/+1 2000-09-10Work around compiler warnings for int/ptr casts.Gravatar aeb 6-10/+20 2000-09-10Added control files for Debian packages.Gravatar aeb 6-8/+106 2000-09-01Added missing prototypes for iso send functions.Gravatar aeb 1-0/+7 2000-08-08Added raw1394_get_irm_id().Gravatar aeb 7-7/+39 2000-08-06Added support for isochronous sending.Gravatar aeb 3-0/+35 2000-07-05Added raw1394_reset_bus() call.Gravatar aeb 4-0/+23 2000-06-22- Set library version info in configure.in, use in src/Makefile.am.Gravatar aeb 4-2/+16 2000-06-15Update libtool version number.Gravatar aeb 2-2/+2 2000-06-14Added copyright headers.Gravatar aeb 6-0/+54 2000-06-11Added explicit AC_PROG_INSTALL call.Gravatar aeb 1-0/+1 2000-06-09Fix size of error field.Gravatar aeb 1-2/+2 2000-06-02Modified support for 32/64 bit environments, control struct fields have fixed...Gravatar aeb 7-43/+28 2000-05-28Added support for environments with 64 bit kernel and 32 bit userland.Gravatar aeb 8-7/+45 2000-04-27Fixed missing setting of ext code in raw1394_start_lock()Gravatar aeb 1-0/+1 2000-04-15Fixed lock transaction to actually return response value.Gravatar aeb 3-5/+11 2000-04-12Add userdata functions as news.Gravatar aeb 1-0/+4 2000-04-05Add userdata functions.Gravatar aeb 3-0/+18 2000-03-18Bump version number to 0.6.Gravatar aeb 3-5/+6 2000-03-18Mention byte order change.Gravatar aeb 1-0/+2 2000-03-18Mention SourceForge home.Gravatar aeb 1-1/+5