-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.cpp
103 lines (72 loc) · 1.67 KB
/
main.cpp
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
#include "gtest/gtest.h"
#include <stack>
#include <unordered_map>
using namespace std;
class stack_test : public ::testing::Test {
protected:
std::stack<int> teststack;
protected:
virtual void TearDown() {
}
virtual void SetUp() {
teststack.push(1);
teststack.push(2);
}
};
TEST_F(stack_test, demo) {
ASSERT_EQ(teststack.top(), 2);
}
int add(int a, int b) {
return a + b;
}
TEST(add, zero) {
EXPECT_EQ(0, add(0, 0)) << "yes";
}
TEST(add, positive_number) {
EXPECT_EQ(3, add(1, 2));
}
TEST(add, negative_number) {
EXPECT_EQ(-3, add(-1, -2));
}
struct Index2 {
int x, y;
explicit Index2(int x = 0, int y = 0) : x(x), y(y) {}
};
struct Index2Hash {
size_t operator()(const Index2 &index) const {
// hash<int>()(...) 仿函数?
return hash<int>()(index.x) ^ hash<int>()(index.y);
}
};
struct Index2Com {
bool operator()(const Index2 &index1, const Index2 &index2) const {
return index1.x == index2.x && index1.y == index2.y;
}
};
class SparseMatrix {
private:
unordered_map<Index2, int, Index2Hash, Index2Com> map;
int count;
public:
SparseMatrix() : count(0) {}
int at(int x, int y) {
if (map.count(Index2(x, y)) <= 0) {
return 0;
} else {
return map[Index2(x, y)];
}
}
void insert(int x, int y, int e) {
// map[Index2(x,y)] = e;
map.emplace(Index2(x,y), e);
}
};
int main() {
// int a = 5,b = 1;
// std::cout << (b=a) << std::endl;
// std::stack<int> s;
// std::cout << s.top() << std::endl;
// ::testing::InitGoogleTest();
// return RUN_ALL_TESTS();
return 0;
}