Sha256: ddf02ca8dcbac8af0079de09520b81887f9cb7eb075c1a8d6b75d36d44d397e6

Contents?: true

Size: 1.28 KB

Versions: 32

Compression:

Stored size: 1.28 KB

Contents

module Bmg
  module Operator
    #
    # NotMatching operator.
    #
    # Filters tuples of left operand to those matching no tuple
    # in right operand.
    #
    class NotMatching
      include Operator::Binary

      def initialize(type, left, right, on)
        @type = type
        @left = left
        @right = right
        @on = on
      end

    private

      attr_reader :on

    public

      def each
        index = Hash.new
        right.each_with_object(index) do |t, index|
          key = tuple_project(t, on)
          index[key] = true
        end
        left.each do |tuple|
          key = tuple_project(tuple, on)
          yield tuple unless index.has_key?(key)
        end
      end

      def to_ast
        [ :not_matching, left.to_ast, right.to_ast, on ]
      end

    protected ### optimization

      def _restrict(type, predicate)
        # Predicate can always be fully applied to left
        # It can never be applied on right, unlike matching
        left
          .restrict(predicate)
          .not_matching(right, on)
      end

    protected ### inspect

      def args
        [ on ]
      end

    private

      def tuple_project(tuple, on)
        TupleAlgebra.project(tuple, on)
      end

    end # class NotMatching
  end # module Operator
end # module Bmg

Version data entries

32 entries across 32 versions & 1 rubygems

Version Path
bmg-0.18.2 lib/bmg/operator/not_matching.rb
bmg-0.18.1 lib/bmg/operator/not_matching.rb
bmg-0.18.0 lib/bmg/operator/not_matching.rb
bmg-0.17.8 lib/bmg/operator/not_matching.rb
bmg-0.17.7 lib/bmg/operator/not_matching.rb
bmg-0.17.6 lib/bmg/operator/not_matching.rb
bmg-0.17.5 lib/bmg/operator/not_matching.rb
bmg-0.17.4 lib/bmg/operator/not_matching.rb
bmg-0.17.3 lib/bmg/operator/not_matching.rb
bmg-0.17.2 lib/bmg/operator/not_matching.rb
bmg-0.16.7 lib/bmg/operator/not_matching.rb
bmg-0.17.1 lib/bmg/operator/not_matching.rb
bmg-0.17.0 lib/bmg/operator/not_matching.rb
bmg-0.16.6 lib/bmg/operator/not_matching.rb
bmg-0.16.5 lib/bmg/operator/not_matching.rb
bmg-0.16.4 lib/bmg/operator/not_matching.rb
bmg-0.16.3 lib/bmg/operator/not_matching.rb
bmg-0.16.2 lib/bmg/operator/not_matching.rb
bmg-0.16.1 lib/bmg/operator/not_matching.rb
bmg-0.16.0 lib/bmg/operator/not_matching.rb