create ordered sequence of the given ranges' start and end values
This commit is contained in:
@@ -27,4 +27,28 @@
|
||||
(value-before [this])
|
||||
(value-after [this])
|
||||
(start [this])
|
||||
(end [this]))
|
||||
(end [this])
|
||||
(range-type [this]))
|
||||
|
||||
(defn- ordered-range-values
|
||||
"Builds an ordered list or 'fenceposts' for the start and end
|
||||
of all given ranges, to prepare to produces a consolidated
|
||||
set of ranges, by doing open/close count matching.
|
||||
|
||||
By building this list, it will allow us to push a `start`
|
||||
onto a stack, and `pop` when we encounter an `end.`
|
||||
|
||||
If we pop, and get an empty stack, we have found the item
|
||||
that represents the end value that matches the start value
|
||||
that we just popped off the stack, and are able to ignore
|
||||
any intermediate matching starts/stops."
|
||||
[ranges]
|
||||
(->> ranges
|
||||
(mapcat (fn [range]
|
||||
[{:value (start range)
|
||||
:boundary-type :start
|
||||
:type (range-type range)}
|
||||
{:value (end range)
|
||||
:boundary-type :end
|
||||
:type (range-type range)}]))
|
||||
(sort-by (juxt :value (comp {:start 0 :end 1} :boundary-type)))))
|
||||
|
||||
Reference in New Issue
Block a user