File: stream_executor.rb

package info (click to toggle)
groonga 15.0.4%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 163,080 kB
  • sloc: ansic: 770,564; cpp: 48,925; ruby: 40,447; javascript: 10,250; yacc: 7,045; sh: 5,602; python: 2,821; makefile: 1,672
file content (45 lines) | stat: -rw-r--r-- 1,442 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
module Groonga
  module Sharding
    class StreamExecutor
      def initialize(context, shard_executor_class)
        @context = context
        @shard_executor_class = shard_executor_class
      end

      private
      def each_shard_executor(&block)
        enumerator = @context.enumerator
        target_range = enumerator.target_range
        if @context.order == :descending
          each_method = :reverse_each
        else
          each_method = :each
        end
        if @context.need_look_ahead?
          previous_executor = nil
          enumerator.send(each_method) do |shard, shard_range|
            @context.push
            current_executor = @shard_executor_class.new(@context, shard, shard_range)
            if previous_executor
              previous_executor.next_executor = current_executor
              current_executor.previous_executor = previous_executor
              yield(previous_executor)
              @context.shift unless previous_executor.shard.first?
            end
            if shard.last?
              yield(current_executor)
              @context.shift
            end
            previous_executor = current_executor
          end
        else
          enumerator.send(each_method) do |shard, shard_range|
            @context.push
            yield(@shard_executor_class.new(@context, shard, shard_range))
            @context.shift
          end
        end
      end
    end
  end
end