Untitled
unknown
python
a year ago
711 B
3
Indexable
Never
def getUnexpiredTokens(time_to_live, queries): tokens = {} for query in queries: query_type = query[0] if query_type == "generate": token_id = query[1] current_time = int(query[2]) tokens[token_id] = (current_time + time_to_live, current_time) elif query_type == "renew": token_id = query[1] current_time = int(query[2]) if token_id in tokens and tokens[token_id][0] > current_time: tokens[token_id] = (current_time + time_to_live, current_time) elif query_type == "count": current_time = int(query[1]) count = 0 for token_id in tokens: if tokens[token_id][0] > current_time: count += 1 yield count