blob: 079637de2314fc7526cd8fd96479ccf9d195efbf (
plain) (
blame)
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#pragma once
#include <map>
#include <cstddef>
template<typename _key, typename _val>
class simplemap
{
public:
explicit simplemap() : _map() {}
explicit simplemap(simplemap& m)
{
_map = m.map();
}
virtual ~simplemap() {}
_val insert(_key key, _val val)
{
typename std::pair<typename std::map<_key,_val>::iterator, bool> p =
_map.insert(std::make_pair(key, val));
if (p.second) return p.first->second;
return NULL;
}
_val find(_key key)
{
typename std::map<_key,_val>::iterator it = _map.find(key);
if (it != _map.end())
return it->second;
else
return NULL;
}
size_t size() { return _map.size(); }
typename std::map<_key,_val>::iterator begin() { return _map.begin(); }
typename std::map<_key,_val>::iterator end() { return _map.end(); }
void delete_second()
{
typename std::map<_key,_val>::iterator it(_map.begin());
for (;it != _map.end(); ++it)
{
delete(it->second);
it->second = NULL;
}
}
void clear()
{
_map.clear();
}
protected:
std::map<_key,_val>& map() { return _map; }
private:
std::map<_key,_val> _map;
};
|