Skip to content

Commit 294d2ef

Browse files
committed
Apply clang-format to DoubleHashingSort - expand single-line if statements
1 parent 0116943 commit 294d2ef

File tree

1 file changed

+63
-21
lines changed

1 file changed

+63
-21
lines changed

src/main/java/com/thealgorithms/sorts/DoubleHashingSort.java

Lines changed: 63 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -76,37 +76,73 @@ public int compare(T a, T b) {
7676

7777
private int compareDoubles(Double a, Double b) {
7878
// Handle NaN: NaN should come last
79-
if (Double.isNaN(a) && Double.isNaN(b)) { return 0; }
80-
if (Double.isNaN(a)) { return 1; }
81-
if (Double.isNaN(b)) { return -1; }
79+
if (Double.isNaN(a) && Double.isNaN(b)) {
80+
return 0;
81+
}
82+
if (Double.isNaN(a)) {
83+
return 1;
84+
}
85+
if (Double.isNaN(b)) {
86+
return -1;
87+
}
8288

8389
// Handle infinities
84-
if (a.equals(Double.NEGATIVE_INFINITY) && b.equals(Double.NEGATIVE_INFINITY)) { return 0; }
85-
if (a.equals(Double.NEGATIVE_INFINITY)) { return -1; }
86-
if (b.equals(Double.NEGATIVE_INFINITY)) { return 1; }
90+
if (a.equals(Double.NEGATIVE_INFINITY) && b.equals(Double.NEGATIVE_INFINITY)) {
91+
return 0;
92+
}
93+
if (a.equals(Double.NEGATIVE_INFINITY)) {
94+
return -1;
95+
}
96+
if (b.equals(Double.NEGATIVE_INFINITY)) {
97+
return 1;
98+
}
8799

88-
if (a.equals(Double.POSITIVE_INFINITY) && b.equals(Double.POSITIVE_INFINITY)) { return 0; }
89-
if (a.equals(Double.POSITIVE_INFINITY)) { return 1; }
90-
if (b.equals(Double.POSITIVE_INFINITY)) { return -1; }
100+
if (a.equals(Double.POSITIVE_INFINITY) && b.equals(Double.POSITIVE_INFINITY)) {
101+
return 0;
102+
}
103+
if (a.equals(Double.POSITIVE_INFINITY)) {
104+
return 1;
105+
}
106+
if (b.equals(Double.POSITIVE_INFINITY)) {
107+
return -1;
108+
}
91109

92110
// Normal comparison
93111
return Double.compare(a, b);
94112
}
95113

96114
private int compareFloats(Float a, Float b) {
97115
// Handle NaN: NaN should come last
98-
if (Float.isNaN(a) && Float.isNaN(b)) { return 0; }
99-
if (Float.isNaN(a)) { return 1; }
100-
if (Float.isNaN(b)) { return -1; }
116+
if (Float.isNaN(a) && Float.isNaN(b)) {
117+
return 0;
118+
}
119+
if (Float.isNaN(a)) {
120+
return 1;
121+
}
122+
if (Float.isNaN(b)) {
123+
return -1;
124+
}
101125

102126
// Handle infinities
103-
if (a.equals(Float.NEGATIVE_INFINITY) && b.equals(Float.NEGATIVE_INFINITY)) { return 0; }
104-
if (a.equals(Float.NEGATIVE_INFINITY)) { return -1; }
105-
if (b.equals(Float.NEGATIVE_INFINITY)) { return 1; }
127+
if (a.equals(Float.NEGATIVE_INFINITY) && b.equals(Float.NEGATIVE_INFINITY)) {
128+
return 0;
129+
}
130+
if (a.equals(Float.NEGATIVE_INFINITY)) {
131+
return -1;
132+
}
133+
if (b.equals(Float.NEGATIVE_INFINITY)) {
134+
return 1;
135+
}
106136

107-
if (a.equals(Float.POSITIVE_INFINITY) && b.equals(Float.POSITIVE_INFINITY)) { return 0; }
108-
if (a.equals(Float.POSITIVE_INFINITY)) { return 1; }
109-
if (b.equals(Float.POSITIVE_INFINITY)) { return -1; }
137+
if (a.equals(Float.POSITIVE_INFINITY) && b.equals(Float.POSITIVE_INFINITY)) {
138+
return 0;
139+
}
140+
if (a.equals(Float.POSITIVE_INFINITY)) {
141+
return 1;
142+
}
143+
if (b.equals(Float.POSITIVE_INFINITY)) {
144+
return -1;
145+
}
110146

111147
// Normal comparison
112148
return Float.compare(a, b);
@@ -121,9 +157,15 @@ private int compareNumbers(Number a, Number b) {
121157

122158
private int compareStrings(String a, String b) {
123159
// Handle empty strings properly - they should come before non-empty strings
124-
if (a.isEmpty() && b.isEmpty()) { return 0; }
125-
if (a.isEmpty()) { return -1; }
126-
if (b.isEmpty()) { return 1; }
160+
if (a.isEmpty() && b.isEmpty()) {
161+
return 0;
162+
}
163+
if (a.isEmpty()) {
164+
return -1;
165+
}
166+
if (b.isEmpty()) {
167+
return 1;
168+
}
127169

128170
// Normal string comparison
129171
return a.compareTo(b);

0 commit comments

Comments
 (0)