schola.core.utils.IdManager
- class schola.core.utils.IdManager(ids)[source]
-
Bases:
object
A class to manage the mapping between nested and flattened ids.
- Parameters:
-
ids (List[List[int]]) – A nested list of lists of ids to manage, index in the list is first id, second id is stored in the second list.
- ids
-
The nested list of lists of ids to manage.
- Type:
-
List[List[int]]
Methods
__init__
(ids)flatten_id_dict
(nested_id_dict[, default])Flatten a dictionary of nested ids into a list of values.
get_flattened_id
(first_id, second_id)Get the flattened id from a nested id.
get_nested_id
(flat_id)Get the nested id from a flattened id.
nest_id_list
(id_list[, default])Nest a list of values, indexed by flattened id, into a dictionary of nested ids.
partial_get
(first_id)Get the second ids for a given first id.
Attributes
List of nested ids, for lookups from flattened id to nested ids.
List of dictionaries mapping nested ids to flattened ids.
The number of ids managed by the IdManager.
- flatten_id_dict(nested_id_dict, default=None)[source]
-
Flatten a dictionary of nested ids into a list of values.
- get_flattened_id(first_id, second_id)[source]
-
Get the flattened id from a nested id.
- get_nested_id(flat_id)[source]
-
Get the nested id from a flattened id.
- property id_list: List[Tuple[int, int]]
-
List of nested ids, for lookups from flattened id to nested ids.
- nest_id_list(id_list, default=None)[source]
-
Nest a list of values, indexed by flattened id, into a dictionary of nested ids.
- Parameters:
-
-
id_list (List[T]) – The list of values to convert into a nested dictionary.
-
default (Optional[T], optional) – The default value to use if a key is not found, by default None.
-
- Returns:
-
A nested dictionary of the values in id_list or default if values are missing.
- Return type:
- property num_ids: int
-
The number of ids managed by the IdManager.
- Returns:
-
The number of ids.
- Return type: