-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTextMap.cpp
More file actions
114 lines (93 loc) · 1.72 KB
/
TextMap.cpp
File metadata and controls
114 lines (93 loc) · 1.72 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#include <map>
#include <windows.h>
using namespace std;
class CStringComparator
{
public:
/*
A < B --> true
*/
bool operator()(const char* A, const char* B) const
{
while (true)
{
if (A[0] == B[0])
{
//A = B
if (!A[0])
return false;
A++;
B++;
}
else
{
return A[0] < B[0];
}
}
}
};
template <class T>
class CMyAllocator
{
public:
typedef typename T value_type;
CMyAllocator()
{
}
template <class U>
CMyAllocator(const CMyAllocator<U> &V)
{
}
T* allocate(size_t Count)
{
//printf("Allocate %d\n", (int)(Count * sizeof(T)));
return (T*)malloc(sizeof(T) * Count);
}
void deallocate(T* V, size_t Count)
{
//printf("Free %d\n", (int)(Count * sizeof(T)));
free(V);
}
};
void TextMapTest()
{
map<char*, size_t, CStringComparator, CMyAllocator<char*>> Map;
char Words[][5] = { "Who", "Are", "You", "Who" };
char* Word;
for (size_t i = 0; i < sizeof(Words) / sizeof(Words[0]); i++)
{
Word = Words[i];
auto It = Map.find(Word);
if (It == Map.end())
{
Map.insert(make_pair(Word, 1));
}
else
{
It->second++;
}
}
for (auto Entry : Map)
{
printf("Word %s, count %I64d\n", Entry.first, (uint64_t)Entry.second);
}
}
ULONGLONG GetCurrentTimeMs()
{
SYSTEMTIME S = { 0 };
FILETIME F = { 0 };
GetSystemTime(&S);
SystemTimeToFileTime(&S, &F);
LARGE_INTEGER Int;
Int.HighPart = F.dwHighDateTime;
Int.LowPart = F.dwLowDateTime;
return Int.QuadPart / 10000;
}
void main()
{
ULONGLONG Start = GetCurrentTimeMs();
TextMapTest();
ULONGLONG End = GetCurrentTimeMs();
printf("Time (ms) %d\n", (int)(End - Start));
//getchar();
}