def extract_subset_from_monolithic_flags_as_dict_from_stream(
        monolithic_trie, stream):
    """Extract a subset of flags from the trie of monolithic flags.

    :param monolithic_trie: the trie containing all the monolithic flags.
    :param stream: a stream containing a list of signature patterns that define
    the subset.
    :return: the dict from signature to row.
    """
    dict_signature_to_row = {}
    for pattern in stream:
        pattern = pattern.rstrip()
        rows = monolithic_trie.get_matching_rows(pattern)
        for row in rows:
            signature = row["signature"]
            dict_signature_to_row[signature] = row
    return dict_signature_to_row