def get_uniq_atoms(atom: Atom) -> set[Atom]: """Return the set of all unique atoms in atom.""" result = {atom} # Recursive cases if atom.is_link(): for o in atom.out: result.update(get_uniq_atoms(o)) return result # Base cases (atom is a node) return result
def is_empty_link(atom: Atom) -> bool: """Return True iff the atom is a link with empty outgoing set.""" return atom.is_link() and atom.out == []