Class: CleverSequence::LowerBoundFinder
- Inherits:
-
Object
- Object
- CleverSequence::LowerBoundFinder
- Defined in:
- lib/demo_mode/clever_sequence/lower_bound_finder.rb
Instance Attribute Summary collapse
-
#block ⇒ Object
readonly
Returns the value of attribute block.
-
#column_name ⇒ Object
readonly
Returns the value of attribute column_name.
-
#klass ⇒ Object
readonly
Returns the value of attribute klass.
Instance Method Summary collapse
-
#initialize(klass, column_name, block) ⇒ LowerBoundFinder
constructor
A new instance of LowerBoundFinder.
- #lower_bound(hint: nil) ⇒ Object
Constructor Details
#initialize(klass, column_name, block) ⇒ LowerBoundFinder
Returns a new instance of LowerBoundFinder.
7 8 9 10 11 |
# File 'lib/demo_mode/clever_sequence/lower_bound_finder.rb', line 7 def initialize(klass, column_name, block) @klass = klass @column_name = column_name @block = block end |
Instance Attribute Details
#block ⇒ Object (readonly)
Returns the value of attribute block.
5 6 7 |
# File 'lib/demo_mode/clever_sequence/lower_bound_finder.rb', line 5 def block @block end |
#column_name ⇒ Object (readonly)
Returns the value of attribute column_name.
5 6 7 |
# File 'lib/demo_mode/clever_sequence/lower_bound_finder.rb', line 5 def column_name @column_name end |
#klass ⇒ Object (readonly)
Returns the value of attribute klass.
5 6 7 |
# File 'lib/demo_mode/clever_sequence/lower_bound_finder.rb', line 5 def klass @klass end |
Instance Method Details
#lower_bound(hint: nil) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/demo_mode/clever_sequence/lower_bound_finder.rb', line 13 def lower_bound(hint: nil) with_lock do start = hint && hint >= 1 ? hint : 1 # If the hint overshoots the actual data, return it directly. # The hint is a previously-known high-water mark, so it's a valid # lower bound. Callers pass the result through GREATEST against the # PG sequence, so a higher value is always safe and avoids a costly # binary search back down to data that won't be used anyway. next hint if start > 1 && !exists?(start) _lower_bound(start, 0, Float::INFINITY) end end |