Sha256: e929e375d8cac2c63a65c9f56cf2b17374e8986221f6d03cb98499ab39b80905

Contents?: true

Size: 1.42 KB

Versions: 1

Compression:

Stored size: 1.42 KB

Contents

module Veritas
  class Optimizer
    module Logic
      class Predicate

        # Abstract base class representing Inclusion optimizations
        class Inclusion < self
          include Enumerable

          # Optimize when the right operand is empty
          class EmptyRightOperand < self
            include Enumerable::EmptyRightOperand

            # An Inclusion with an empty right operand matches nothing
            #
            # @return [False]
            #
            # @api private
            def optimize
              Veritas::Logic::Proposition::False.instance
            end

          end # class EmptyRightOperand

          # Optimize when the right operand has one entry
          class OneRightOperand < self
            include Enumerable::OneRightOperand

            # An Inclusion with a single right operand is equivalent to an Equality
            #
            # @return [Equality]
            #
            # @api private
            def optimize
              Veritas::Logic::Predicate::Equality.new(left, right.first).optimize
            end

          end # class OneRightOperand

          Veritas::Logic::Predicate::Inclusion.optimizer = chain(
            ConstantOperands,
            EmptyRightOperand,
            OneRightOperand,
            UnoptimizedOperand
          )

        end # class Inclusion
      end # class Predicate
    end # module Logic
  end # class Optimizer
end # module Veritas

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
veritas-0.0.2 lib/veritas/optimizer/logic/predicate/inclusion.rb