class ZKSync::InodeTable
Attributes
inode_width[R]
Public Class Methods
new(inode_width)
click to toggle source
# File lib/zksync/inode_table.rb, line 22 def initialize(inode_width) @inode_width = inode_width @table = [] end
Public Instance Methods
add_inode(inode)
click to toggle source
# File lib/zksync/inode_table.rb, line 27 def add_inode(inode) num_slots_needed = inode.slots_used n = find_free(num_slots_needed) num_slots_needed.times { |i| @table[n+i] = i == 0 ? inode : :placeholder } inode.index = n end
delete_inode(index)
click to toggle source
# File lib/zksync/inode_table.rb, line 34 def delete_inode(index) return unless inode = @table[index] while index < @table.length && [:placeholder, inode].include?(@table[i]) do @table[i] = nil index += 1 end end
find_free(size)
click to toggle source
# File lib/zksync/inode_table.rb, line 43 def find_free(size) (0..@table.length-size).to_a.each do |n| return n if free_at_n?(n) end @table.length end
free_at_n?(n)
click to toggle source
# File lib/zksync/inode_table.rb, line 51 def free_at_n?(n) (0..n).to_a.each { |m| return false unless @table[m].nil? } true end
to_s()
click to toggle source
# File lib/zksync/inode_table.rb, line 56 def to_s # TODO: redo writing of InodeTable with a stream, so we don't have to have the whole serialized table in memory @table.map do |entry| case entry when nil " "*inode_width when :placeholder "" else text = entry.to_s text.to_s + " "*(inode_width - (text.length%inode_width)) unless text.length > 0 && text.length % inode_width == 0 end end.join("") end