Skip to content

Commit

Permalink
Properly handle empty sequences in ordersort
Browse files Browse the repository at this point in the history
  • Loading branch information
Mukundan314 committed Oct 13, 2024
1 parent 4a73595 commit ee0d61f
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions pyrival/misc/ordersort.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
def bucketsort(order, seq):
buckets = [0] * (max(seq) + 1)
buckets = [0] * (max(seq, default=0) + 1)
for x in seq:
buckets[x] += 1
for i in range(len(buckets) - 1):
Expand All @@ -15,7 +15,7 @@ def bucketsort(order, seq):


def ordersort(order, seq, reverse=False):
bit = max(seq).bit_length() >> 1
bit = max(seq, default=0).bit_length() >> 1
mask = (1 << bit) - 1
order = bucketsort(order, [x & mask for x in seq])
order = bucketsort(order, [x >> bit for x in seq])
Expand Down

0 comments on commit ee0d61f

Please sign in to comment.