Module: Ibex::LALR::ConflictSearchLimits

Included in:
ConflictSearch
Defined in:
lib/ibex/lalr/conflict_search_limits.rb,
sig/ibex/lalr/conflict_search_limits.rbs

Overview

Validates search limits and measures sentences against the token budget.

Constant Summary collapse

DEFAULT_MAX_TOKENS =

Signature:

  • Integer

Returns:

  • (Integer)
32
DEFAULT_MAX_CONFIGURATIONS =

Signature:

  • Integer

Returns:

  • (Integer)
50_000

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.validate!(max_tokens:, max_configurations:) ⇒ void

This method returns an undefined value.

RBS:

  • (max_tokens: Integer, max_configurations: Integer) -> void

Parameters:

  • max_tokens: (Integer)
  • max_configurations: (Integer)


11
12
13
14
# File 'lib/ibex/lalr/conflict_search_limits.rb', line 11

def self.validate!(max_tokens:, max_configurations:)
  validate_limit!(:max_tokens, max_tokens)
  validate_limit!(:max_configurations, max_configurations)
end

.validate_limit!(name, value) ⇒ Integer

RBS:

  • (Symbol name, Integer value) -> Integer

Parameters:

  • name (Symbol)
  • value (Integer)

Returns:

  • (Integer)


17
18
19
20
21
# File 'lib/ibex/lalr/conflict_search_limits.rb', line 17

def self.validate_limit!(name, value)
  return value if value.is_a?(Integer) && value.positive?

  raise ArgumentError, "#{name} must be a positive Integer"
end

Instance Method Details

#conflict_lookahead_lengthInteger

RBS:

  • () -> Integer

Returns:

  • (Integer)


36
# File 'lib/ibex/lalr/conflict_search_limits.rb', line 36

def conflict_lookahead_length = @lookahead.zero? ? 0 : 1

#room_for_token?(prefix, suffix) ⇒ Boolean

RBS:

  • (Array[Integer] prefix, Array[Integer] suffix) -> bool

Parameters:

  • prefix (Array[Integer])
  • suffix (Array[Integer])

Returns:

  • (Boolean)


31
32
33
# File 'lib/ibex/lalr/conflict_search_limits.rb', line 31

def room_for_token?(prefix, suffix)
  prefix.length + suffix.length + conflict_lookahead_length < @max_tokens
end

#within_token_budget?(prefix, suffix) ⇒ Boolean

RBS:

  • (Array[Integer] prefix, Array[Integer] suffix) -> bool

Parameters:

  • prefix (Array[Integer])
  • suffix (Array[Integer])

Returns:

  • (Boolean)


26
27
28
# File 'lib/ibex/lalr/conflict_search_limits.rb', line 26

def within_token_budget?(prefix, suffix)
  prefix.length + suffix.length + conflict_lookahead_length <= @max_tokens
end