class SuffixTreeDB

Public Class Methods

new(textFile) click to toggle source
# File lib/persist/suffix_tree_db.rb, line 4
def initialize(textFile)
  @textFile = File.open(textFile, "w")
  @dataValues = []
  @dataValueIdx = 0
end

Public Instance Methods

persist(node) click to toggle source
# File lib/persist/suffix_tree_db.rb, line 18
def persist(node)
  @textFile.print "#{node.nodeId} #{val(node.parent)} #{node.incomingEdgeStartOffset} #{node.incomingEdgeEndOffset} #{node.suffixOffset} #{val(node.suffixLink)}"
  if (node.children != nil) then
    node.children.values.each do |childNode|
      @textFile.print " #{childNode.nodeId}"
    end
  end
  @textFile.print " 0\n"
end
readInt() click to toggle source
# File lib/persist/suffix_tree_db.rb, line 28
def readInt()
  if (@dataValueIdx >= @dataValues.length) then
    if (@textFile.eof?) then
      return 0
    end
    line = @textFile.readline()
    if (line == nil) then
      return 0
    else
      line.chomp!
      @dataValueIdx = 0
      @dataValues = line.split
    end
  end

  result = @dataValues[@dataValueIdx].to_i
  @dataValueIdx += 1
  return result
end
val(node) click to toggle source
# File lib/persist/suffix_tree_db.rb, line 10
def val(node)
  if (node == nil) then
    return 0
  else
    return node.nodeId
  end
end