Module: Parslet::Source::RangeSearch

### Home Classes Methods

### In Files

- lib/parslet/source/line_cache.rb

### Methods

- #find_mid
- #lbound

### Files

- README

### Class/Module Index

Quicksearch

- Parslet
- Parslet::Atoms
- Parslet::Atoms::Alternative
- Parslet::Atoms::Base
- Parslet::Atoms::CanFlatten
- Parslet::Atoms::Capture
- Parslet::Atoms::Context
- Parslet::Atoms::DSL
- Parslet::Atoms::Dynamic
- Parslet::Atoms::Entity
- Parslet::Atoms::Lookahead
- Parslet::Atoms::Named
- Parslet::Atoms::Precedence
- Parslet::Atoms::Re
- Parslet::Atoms::Repetition
- Parslet::Atoms::Scope
- Parslet::Atoms::Sequence
- Parslet::Atoms::Str
- Parslet::Cause
- Parslet::ClassMethods
- Parslet::DelayedMatchConstructor
- Parslet::ErrorReporter
- Parslet::ErrorReporter::Deepest
- Parslet::ErrorReporter::Tree
- Parslet::Expression
- Parslet::Expression::Treetop
- Parslet::Expression::Treetop::Parser
- Parslet::Expression::Treetop::Transform
- Parslet::ParseFailed
- Parslet::Parser
- Parslet::Parser::PrettyPrinter
- Parslet::Parser::Visitors
- Parslet::Parser::Visitors::Citrus
- Parslet::Parser::Visitors::Treetop
- Parslet::Pattern
- Parslet::Pattern::SequenceBind
- Parslet::Pattern::SimpleBind
- Parslet::Pattern::SubtreeBind
- Parslet::Scope
- Parslet::Scope::Binding
- Parslet::Scope::NotFound
- Parslet::Slice
- Parslet::Source
- Parslet::Source::LineCache
- Parslet::Source::RangeSearch
- Parslet::Transform
- Parslet::Transform::Context

No matching classes.

# Parslet::Source::RangeSearch

Mixin for arrays that implicitly give a number of ranges, where one range begins where the other one ends.

    Example:

      [10, 20, 30]
      # would describe [0, 10], (10, 20], (20, 30]

### Public Instance Methods

find_mid(left, right) click to toggle source

    # File lib/parslet/source/line_cache.rb, line 63
    def find_mid(left, right)
      # NOTE: Jonathan Hinkle reported that when mathn is required, just
      # dividing and relying on the integer truncation is not enough.
      left + ((right - left) / 2).floor
    end

lbound(bound) click to toggle source

Scans the array for the first number that is > than bound. Returns the index of that number.

    # File lib/parslet/source/line_cache.rb, line 72
    def lbound(bound)
      return nil if empty?
      return nil unless last > bound

      left = 0
      right = size - 1

      loop do
        mid = find_mid(left, right)

        if self[mid] > bound
          right = mid
        else
          # assert: self[mid] <= bound
          left = mid+1
        end

        if right <= left
          return right
        end
      end
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.