Sha256: 64c53a67c0c4870cc3e027381dd529cfb4cd4a13262b9f1da7898923f1484a97

Contents?: true

Size: 1.38 KB

Versions: 2

Compression:

Stored size: 1.38 KB

Contents

module Alf
  module Operator::NonRelational
    class Compact < Alf::Operator()
      include Operator::NonRelational, Operator::Shortcut, Operator::Unary
  
      signature do |s|
      end
      
      # Removes duplicates according to a complete order
      class SortBased
        include Operator, Operator::Cesure

        def initialize
          @cesure_key ||= AttrList.new([])
        end
          
        protected
        
        # (see Operator::Cesure#project)
        def project(tuple)
          @cesure_key.project(tuple, true)
        end
  
        # (see Operator::Cesure#accumulate_cesure)
        def accumulate_cesure(tuple, receiver)
          @tuple = tuple
        end
  
        # (see Operator::Cesure#flush_cesure)
        def flush_cesure(key, receiver)
          receiver.call(@tuple)
        end
 
      end # class SortBased
  
      # Removes duplicates by loading all in memory and filtering 
      # them there 
      class BufferBased
        include Operator, Operator::Unary
  
        protected
        
        def _prepare
          @tuples = input.to_a.uniq
        end
  
        def _each
          @tuples.each(&Proc.new)
        end
  
      end # class BufferBased
  
      protected 
      
      def longexpr
        chain BufferBased.new,
              datasets
      end
  
    end # class Compact
  end # module Operator::NonRelational
end # module Alf

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
alf-0.10.1 lib/alf/operator/non_relational/compact.rb
alf-0.10.0 lib/alf/operator/non_relational/compact.rb