Skip to content

Commit e24aef5

Browse files
committed
Refactor comments and formatting in power_sort.py for improved readability. Adjusted whitespace and line breaks in function definitions and comments to enhance clarity without altering functionality.
1 parent 7690063 commit e24aef5

1 file changed

Lines changed: 14 additions & 9 deletions

File tree

sorts/power_sort.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,8 @@ def _node_power(total_length: int, b1: int, n1: int, b2: int, n2: int) -> int:
113113
>>> _node_power(100, 0, 50, 50, 50)
114114
1
115115
"""
116-
# Calculate midpoints: a = (b1 + n1/2) / total_length, b = (b2 + n2/2) / total_length
116+
# Calculate midpoints: a = (b1 + n1/2) / total_length,
117+
# b = (b2 + n2/2) / total_length
117118
# To avoid floating point, we work with a = (2*b1 + n1) / (2*total_length) and
118119
# b = (2*b2 + n2) / (2*total_length)
119120
# We want smallest p where floor(a * 2^p) != floor(b * 2^p)
@@ -273,13 +274,13 @@ def power_sort(
273274
def reverse_key(element: Any) -> Any:
274275
"""
275276
Reverse key function for numeric values.
276-
277+
277278
Args:
278279
element: The element to process
279-
280+
280281
Returns:
281282
Negated value for numeric types, original value otherwise
282-
283+
283284
>>> reverse_key(5)
284285
-5
285286
>>> reverse_key('hello')
@@ -297,13 +298,13 @@ def reverse_key(element: Any) -> Any:
297298
def reverse_cmp(element: Any) -> Any:
298299
"""
299300
Reverse comparison function for numeric values.
300-
301+
301302
Args:
302303
element: The element to process
303-
304+
304305
Returns:
305306
Negated value for numeric types, original value otherwise
306-
307+
307308
>>> reverse_cmp(10)
308309
-10
309310
>>> reverse_cmp('test')
@@ -330,7 +331,9 @@ def reverse_cmp(element: Any) -> Any:
330331
power = 0
331332
else:
332333
prev_start, prev_length, _ = stack[-1]
333-
power = _node_power(total_length, prev_start, prev_length, start, run_length)
334+
power = _node_power(
335+
total_length, prev_start, prev_length, start, run_length
336+
)
334337

335338
# Merge runs from stack based on power comparison
336339
while len(stack) > 0 and stack[-1][2] >= power:
@@ -367,7 +370,9 @@ def reverse_cmp(element: Any) -> Any:
367370
else:
368371
prev_start, prev_length, _ = stack[-1]
369372
merged_length = start2 + length2 - start1
370-
power = _node_power(total_length, prev_start, prev_length, start1, merged_length)
373+
power = _node_power(
374+
total_length, prev_start, prev_length, start1, merged_length
375+
)
371376

372377
stack.append((start1, start2 + length2 - start1, power))
373378

0 commit comments

Comments
 (0)