def _index_counter_keys(self, counter, unknown_token, special_tokens, max_size,<EOL>min_freq):
unknown_and_special_tokens = set(special_tokens) if special_tokens else set()<EOL>if unknown_token:<EOL><INDENT>unknown_and_special_tokens.add(unknown_token)<EOL><DEDENT>token_freqs = sorted(counter.items(), key=lambda x: x[<NUM_LIT:0>])<EOL>token_freqs.sort(key=lambda x: x[<NUM_LIT:1>], reverse=True)<EOL>token_cap = len(unknown_and_special_tokens) + (<EOL>len(counter) if not max_size else max_size)<EOL>for token, freq in token_freqs:<EOL><INDENT>if freq < min_freq or len(self._idx_to_token) == token_cap:<EOL><INDENT>break<EOL><DEDENT>if token not in unknown_and_special_tokens:<EOL><INDENT>self._idx_to_token.append(token)<EOL>self._token_to_idx[token] = len(self._idx_to_token) - <NUM_LIT:1><EOL><DEDENT><DEDENT>
Indexes keys of `counter`.


        Indexes keys of `counter` according to frequency thresholds such as `max_size` and
        `min_freq`.