Class: Fairy::PGroupBy::DirectMergeSortBuffer::KeyValueStream

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/fairy/node/p-group-by.rb

Constant Summary collapse

EOS =
:__KEY_VALUE_STREAM_EOS__

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key, merger) ⇒ KeyValueStream

Returns a new instance of KeyValueStream.



1141
1142
1143
1144
1145
1146
# File 'lib/fairy/node/p-group-by.rb', line 1141

def initialize(key, merger)
  @key = key
  @merger = merger

  @buf = []
end

Instance Attribute Details

#keyObject (readonly)

Returns the value of attribute key.



1147
1148
1149
# File 'lib/fairy/node/p-group-by.rb', line 1147

def key
  @key
end

Instance Method Details

#concat(elements) ⇒ Object



1158
1159
1160
# File 'lib/fairy/node/p-group-by.rb', line 1158

def concat(elements)
  @buf.concat elements
end

#each(&block) ⇒ Object



1171
1172
1173
# File 'lib/fairy/node/p-group-by.rb', line 1171

def each(&block)
  @merger.each_by_key(&block)
end

#push(e) ⇒ Object Also known as: enq



1149
1150
1151
# File 'lib/fairy/node/p-group-by.rb', line 1149

def push(e)
  @buf.push e
end

#push_eosObject



1154
1155
1156
# File 'lib/fairy/node/p-group-by.rb', line 1154

def push_eos
  push EOS
end

#shiftObject Also known as: deq, pop



1162
1163
1164
1165
1166
1167
# File 'lib/fairy/node/p-group-by.rb', line 1162

def shift
  while @buf.empty?
    @merger.get_buf(self)
  end
  @buf.shift
end

#sizeObject



1175
1176
1177
1178
1179
# File 'lib/fairy/node/p-group-by.rb', line 1175

def size
  c = 0
  each{|v| c += 1}
  c
end