Skip to content

Commit 8a9447b

Browse files
authored
Format source code (indy256#150)
1 parent 6792012 commit 8a9447b

File tree

269 files changed

+2123
-2065
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

269 files changed

+2123
-2065
lines changed

.clang-format

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
BasedOnStyle: Google
3+
IndentWidth: 4
4+
ColumnLimit: 120
5+
6+
---
7+
Language: Cpp
8+
AllowShortBlocksOnASingleLine: false
9+
AllowShortIfStatementsOnASingleLine: false
10+
AllowShortLoopsOnASingleLine: false
11+
AllowShortFunctionsOnASingleLine: Inline
12+
13+
---
14+
Language: Java

.github/workflows/main.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
name: clang-format
2+
3+
on: [push]
4+
5+
jobs:
6+
check-clang-format:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/checkout@v2
10+
- name: run clang-format
11+
run: |
12+
source_files=$(find . -type f -name "*.cpp" -o -name "*.h" -o -name "*.java")
13+
diff -u <(cat $source_files) <(clang-format $source_files)

cpp/backtrack/mis.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@ using namespace std;
44
#ifdef _MSC_VER
55
int __builtin_ctzll(unsigned long long x) {
66
int bit = 0;
7-
while (bit < 64 && (x & (1LL << bit)) == 0) ++bit;
7+
while (bit < 64 && (x & (1LL << bit)) == 0)
8+
++bit;
89
return bit;
910
}
1011
int __builtin_popcountll(unsigned long long x) {
1112
int bits = 0;
12-
for (; x; x &= x - 1, ++bits);
13+
for (; x; x &= x - 1, ++bits)
14+
;
1315
return bits;
1416
}
1517
#endif

cpp/combinatorics/enumerating_combinations.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ bool next_combination(vector<int> &comb, int n) {
1818
int main() {
1919
vector<int> comb{0, 1, 2};
2020
do {
21-
for (int v : comb) cout << v + 1 << " ";
21+
for (int v : comb)
22+
cout << v + 1 << " ";
2223
cout << endl;
2324
} while (next_combination(comb, 5));
2425
}

cpp/geometry/angle_area_orientation_sort_rotation_perpendicular.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ ll double_signed_area(const vector<int> &x, const vector<int> &y) {
2121
int n = x.size();
2222
ll area = 0;
2323
for (int i = 0, j = n - 1; i < n; j = i++) {
24-
area += (ll) (x[i] - x[j]) * (y[i] + y[j]); // area += (long) x[i] * y[j] - (long) x[j] * y[i];
24+
area += (ll)(x[i] - x[j]) * (y[i] + y[j]); // area += (long) x[i] * y[j] - (long) x[j] * y[i];
2525
}
2626
return area;
2727
}
@@ -50,10 +50,12 @@ struct Point {
5050
bool operator<(const Point &o) const {
5151
bool up1 = y > 0 || (y == 0 && x >= 0);
5252
bool up2 = o.y > 0 || (o.y == 0 && o.x >= 0);
53-
if (up1 != up2) return up1;
54-
ll cmp = (ll) o.x * y - (ll) o.y * x;
55-
if (cmp != 0) return cmp < 0;
56-
return (ll) x * x + (ll) y * y < (ll) o.x * o.x + (ll) o.y * o.y;
53+
if (up1 != up2)
54+
return up1;
55+
ll cmp = (ll)o.x * y - (ll)o.y * x;
56+
if (cmp != 0)
57+
return cmp < 0;
58+
return (ll)x * x + (ll)y * y < (ll)o.x * o.x + (ll)o.y * o.y;
5759
// return atan2(y, x) < atan2(o.y, o.x);
5860
}
5961
};
@@ -71,5 +73,4 @@ Line perpendicular(Line line, ll x, ll y) {
7173
}
7274

7375
// usage example
74-
int main() {
75-
}
76+
int main() {}

cpp/geometry/convex_hull.cpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ struct point {
99
};
1010

1111
bool isNotRightTurn(const point &a, const point &b, const point &c) {
12-
long long cross = (long long) (a.x - b.x) * (c.y - b.y) - (long long) (a.y - b.y) * (c.x - b.x);
13-
long long dot = (long long) (a.x - b.x) * (c.x - b.x) + (long long) (a.y - b.y) * (c.y - b.y);
12+
long long cross = (long long)(a.x - b.x) * (c.y - b.y) - (long long)(a.y - b.y) * (c.x - b.x);
13+
long long dot = (long long)(a.x - b.x) * (c.x - b.x) + (long long)(a.y - b.y) * (c.y - b.y);
1414
return cross < 0 || (cross == 0 && dot <= 0);
1515
}
1616

@@ -30,13 +30,9 @@ vector<point> convex_hull(vector<point> points) {
3030

3131
// usage example
3232
int main() {
33-
vector<point> hull1 = convex_hull({{0, 0},
34-
{3, 0},
35-
{0, 3},
36-
{1, 1}});
33+
vector<point> hull1 = convex_hull({{0, 0}, {3, 0}, {0, 3}, {1, 1}});
3734
cout << (3 == hull1.size()) << endl;
3835

39-
vector<point> hull2 = convex_hull({{0, 0},
40-
{0, 0}});
36+
vector<point> hull2 = convex_hull({{0, 0}, {0, 0}});
4137
cout << (1 == hull2.size()) << endl;
4238
}

cpp/geometry/diameter.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,6 @@ double diameter(const vector<point> &p) {
5656

5757
// usage example
5858
int main() {
59-
double d = diameter({{0, 0},
60-
{3, 0},
61-
{0, 3},
62-
{1, 1}});
59+
double d = diameter({{0, 0}, {3, 0}, {0, 3}, {1, 1}});
6360
cout << d << endl;
6461
}

cpp/geometry/dynamic_upper_envelope.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ struct LineContainer : multiset<Line, less<>> {
2222
// (for doubles, use inf = 1/.0, div(a,b) = a/b)
2323
const ll inf = numeric_limits<ll>::max();
2424

25-
ll div(ll a, ll b) { // floored division
25+
ll div(ll a, ll b) { // floored division
2626
return a / b - ((a ^ b) < 0 && a % b);
2727
}
2828

@@ -31,15 +31,19 @@ struct LineContainer : multiset<Line, less<>> {
3131
x->p = inf;
3232
return false;
3333
}
34-
if (x->a == y->a) x->p = x->b > y->b ? inf : -inf;
35-
else x->p = div(y->b - x->b, x->a - y->a);
34+
if (x->a == y->a)
35+
x->p = x->b > y->b ? inf : -inf;
36+
else
37+
x->p = div(y->b - x->b, x->a - y->a);
3638
return x->p >= y->p;
3739
}
3840

3941
void add_line(ll a, ll b) {
4042
auto z = insert({a, b, 0}), y = z++, x = y;
41-
while (isect(y, z)) z = erase(z);
42-
if (x != begin() && isect(--x, y)) isect(x, erase(y));
43+
while (isect(y, z))
44+
z = erase(z);
45+
if (x != begin() && isect(--x, y))
46+
isect(x, erase(y));
4347
while ((y = x) != begin() && (--x)->p >= y->p)
4448
isect(x, erase(y));
4549
}

cpp/geometry/find_segments_intersection.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@ struct segment {
1818
pii a, b;
1919
int id;
2020

21-
segment(pii a, pii b, int id) :
22-
a(std::move(a)), b(std::move(b)), id(id) {
23-
}
21+
segment(pii a, pii b, int id) : a(std::move(a)), b(std::move(b)), id(id) {}
2422

2523
bool operator<(const segment &o) const {
2624
if (a.first < o.a.first) {

cpp/geometry/li_chao_tree.cpp

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@ using T = long long;
99
struct Line {
1010
T a, d;
1111

12-
T eval(T x) {
13-
return a * x + d;
14-
}
12+
T eval(T x) { return a * x + d; }
1513
};
1614

1715
struct Node {
@@ -63,17 +61,11 @@ struct LiChaoTree {
6361
T maxx;
6462
Node *root;
6563

66-
LiChaoTree(T minx, T maxx) : minx(minx), maxx(maxx) {
67-
root = new Node({0, numeric_limits<T>::max() / 2});
68-
}
64+
LiChaoTree(T minx, T maxx) : minx(minx), maxx(maxx) { root = new Node({0, numeric_limits<T>::max() / 2}); }
6965

70-
void add_line(Line line) {
71-
root->add_line(line, minx, maxx + 1);
72-
}
66+
void add_line(Line line) { root->add_line(line, minx, maxx + 1); }
7367

74-
T get_min(T x) {
75-
return root->get_min(x, minx, maxx + 1);
76-
}
68+
T get_min(T x) { return root->get_min(x, minx, maxx + 1); }
7769
};
7870

7971
// usage example

0 commit comments

Comments
 (0)