start of protocol for discrete value ranges
This commit is contained in:
30
src/challenge/discrete_value_range.clj
Normal file
30
src/challenge/discrete_value_range.clj
Normal file
@@ -0,0 +1,30 @@
|
||||
(ns challenge.discrete-value-range)
|
||||
|
||||
(defprotocol DiscreteValueRange
|
||||
"A protocol for generic behavior on Ranges over
|
||||
discrete values.
|
||||
|
||||
This is for discrete values as we want to be
|
||||
able to determine the value before the range
|
||||
start and the value immediately after the range end.
|
||||
|
||||
By using discrete values we:
|
||||
1. Determine if two ranges abut (touch) each other, and
|
||||
can therefore be combined into a single range
|
||||
2. Can combine overlapping by listing all ranges' start
|
||||
and end values, and using a stack's push/pop functionality
|
||||
to know if we are in a larger composite range, similiar
|
||||
to parenthesis matching. e.g. If I encounter two range
|
||||
start items, I know I should be expecting two end values,
|
||||
even if the range is 'unbounded', there should be a MIN/MAX
|
||||
value specified.
|
||||
3. Know the discrete values for both before and or after the range
|
||||
(even if a MIN/MAX marker) value that we can use to compare
|
||||
that before/after values against other values that the range
|
||||
is over.
|
||||
"
|
||||
(abuts [this ^DiscreteValueRange other])
|
||||
(value-before [this])
|
||||
(value-after [this])
|
||||
(start [this])
|
||||
(end [this]))
|
||||
Reference in New Issue
Block a user