Class: RbBCC::ArrayTable

Inherits:
TableBase show all
Defined in:
lib/rbbcc/table.rb

Instance Attribute Summary

Attributes inherited from TableBase

#bpf, #flags, #keysize, #leafsize, #leaftype, #map_fd, #map_id, #name, #ttype

Instance Method Summary collapse

Methods inherited from TableBase

#[], #[]=, #clear, #each_key, #each_pair, #each_value, #fetch, #items, #next, #print_linear_hist, #print_log2_hist, #structured_key?, #values

Methods included from CPUHelper

_read_cpu_range, get_online_cpus, get_possible_cpus

Constructor Details

#initialize(bpf, map_id, map_fd, keytype, leaftype, name: nil) ⇒ ArrayTable



213
214
215
216
# File 'lib/rbbcc/table.rb', line 213

def initialize(bpf, map_id, map_fd, keytype, leaftype, name: nil)
  super
  @max_entries = Clib.bpf_table_max_entries_id(bpf.module, map_id)
end

Instance Method Details

#clearitem(key) ⇒ Object



224
225
226
# File 'lib/rbbcc/table.rb', line 224

def clearitem(key)
  self[key] = byref(0, @leafsize)
end

#delete(key) ⇒ Object



228
229
230
231
# File 'lib/rbbcc/table.rb', line 228

def delete(key)
  # Delete in Array type does not have an effect, so zero out instead
  clearitem(key)
end

#each(&b) ⇒ Object



233
234
235
236
237
# File 'lib/rbbcc/table.rb', line 233

def each(&b)
  each_value do |v|
    b.call(v.to_bcc_value)
  end
end

#sizeObject Also known as: length

We now emulate the Array class of Ruby



219
220
221
# File 'lib/rbbcc/table.rb', line 219

def size
  @max_entries
end