Class: ZKSync::InodeTable
- Inherits:
-
Object
- Object
- ZKSync::InodeTable
- Defined in:
- lib/zksync/inode_table.rb
Instance Attribute Summary collapse
-
#inode_width ⇒ Object
readonly
Returns the value of attribute inode_width.
Instance Method Summary collapse
- #add_inode(inode) ⇒ Object
- #delete_inode(index) ⇒ Object
- #find_free(size) ⇒ Object
- #free_at_n?(n) ⇒ Boolean
-
#initialize(inode_width) ⇒ InodeTable
constructor
A new instance of InodeTable.
- #to_s ⇒ Object
Constructor Details
#initialize(inode_width) ⇒ InodeTable
Returns a new instance of InodeTable.
22 23 24 25 |
# File 'lib/zksync/inode_table.rb', line 22 def initialize(inode_width) @inode_width = inode_width @table = [] end |
Instance Attribute Details
#inode_width ⇒ Object (readonly)
Returns the value of attribute inode_width.
20 21 22 |
# File 'lib/zksync/inode_table.rb', line 20 def inode_width @inode_width end |
Instance Method Details
#add_inode(inode) ⇒ Object
27 28 29 30 31 32 |
# 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) ⇒ Object
34 35 36 37 38 39 40 41 |
# 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) ⇒ Object
43 44 45 46 47 48 49 |
# 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) ⇒ Boolean
51 52 53 54 |
# 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 ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# 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 |