collections#

Helpers for various collections.

Module Contents#

Functions#

make_hash(→ int)

Make a hash from a dictionary, list, tuple or set to any level.

without(→ dict)

Copy a dictionary excluding a specific list of keys.

find_inner_dicts_containing_key(→ List[dict])

Generate a list of the first dictionaries encountered that contain a certain key.

find_all_port_clock_combinations(→ List[Tuple[str, str]])

Generate a list with all port-clock combinations found in a nested dictionary.

find_port_clock_path(→ list)

Find the path to a port-clock combination in a nested dictionary.

make_hash(obj: Any) int[source]#

Make a hash from a dictionary, list, tuple or set to any level.

From: https://stackoverflow.com/questions/5884066/hashing-a-dictionary

Parameters:

obj – Input collection.

Returns:

Hash.

without(dict_in: dict, keys: list) dict[source]#

Copy a dictionary excluding a specific list of keys.

Parameters:
  • dict_in – Input dictionary.

  • keys – List of keys to exclude.

Returns:

Filtered dictionary.

find_inner_dicts_containing_key(d: dict, key: Any) List[dict][source]#

Generate a list of the first dictionaries encountered that contain a certain key.

This is achieved by recursively traversing the nested structures until the key is found, which is then appended to a list.

Parameters:
  • d – The dictionary to traverse.

  • key – The key to search for.

Returns:

A list containing all the inner dictionaries containing the specified key.

find_all_port_clock_combinations(d: dict) List[Tuple[str, str]][source]#

Generate a list with all port-clock combinations found in a nested dictionary.

Traversing the dictionary is done using the find_inner_dicts_containing_key function.

Parameters:

d – The dictionary to traverse.

Returns:

A list containing tuples representing the port and clock combinations found in the dictionary.

find_port_clock_path(hardware_config: dict, port: str, clock: str) list[source]#

Find the path to a port-clock combination in a nested dictionary.

Parameters:
  • hardware_config – The (nested) hardware config dictionary to loop over.

  • port – The port to find.

  • clock – The clock to find.

Returns:

A list representing the keys to the port-clock combination in the hardware config. If the port-clock location is in a list, the list index is also included in this path.