classAuthenticationManager { int timeToLive; unordered_map<string, int> expiredTime; public: AuthenticationManager(int _timeToLive) : timeToLive(_timeToLive) { } voidgenerate(string tokenId, int currentTime){ expiredTime[tokenId] = currentTime + timeToLive; } voidrenew(string tokenId, int currentTime){ auto it = expiredTime.find(tokenId); if (it != expiredTime.end() && it->second > currentTime) { generate(tokenId, currentTime); } } intcountUnexpiredTokens(int currentTime){ int ans = 0; for (constauto& p : expiredTime) { if (p.second > currentTime) { ++ans; } } return ans; } };
/** * Your AuthenticationManager object will be instantiated and called as such: * AuthenticationManager* obj = new AuthenticationManager(timeToLive); * obj->generate(tokenId,currentTime); * obj->renew(tokenId,currentTime); * int param_3 = obj->countUnexpiredTokens(currentTime); */