Sha256: 67589b59487c676b92cfda6b2c043dcee9b8bcdb5bc9f40846ef17183fcecf78

Contents?: true

Size: 748 Bytes

Versions: 3

Compression:

Stored size: 748 Bytes

Contents

class LogSlice
  class SearchBoundary

    attr_reader :cursor

    def initialize file_size
      @file_size = file_size
    end

    # reset the search boundary to cover the entire file
    def reset
      @lower = 0
      @upper = @file_size
      @cursor = 0
      cursor_forward
      self
    end

    # Move cursor forward.
    # The cursor is moved half way between it's start location and the upper boundary.
    def cursor_forward
      @lower = @cursor
      @cursor = @cursor + (@upper - @cursor) / 2
    end

    # Move cursor backward.
    # The cursor is moved half way between it's start location and the lower boundary.
    def cursor_back
      @upper = @cursor
      @cursor = @cursor - (@cursor - @lower) / 2
    end

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
log_slice-0.4 lib/log_slice/search_boundary.rb
log_slice-0.3 lib/log_slice/search_boundary.rb
log_slice-0.2 lib/log_slice/search_boundary.rb