Created
February 17, 2020 09:59
-
-
Save imsjz/7339f0228e254a1018a6e1b210aaef41 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <string> | |
namespace sanjay{ | |
// 写一个简易版哈希表类 | |
class MyHashTable { | |
public: | |
std::string operator[](const std::string& key) const { | |
if(key == key_) { | |
return value_; | |
} | |
// 假设 这里查找没有key_的存在 | |
key_ = key; | |
value_ = "1"; | |
return value_; | |
} | |
private: | |
mutable std::string key_{}; | |
mutable std::string value_{}; | |
}; | |
void test() { | |
MyHashTable demo; | |
std::cout << demo["coo"] << std::endl; | |
} | |
} | |
int main() { | |
sanjay::test(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment