-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbmap.h
More file actions
83 lines (80 loc) · 2.21 KB
/
Copy pathbmap.h
File metadata and controls
83 lines (80 loc) · 2.21 KB
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#ifndef __DATA_STRUCT_BMAP_H__
#define __DATA_STRUCT_BMAP_H__
#include <map>
namespace ds
{
class bmap_t : public std::map<size_t, size_t>
{
public:
bmap_t()
{
}
~bmap_t()
{
}
void print()
{
printf("[(%s:%s:%d) ++++]\n", __FILE__, __PRETTY_FUNCTION__, __LINE__);
printf("[size(%zu)]\n", std::map<size_t, size_t>::size());
std::map<size_t, size_t>::iterator iter = std::map<size_t, size_t>::begin(), end = std::map<size_t, size_t>::end();
for(; iter != end; ++ iter)
{
printf("[(%zu:%zu)]\n", (*iter).first, (*iter).second);
}
if(0 != std::map<size_t, size_t>::size())
{
printf("\n");
}
printf("[(%s:%s:%d) ----]\n", __FILE__, __PRETTY_FUNCTION__, __LINE__);
}
template<typename T>
bool read(T& t)
{
uint16_t c = 0;
if(!t.read(c))
{
return false;
}
for(size_t x = 0; x < c; ++ x)
{
uint32_t k = 0;
if(!t.read(k))
{
return false;
}
uint32_t v = 0;
if(!t.read(v))
{
return false;
}
insert(std::make_pair<size_t, size_t>(k, v));
}
return true;
}
template<typename T>
bool write(T& t)
{
uint16_t c = std::map<size_t, size_t>::size();
if(!t.write(c))
{
return false;
}
typename std::map<size_t, size_t>::iterator iter = std::map<size_t, size_t>::begin(), end = std::map<size_t, size_t>::end();
for(; iter != end; ++ iter)
{
uint32_t k = (*iter).first;
if(!t.write(k))
{
return false;
}
uint32_t v = (*iter).second;
if(!t.write(v))
{
return false;
}
}
return true;
}
};
}
#endif