module
VirtualTime::RangeHelper
Defined in:
virtualtime.crClass Method Summary
-
.count(value) : Int64 | Nil
Returns how many values the range or stepped range yields, or nil for a value whose size is not knowable arithmetically.
-
.empty_step?(value : Steppable::StepIterator(Int32, Int32, Int32)) : Bool
Returns whether the stepped range yields no value at all.
-
.first_from(value : Steppable::StepIterator(Int32, Int32, Int32), element : Int32) : Int32 | Nil
Returns the smallest value the stepped range yields that is at least
element, or nil when it yields none. -
.includes?(value : Steppable::StepIterator(Int32, Int32, Int32), element : Int32) : Bool
Returns whether the stepped range yields
element. -
.includes?(value : Array(Int32) | Set(Int32) | Range(Int32, Int32), element : Int32) : Bool
:ditto: for the collections that answer membership on their own.
-
.intersect?(a : Range(Int32, Int32), b : Range(Int32, Int32)) : Bool
Returns whether the two ranges have at least one value in common.
-
.intersect?(a : Range(Int32, Int32), b : Steppable::StepIterator(Int32, Int32, Int32)) : Bool
Returns whether the range and the stepped range have at least one value in common, worked out from their bounds rather than by walking either.
-
.intersect?(a : Steppable::StepIterator(Int32, Int32, Int32), b : Range(Int32, Int32)) : Bool
Returns whether the range and the stepped range have at least one value in common, worked out from their bounds rather than by walking either.
-
.intersect?(a : Steppable::StepIterator(Int32, Int32, Int32), b : Steppable::StepIterator(Int32, Int32, Int32)) : Bool
Returns whether the two stepped ranges have at least one value in common.
-
.largest(value : Steppable::StepIterator(Int32, Int32, Int32)) : Int32 | Nil
Returns the largest value the stepped range yields, or nil when it yields none.
-
.last(range : Range(Int32, Int32)) : Int32 | Nil
Returns the last value included in
range, ornilif it contains no values. -
.restart(value : Steppable::StepIterator(Int32, Int32, Int32))
Returns
valueready to be iterated from its first element. -
.restart(value)
Returns
valueready to be iterated from its first element. -
.smallest(value : Steppable::StepIterator(Int32, Int32, Int32)) : Int32 | Nil
Returns the smallest value the stepped range yields, or nil when it yields none.
Class Method Detail
Returns how many values the range or stepped range yields, or nil for a value whose size is not knowable arithmetically.
In Int64, since a range over Int32 bounds can hold more values than
Int32 counts.
Returns whether the stepped range yields no value at all.
Worked out from the bounds rather than by stepping, which would mean copying the iterator -- it is stateful -- on every comparison.
Returns the smallest value the stepped range yields that is at least
element, or nil when it yields none.
Returns whether the stepped range yields element.
Arithmetic rather than iteration, for the same reason #intersect? is:
a stepped range over a second's worth of nanoseconds holds hundreds of
millions of values, and walking them to answer a single comparison is
exactly what the plain ranges beside it are careful never to do.
:ditto: for the collections that answer membership on their own.
Returns whether the two ranges have at least one value in common.
This is the O(1) counterpart of intersecting them by iteration, which matters because VirtualTime ranges can be enormous (e.g. nanoseconds).
Returns whether the range and the stepped range have at least one value in common, worked out from their bounds rather than by walking either.
Returns whether the range and the stepped range have at least one value in common, worked out from their bounds rather than by walking either.
Returns whether the two stepped ranges have at least one value in common.
Each is an arithmetic progression, so a common value is one that satisfies both of their congruences -- a question the Chinese remainder theorem answers in constant time, where walking either progression costs as many steps as it has values.
Returns the largest value the stepped range yields, or nil when it yields none.
Returns the last value included in range, or nil if it contains no values.
Returns value ready to be iterated from its first element.
Steppable::StepIterators are stateful and are consumed by iteration,
so they must be copied before every traversal; everything else is
returned as-is.
The copy is only as complete as value itself: iterating past the first
element moves an iterator's current bound, and nothing records where
it started. That is why a VirtualTime never lets the iterator it
stores out of its hands -- see virtual_time_property.
Returns value ready to be iterated from its first element.
Steppable::StepIterators are stateful and are consumed by iteration,
so they must be copied before every traversal; everything else is
returned as-is.
The copy is only as complete as value itself: iterating past the first
element moves an iterator's current bound, and nothing records where
it started. That is why a VirtualTime never lets the iterator it
stores out of its hands -- see virtual_time_property.
Returns the smallest value the stepped range yields, or nil when it yields none.