shnitsel.data.tree.child_support_functions#

Functions#

find_child_key(existing_child_keys, new_child[, ...])

Helper function to find a new collision free key for a new child node

get_data_name_candidate(data[, name_candidate])

Helper function to extract name candidates from arbitrary data

Module Contents#

find_child_key(existing_child_keys, new_child, default_prefix='child')#

Helper function to find a new collision free key for a new child node given the existing set of keys and the new node

Will first attempt to extract a name candidate from the node and then try to resolve potential name collisions by appending suffixes.

Parameters:
  • existing_child_keys (Iterable[Hashable]) – Set of existing keys in use for existing children.

  • new_child (TreeNode) – The new node for which we want to find a key.

  • default_prefix (str, optional) – A default prefix to use if we cannot extract a name candidate, by default “child”

Returns:

A derived key that does not have any collisions in existing_child_keys and incorporates information from new_child if possible.

Return type:

str

Raises:

OverflowError – If no unused child name has been found after 1000 attempts.

get_data_name_candidate(data, name_candidate=None)#

Helper function to extract name candidates from arbitrary data that could be stored in a Tree leave.

Parameters:
  • data (Any) – The arbitrary data for which we want to derive a name

  • name_candidate (str | None, optional) – A potentially already existing name candidate that may be used, by default None

Returns:

A name based on the data or None if no name could be derived.

Return type:

str | None