From ee0d61facd7cc8e39516a9919494b57e85687fe4 Mon Sep 17 00:00:00 2001 From: Mukundan314 Date: Sun, 13 Oct 2024 20:26:29 +0530 Subject: [PATCH] Properly handle empty sequences in ordersort --- pyrival/misc/ordersort.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pyrival/misc/ordersort.py b/pyrival/misc/ordersort.py index be736cf8..e8b259fb 100644 --- a/pyrival/misc/ordersort.py +++ b/pyrival/misc/ordersort.py @@ -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): @@ -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])