module VirtualTime::RangeHelper

Defined in:

virtualtime.cr

Class Method Summary

Class Method Detail

def self.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.

In Int64, since a range over Int32 bounds can hold more values than Int32 counts.


[View source]
def self.empty_step?(value : Steppable::StepIterator(Int32, Int32, Int32)) : Bool #

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.


[View source]
def self.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.


[View source]
def self.includes?(value : Steppable::StepIterator(Int32, Int32, Int32), element : Int32) : Bool #

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.


[View source]
def self.intersect?(a : Range(Int32, Int32), b : Range(Int32, Int32)) : Bool #

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).


[View source]
def self.last(range : Range(Int32, Int32)) : Int32 | Nil #

Returns the last value included in range, or nil if it contains no values.


[View source]
def self.restart(value : Steppable::StepIterator(Int32, Int32, Int32)) #

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.


[View source]
def self.restart(value) #

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.


[View source]
def self.smallest(value : Steppable::StepIterator(Int32, Int32, Int32)) : Int32 | Nil #

Returns the smallest value the stepped range yields, or nil when it yields none.


[View source]