MCPcopy Index your code
hub / github.com/OmkarPathak/pygorithm / sum_entities

Method sum_entities

pygorithm/data_structures/quadtree.py:388–409  ·  view source on GitHub ↗

Sum the number of entities in this quad tree and all lower quad trees. If `entities_per_depth` is not None, that array is used to calculate the sum of entities rather than traversing the tree. Either way, this is implemented iteratively. See :py:meth:`.__st

(self, entities_per_depth=None)

Source from the content-addressed store, hash-verified

386 return nodes_per_depth
387
388 def sum_entities(self, entities_per_depth=None):
389 """
390 Sum the number of entities in this quad tree and all lower quad trees.
391
392 If `entities_per_depth` is not None, that array is used to calculate the sum
393 of entities rather than traversing the tree. Either way, this is implemented
394 iteratively. See :py:meth:`.__str__` for usage example.
395
396 :param entities_per_depth: the result of :py:meth:`.find_entities_per_depth`
397 :type entities_per_depth: `dict int: (int, int)` or None
398 :returns: number of entities in this and child nodes
399 :rtype: int
400 """
401 if entities_per_depth is not None:
402 return sum(entities_per_depth.values())
403
404 container = { 'result': 0 }
405 def handler(curr, container=container):
406 container['result'] += len(curr.entities)
407 self._iter_helper(handler)
408
409 return container['result']
410
411 def calculate_avg_ents_per_leaf(self):
412 """

Callers 3

__str__Method · 0.95
test_sum_entsMethod · 0.95

Calls 1

_iter_helperMethod · 0.95

Tested by 1

test_sum_entsMethod · 0.76