-
Notifications
You must be signed in to change notification settings - Fork 0
/
RadixTree.h
56 lines (46 loc) · 954 Bytes
/
RadixTree.h
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
//
// RadixTree.h
// CS32_4
//
// Created by Snigdha Kansal on 3/4/22.
//
#ifndef RadixTree_h
#define RadixTree_h
#include <map>
#include <string>
using namespace std;
template <typename ValueType>
class RadixTree
{
public:
RadixTree();
~RadixTree();
void insert(string key, const ValueType &value);
ValueType *search(string key) const;
private:
map<string, ValueType> m_map;
};
template <typename ValueType>
RadixTree<ValueType>::RadixTree()
{
}
template <typename ValueType>
RadixTree<ValueType>::~RadixTree()
{
}
template <typename ValueType>
void RadixTree<ValueType>::insert(string key, const ValueType &value)
{
m_map.insert_or_assign(key, value);
}
template <typename ValueType>
ValueType *RadixTree<ValueType>::search(string key) const
{
auto it = m_map.find(key);
if (it == m_map.end())
{
return nullptr;
}
return const_cast<ValueType *>(&(it->second));
}
#endif /* RadixTree_h */