MCPcopy Create free account
hub / github.com/iovisor/bcc / _alloc_keys_values

Method _alloc_keys_values

src/python/bcc/table.py:418–451  ·  view source on GitHub ↗

Allocate keys and/or values arrays. Useful for in items_*_batch. Args: alloc_k (bool): True to allocate keys array, False otherwise. Default is False. alloc_v (bool): True to allocate values array, False otherwise. Default is False.

(self, alloc_k=False, alloc_v=False, count=None)

Source from the content-addressed store, hash-verified

416 self.__delitem__(k)
417
418 def _alloc_keys_values(self, alloc_k=False, alloc_v=False, count=None):
419 """Allocate keys and/or values arrays. Useful for in items_*_batch.
420
421 Args:
422 alloc_k (bool): True to allocate keys array, False otherwise.
423 Default is False.
424 alloc_v (bool): True to allocate values array, False otherwise.
425 Default is False.
426 count (int): number of elements in the array(s) to allocate. If
427 count is None then it allocates the maximum number of elements i.e
428 self.max_entries.
429
430 Returns:
431 tuple: (count, keys, values). Where count is ct.c_uint32,
432 and keys and values an instance of ct.Array
433 Raises:
434 ValueError: If count is less than 1 or greater than
435 self.max_entries.
436 """
437 keys = values = None
438 if not alloc_k and not alloc_v:
439 return (ct.c_uint32(0), None, None)
440
441 if not count: # means alloc maximum size
442 count = self.max_entries
443 elif count < 1 or count > self.max_entries:
444 raise ValueError("Wrong count")
445
446 if alloc_k:
447 keys = (self.Key * count)()
448 if alloc_v:
449 values = (self.Leaf * count)()
450
451 return (ct.c_uint32(count), keys, values)
452
453 def _sanity_check_keys_values(self, keys=None, values=None):
454 """Check if the given keys or values have the right type and size.

Calls

no outgoing calls

Tested by

no test coverage detected