def group_index(self, tid: int) -> Set[int]: r"""Look up the group_index with key `tid`. If the index is not built, this will raise a ``PackIndexError``. """ if not self._group_index_switch: raise PackIndexError('Group index for pack not build') return self._group_index[tid]
def update_group_index(self, groups: List[GroupType]): """Build or update :attr:`group_index`, the index from group members to groups. Args: groups (list): a list of groups to be added into the index. """ logger.debug("Updating group index") if not self._group_index: raise PackIndexError("Group index has not been built.") for group in groups: for member in group.members: self._group_index[member].add(group.tid)
def link_index(self, tid: int, as_parent: bool = True) -> Set[int]: r"""Look up the link_index with key ``tid``. If the link index is not built, this will throw a ``PackIndexError``. Args: tid (int): the tid of the entry being looked up. as_parent (bool): If `as_patent` is True, will look up :attr:`link_index["parent_index"] and return the tids of links whose parent is `tid`. Otherwise, will look up :attr:`link_index["child_index"] and return the tids of links whose child is `tid`. """ if not self._link_index_switch: raise PackIndexError('Link index for pack not build') if as_parent: return self._link_index["parent_index"][tid] else: return self._link_index["child_index"][tid]
def update_link_index(self, links: List[LinkType]): """ Update :attr:`link_index` with the provided links, the index from child and parent to links. :attr:`link_index` consists of two sub-indexes: "child_index" is the index from child nodes to their corresponding links, and "parent_index" is the index from parent nodes to their corresponding links. Args: links (list): a list of links to be added into the index. """ logger.debug("Updating link index.") if not self._link_index: raise PackIndexError("Link index has not been built.") for link in links: self._link_index["child_index"][link.get_child().index_key].add( link.tid) self._link_index["parent_index"][link.get_parent().index_key].add( link.tid)