forked from rui314/chibicc
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhashmap.cpp
More file actions
33 lines (30 loc) · 863 Bytes
/
Copy pathhashmap.cpp
File metadata and controls
33 lines (30 loc) · 863 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// This is rewrite of API for unordered_map
#include "opencc.h"
void *hashmap_get(HashMap& map, const std::string& key) {
auto it = map.find(key);
if(it!=map.end()) {
return it->second;
}
return nullptr;
}
void *hashmap_get2(HashMap& map, const std::string& key, int keylen) {
std::string k = key.substr(0, keylen);
return hashmap_get(map, k);
}
void hashmap_put(HashMap& map, const std::string& key, void *val) {
map[key] = val;
}
void hashmap_put2(HashMap& map, const std::string& key, int keylen, void *val) {
map[key.substr(0, keylen)] = val;
}
void hashmap_delete(HashMap& map, const std::string& key) {
auto it = map.find(key);
if(it!=map.end()) map.erase(it);
}
void hashmap_delete2(HashMap& map, const std::string& key, int keylen) {
hashmap_delete(map, key.substr(0, keylen));
}
// dummy
void hashmap_test(void) {
return;
}