Class: Alf::Engine::Sort::InMemory

Inherits:
Object
  • Object
show all
Includes:
Cog, Alf::Engine::Sort
Defined in:
lib/alf/engine/sort/in_memory.rb

Overview

Implement an in-memory sort, relying on `to_a.sort!`

Example:

rel = [
  {:name => "Smith"},
  {:name => "Jones"}
]
Sort.new(rel, Ordering[[:name, :asc]]).to_a
# => [
#      {:name => "Jones"}
#      {:name => "Smith"},
#    ]

Constant Summary

Constants included from Cog

Cog::EMPTY_CHILDREN, Cog::EMPTY_OPTIONS

Instance Attribute Summary collapse

Attributes included from Compiler::Cog

#compiler, #expr

Instance Method Summary collapse

Methods included from Cog

#children, #each, #options, #to_s

Methods included from Compiler::Cog

#orderedby?, #relation_type, #to_ascii_tree, #to_cog, #to_relation

Methods included from Alf::Engine::Sort

new

Constructor Details

#initialize(operand, ordering, expr = nil, compiler = nil) ⇒ InMemory

Creates an Autonum instance


29
30
31
32
33
# File 'lib/alf/engine/sort/in_memory.rb', line 29

def initialize(operand, ordering, expr = nil, compiler = nil)
  super(expr, compiler)
  @operand = operand
  @ordering = ordering
end

Instance Attribute Details

#operandEnumerable (readonly)


23
24
25
# File 'lib/alf/engine/sort/in_memory.rb', line 23

def operand
  @operand
end

#orderingOrdering (readonly)


26
27
28
# File 'lib/alf/engine/sort/in_memory.rb', line 26

def ordering
  @ordering
end

Instance Method Details

#_each(&block) ⇒ Object


41
42
43
# File 'lib/alf/engine/sort/in_memory.rb', line 41

def _each(&block)
  operand.to_a.sort!(&ordering.sorter).each(&block)
end

#argumentsObject


45
46
47
# File 'lib/alf/engine/sort/in_memory.rb', line 45

def arguments
  [ ordering ]
end

#cog_ordersObject


36
37
38
# File 'lib/alf/engine/sort/in_memory.rb', line 36

def cog_orders
  @cog_orders ||= [ ordering ]
end