def tokenize_file(file, delim=None):
    """Extract all delimited tokens from a given text file.

    Notes:
        * Parses on newlines and assumes last line of file ends with a newline.
        * Returns a set so that token lookups are O(1).

    Args:
        file (str): Input file.
        delim (str, None, optional): Token delimiter. If None, whitespace is
            used. Default is None.

    Returns:
        set: Tokens.
    """
    with open(file, 'rb') as fd:
        tokens = set()
        for line in fd:
            tokens.update(line.split(delim))
        return tokens