Class: S3Stream::BufferGrowth
- Inherits:
-
Object
- Object
- S3Stream::BufferGrowth
- Defined in:
- lib/s3stream/buffer_growth.rb
Constant Summary collapse
- EPSILON =
1.0e-16
Instance Method Summary collapse
-
#initialize(initial_buffer_size, max_file_size, max_chunks) ⇒ BufferGrowth
constructor
A new instance of BufferGrowth.
- #solve ⇒ Object
Constructor Details
#initialize(initial_buffer_size, max_file_size, max_chunks) ⇒ BufferGrowth
Returns a new instance of BufferGrowth.
6 7 8 9 10 |
# File 'lib/s3stream/buffer_growth.rb', line 6 def initialize(initial_buffer_size, max_file_size, max_chunks) @max_chunks = max_chunks @max_file_size = max_file_size @initial_buffer_size = initial_buffer_size end |
Instance Method Details
#solve ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/s3stream/buffer_growth.rb', line 12 def solve lower_bound = 1.0 upper_bound = 1.0 upper_bound *= 2.0 until too_big?(upper_bound) begin puts "bounds: #{[lower_bound, upper_bound]}" return lower_bound if (upper_bound - lower_bound) < EPSILON guess = (lower_bound + upper_bound) / 2.0 return lower_bound if [lower_bound,upper_bound].include?(guess) if too_big?(guess) upper_bound = guess else lower_bound = guess end end while true end |