Skip to content

Commit

Permalink
Actually implement range-set-span
Browse files Browse the repository at this point in the history
Guess I never got around to doing this.
  • Loading branch information
jackfirth committed Apr 17, 2024
1 parent 0cc772e commit 5392898
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 7 deletions.
12 changes: 8 additions & 4 deletions collection/private/endpoint-map-range-set.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
(endpoint-map-range-containing-or-absent (this-endpoints this) (this-comparator this) value))

(define (range-set-span-or-absent this)
(endpoint-map-span-or-absent (this-endpoints this)))
(endpoint-map-span-or-absent (this-endpoints this) (this-comparator this)))

(define (range-subset this subset-range)
(define cut-comparator (cut<=> (range-comparator subset-range)))
Expand Down Expand Up @@ -287,7 +287,7 @@
(endpoint-map-range-containing-or-absent (this-endpoints this) (this-comparator this) value))

(define (range-set-span-or-absent this)
(endpoint-map-span-or-absent (this-endpoints this)))
(endpoint-map-span-or-absent (this-endpoints this) (this-comparator this)))

(define (range-subset this subset-range)
TODO)]
Expand Down Expand Up @@ -369,8 +369,12 @@
(λ (nearest-range) (range-contains? nearest-range value))))


(define (endpoint-map-span-or-absent endpoints)
TODO)
(define/guard (endpoint-map-span-or-absent endpoints comparator)
(guard (sorted-map-empty? endpoints) then
absent)
(match-define (present lower-cut) (sorted-map-least-key endpoints))
(match-define (present (entry _ upper-cut)) (sorted-map-greatest-entry endpoints))
(present (range-from-cuts lower-cut upper-cut #:comparator comparator)))


(define/guard (endpoint-map-get-nearest-range endpoints comparator cut)
Expand Down
16 changes: 15 additions & 1 deletion collection/range-set.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -593,4 +593,18 @@
(test-case "remove span enclosing range"
(define actual (range-set-remove ranges (closed-range 2 25)))
(define expected (range-set #:comparator real<=>))
(check-equal? actual expected)))))
(check-equal? actual expected))))

(test-case (name-string range-set-span)

(test-case "closed ranges"
(define actual (range-set-span (range-set (closed-range 2 5) (closed-range 7 10))))
(check-equal? actual (closed-range 2 10)))

(test-case "open ranges"
(define actual (range-set-span (range-set (open-range 2 5) (open-range 7 10))))
(check-equal? actual (open-range 2 10)))

(test-case "closed and open ranges"
(define actual (range-set-span (range-set (closed-range 2 5) (open-range 7 10))))
(check-equal? actual (closed-open-range 2 10)))))
5 changes: 3 additions & 2 deletions collection/range-set.scrbl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
racket/sequence
racket/set
rebellion/base/comparator
rebellion/base/option
rebellion/base/range
rebellion/collection/range-set
rebellion/streaming/reducer
Expand Down Expand Up @@ -268,7 +269,7 @@ descending order, use @racket[in-range-set] with @racket[#:descending?] set to t

@(examples
#:eval (make-evaluator) #:once
(range-set-span (range-set (closed-range 2 5) (oepn-range 9 10)))
(range-set-span (range-set (closed-range 2 5) (open-range 9 10)))
(eval:error (range-set-span (range-set #:comparator real<=>)))
(range-set-span (range-set #:comparator real<=>) "empty range set!"))}

Expand All @@ -280,7 +281,7 @@ descending order, use @racket[in-range-set] with @racket[#:descending?] set to t

@(examples
#:eval (make-evaluator) #:once
(range-set-span-or-absent (range-set (closed-range 2 5) (oepn-range 9 10)))
(range-set-span-or-absent (range-set (closed-range 2 5) (open-range 9 10)))
(range-set-span-or-absent (range-set #:comparator real<=>)))}


Expand Down

0 comments on commit 5392898

Please sign in to comment.