Class: Fairy::PGroupBy::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, generator) ⇒ KeyValueStream

Returns a new instance of KeyValueStream.



126
127
128
129
# File 'lib/fairy/node/p-group-by.rb', line 126

def initialize(key, generator)
	@key = key
	@buf = []
end

Instance Attribute Details

#keyObject (readonly)

Returns the value of attribute key.



131
132
133
# File 'lib/fairy/node/p-group-by.rb', line 131

def key
  @key
end

Instance Method Details

#concat(elements) ⇒ Object



142
143
144
# File 'lib/fairy/node/p-group-by.rb', line 142

def concat(elements)
	@buf.concat elements
end

#each(&block) ⇒ Object



155
156
157
158
159
# File 'lib/fairy/node/p-group-by.rb', line 155

def each(&block)
	while (v = shift) != EOS
	  block.call v
	end
end

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



133
134
135
# File 'lib/fairy/node/p-group-by.rb', line 133

def push(e)
	@buf.push e
end

#push_eosObject



138
139
140
# File 'lib/fairy/node/p-group-by.rb', line 138

def push_eos
	push EOS
end

#shiftObject Also known as: deq, pop



146
147
148
149
150
151
# File 'lib/fairy/node/p-group-by.rb', line 146

def shift
	while @buf.empty?
	  Fiber.yield
	end
	@buf.shift
end

#sizeObject



161
162
163
164
165
# File 'lib/fairy/node/p-group-by.rb', line 161

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