tur/range
Range: continuous interval with inclusive, exclusive, or unbounded ends.
Since: Phase LZ4
range-bound-new
(range-bound-new [inclusive :int value :int] :int)
allocate a RangeBound with given inclusivity and value.
| inclusive | 1 for inclusive, 0 for exclusive | |
| value | the endpoint value |
int64_t pointer to a heap RangeBound.
Since: LZ4
range-bound-inclusive?
(range-bound-inclusive? [b :int] :bool)
true if the bound is inclusive.
| b | int64_t pointer to a RangeBound (must not be 0) |
Since: LZ4
range-bound-value
(range-bound-value [b :int] :int)
return the endpoint value of a bound.
| b | int64_t pointer to a RangeBound (must not be 0) |
Since: LZ4
range-bound-flip
(range-bound-flip [b :int] :int)
return a new bound with the same value but flipped inclusivity.
| b | int64_t pointer to a RangeBound (must not be 0) |
Since: LZ4
range-new
(range-new [lower :int upper :int] :int)
allocate a Range from lower and upper bound pointers.
| lower | 0 for unbounded below, else RangeBound pointer | |
| upper | 0 for unbounded above, else RangeBound pointer |
int64_t pointer to a heap Range.
Since: LZ4
range-lower
(range-lower [r :int] :int)
return the lower bound pointer (0 = unbounded).
| r | int64_t pointer to a Range |
Since: LZ4
range-upper
(range-upper [r :int] :int)
return the upper bound pointer (0 = unbounded).
| r | int64_t pointer to a Range |
Since: LZ4
range-abort-not-connected
(range-abort-not-connected :int)
range-abort-connected
(range-abort-connected :int)
range-abort-unbounded-lower
(range-abort-unbounded-lower :int)
closed-range
(closed-range [lo :int hi :int] :int)
[lo, hi] both endpoints inclusive.
| lo | lower bound value | |
| hi | upper bound value |
A Range representing [lo, hi].
(closed-range 1 5) ; => [1, 5]
Since: LZ4
open-range
(open-range [lo :int hi :int] :int)
(lo, hi) both endpoints exclusive.
| lo | lower bound value (excluded) | |
| hi | upper bound value (excluded) |
A Range representing (lo, hi).
(open-range 1 5) ; => (1, 5)
Since: LZ4
closed-open-range
(closed-open-range [lo :int hi :int] :int)
[lo, hi) inclusive lower, exclusive upper.
| lo | lower bound value (included) | |
| hi | upper bound value (excluded) |
A Range representing [lo, hi).
(closed-open-range 1 5) ; => [1, 5)
Since: LZ4
open-closed-range
(open-closed-range [lo :int hi :int] :int)
(lo, hi] exclusive lower, inclusive upper.
| lo | lower bound value (excluded) | |
| hi | upper bound value (included) |
A Range representing (lo, hi].
(open-closed-range 1 5) ; => (1, 5]
Since: LZ4
at-least-range
(at-least-range [lo :int] :int)
[lo, +inf) inclusive lower, unbounded above.
| lo | lower bound value (included) |
A Range representing [lo, +inf).
(at-least-range 5) ; => [5, +inf)
Since: LZ4
greater-than-range
(greater-than-range [lo :int] :int)
(lo, +inf) exclusive lower, unbounded above.
| lo | lower bound value (excluded) |
A Range representing (lo, +inf).
(greater-than-range 5) ; => (5, +inf)
Since: LZ4
at-most-range
(at-most-range [hi :int] :int)
(-inf, hi] unbounded below, inclusive upper.
| hi | upper bound value (included) |
A Range representing (-inf, hi].
(at-most-range 5) ; => (-inf, 5]
Since: LZ4
less-than-range
(less-than-range [hi :int] :int)
(-inf, hi) unbounded below, exclusive upper.
| hi | upper bound value (excluded) |
A Range representing (-inf, hi).
(less-than-range 5) ; => (-inf, 5)
Since: LZ4
singleton-range
(singleton-range [v :int] :int)
[v, v] a range containing exactly one value.
| v | the single value |
A Range representing [v, v].
(singleton-range 3) ; => [3, 3]
Since: LZ4
unbounded-range
(unbounded-range :int)
(-inf, +inf) no bounds at all.
A Range representing all values.
(unbounded-range) ; => (-inf, +inf)
Since: LZ4
range-val-in-lower?
(range-val-in-lower? [b :int v :int] :bool)
range-val-in-upper?
(range-val-in-upper? [b :int v :int] :bool)
range-bound-strictly-before?
(range-bound-strictly-before? [u :int l :int] :bool)
range-bound-has-gap?
(range-bound-has-gap? [u :int l :int] :bool)
range-contains?
(range-contains? [r :int v :int] :bool)
true if value v falls within range r.
| r | int64_t pointer to a Range | |
| v | value to test |
true if v satisfies both the lower and upper bounds of r.
(range-contains? (closed-range 1 5) 3) ; => true (range-contains? (open-range 1 5) 1) ; => false
Since: LZ4
range-encloses?
(range-encloses? [r :int other :int] :bool)
true if every value in other is also in r.
| r | the outer Range | |
| other | the inner Range |
true if r's lower <= other's lower and r's upper >= other's upper (accounting for inclusive/exclusive endpoints).
(range-encloses? (closed-range 0 10) (closed-range 2 8)) ; => true
Since: LZ4
range-connected?
(range-connected? [r1 :int r2 :int] :bool)
true if no gap exists between r1 and r2.
| r1 | first Range | |
| r2 | second Range |
true if r1 and r2 are connected.
(range-connected? (closed-open-range 1 3) (closed-range 3 5)) ; => true (range-connected? (less-than-range 3) (greater-than-range 3)) ; => false
Since: LZ4
range-overlaps?
(range-overlaps? [r1 :int r2 :int] :bool)
true if r1 and r2 share at least one common value.
| r1 | first Range | |
| r2 | second Range |
true if there exists a value contained in both r1 and r2.
(range-overlaps? (closed-range 1 3) (closed-range 3 5)) ; => true (range-overlaps? (closed-open-range 1 3) (closed-range 3 5)) ; => false
Since: LZ4
bounded-range?
(bounded-range? [r :int] :bool)
true if both endpoints are present.
| r | int64_t pointer to a Range |
Since: LZ4
bounded-above?
(bounded-above? [r :int] :bool)
true if r has an upper bound.
| r | int64_t pointer to a Range |
Since: LZ4
bounded-below?
(bounded-below? [r :int] :bool)
true if r has a lower bound.
| r | int64_t pointer to a Range |
Since: LZ4
unbounded-above?
(unbounded-above? [r :int] :bool)
true if r has no upper bound.
| r | int64_t pointer to a Range |
Since: LZ4
unbounded-below?
(unbounded-below? [r :int] :bool)
true if r has no lower bound.
| r | int64_t pointer to a Range |
Since: LZ4
singleton-range?
(singleton-range? [r :int] :bool)
true if r contains exactly one value.
| r | int64_t pointer to a Range |
Since: LZ4
empty-range?
(empty-range? [r :int] :bool)
true if r contains no values.
| r | int64_t pointer to a Range |
Since: LZ4
nonempty-range?
(nonempty-range? [r :int] :bool)
true if r contains at least one value.
| r | int64_t pointer to a Range |
Since: LZ4
range-lower-min
(range-lower-min [b1 :int b2 :int] :int)
range-upper-max
(range-upper-max [b1 :int b2 :int] :int)
range-lower-max
(range-lower-max [b1 :int b2 :int] :int)
range-upper-min
(range-upper-min [b1 :int b2 :int] :int)
range-span
(range-span [r1 :int r2 :int] :int)
smallest range enclosing both r1 and r2 (convex hull).
| r1 | first Range | |
| r2 | second Range |
A Range whose lower bound is the min of both lowers and whose upper bound is the max of both uppers.
(range-span (closed-range 1 3) (closed-range 5 8)) ; => [1, 8]
Since: LZ4
range-intersection
(range-intersection [r1 :int r2 :int] :int)
largest range enclosed by both r1 and r2.
| r1 | first Range | |
| r2 | second Range |
A Range representing the intersection of r1 and r2.
(range-intersection (closed-range 1 5) (closed-range 3 8)) ; => [3, 5]
Since: LZ4
range-gap
(range-gap [r1 :int r2 :int] :int)
largest range lying strictly between r1 and r2.
| r1 | first Range | |
| r2 | second Range |
A Range representing the gap between r1 and r2. The gap's bounds are the flipped endpoints of whichever range ends first and whichever starts second.
(range-gap (closed-range 1 3) (closed-range 5 8)) ; => (3, 5) (range-gap (closed-open-range 1 3) (open-range 3 8)) ; => [3, 3]
Since: LZ4
seq/from-range
(seq/from-range [r :int] :int)
convert a bounded integer Range to a lazy Seq.
| r | int64_t pointer to a Range (integer endpoints) |
A Seq yielding each integer in r in ascending order.
(seq-for-each println (seq/from-range (closed-range 1 4))) ; => 1 2 3 4 (seq-for-each println (seq/from-range (open-range 1 5))) ; => 2 3 4
Since: LZ4
seq/from-range-step
(seq/from-range-step [step :int r :int] :int)
convert a bounded integer Range to a Seq with a custom step.
| step | increment per element (nonzero) | |
| r | int64_t pointer to a Range (integer endpoints) |
A Seq yielding each integer in r at the given step.
(seq-for-each println (seq/from-range-step 2 (closed-range 0 8))) ; => 0 2 4 6 8
Since: LZ4