Skip to content

Instantly share code, notes, and snippets.

@imsjz
Created February 17, 2020 09:59
Show Gist options
  • Save imsjz/7339f0228e254a1018a6e1b210aaef41 to your computer and use it in GitHub Desktop.
Save imsjz/7339f0228e254a1018a6e1b210aaef41 to your computer and use it in GitHub Desktop.
#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