class FlatKit::LeafNode

Private: The LeafNode is a wrapper around a Reader object to enable a consistent api for use in the MergeTree

The LeafNode keeps track of the head of the reader list and when its value is used up, it pulls the next value and then notifies the next level of the MergeTree that its value has changed and so should do another play.

If all the data is used up from the reader, it also notifies the next level of that so the next level can remove it from the tree.

Attributes

next_level[RW]
reader[R]
value[R]

Public Class Methods

new(reader) click to toggle source
# File lib/flat_kit/leaf_node.rb, line 20
def initialize(reader)
  @reader     = reader
  @enum       = @reader.to_enum
  @value      = @enum.next

  @next_level = nil
end

Public Instance Methods

<=>(other) click to toggle source
# File lib/flat_kit/leaf_node.rb, line 66
def <=>(other)
  return -1 if other.sentinel?
  self.value.<=>(other.value)
end
finished?() click to toggle source
# File lib/flat_kit/leaf_node.rb, line 62
def finished?
  @enum && @value.nil?
end
leaf() click to toggle source
# File lib/flat_kit/leaf_node.rb, line 40
def leaf
  self
end
leaf?() click to toggle source
# File lib/flat_kit/leaf_node.rb, line 36
def leaf?
  true
end
next() click to toggle source
# File lib/flat_kit/leaf_node.rb, line 53
def next
  begin
    @value = @enum.next
  rescue StopIteration
    @value = nil
  end
  @value
end
sentinel?() click to toggle source
# File lib/flat_kit/leaf_node.rb, line 32
def sentinel?
  false
end
update_and_replay() click to toggle source
# File lib/flat_kit/leaf_node.rb, line 44
def update_and_replay
  self.next
  if finished? then
    ::FlatKit.logger.debug "#{reader.source} has finished reading #{reader.count} records"
    next_level.player_finished(self)
  end
  next_level.play
end
winner() click to toggle source
# File lib/flat_kit/leaf_node.rb, line 28
def winner
  value
end