Class: RbBCC::ArrayTable

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

Instance Attribute Summary

Attributes inherited from TableBase

#bpf, #flags, #keysize, #keytype, #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

Returns a new instance of ArrayTable.



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

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



246
247
248
# File 'lib/rbbcc/table.rb', line 246

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

#delete(key) ⇒ Object



250
251
252
253
# File 'lib/rbbcc/table.rb', line 250

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

#each(&b) ⇒ Object



255
256
257
258
259
# File 'lib/rbbcc/table.rb', line 255

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



241
242
243
# File 'lib/rbbcc/table.rb', line 241

def size
  @max_entries
end