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.



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

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

Instance Attribute Details

#keyObject (readonly)

Returns the value of attribute key.



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

def key
  @key
end

Instance Method Details

#concat(elements) ⇒ Object



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

def concat(elements)
	@buf.concat elements
end

#each(&block) ⇒ Object



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

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

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



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

def push(e)
	@buf.push e
end

#push_eosObject



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

def push_eos
	push EOS
end

#shiftObject Also known as: deq, pop



152
153
154
155
156
157
# File 'lib/fairy/node/p-group-by.rb', line 152

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

#sizeObject



167
168
169
170
171
# File 'lib/fairy/node/p-group-by.rb', line 167

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