Skip to content

Commit

Permalink
Update paths.py
Browse files Browse the repository at this point in the history
  • Loading branch information
baseplate-admin committed Feb 23, 2024
1 parent 6db26c5 commit a1c858e
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions django_ltree/paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,26 +32,27 @@ def __next__(self):

next = __next__

def guess_the_label_size(self, path_size: int, combination_size: int) -> int:
@staticmethod
def guess_the_label_size(path_size: int, combination_size: int):
if path_size == 0:
return 1

# The theoritical limit for this at the time of writing is 2_538_557_185_841_324_496 (python 3.12.2)
calculated_path_size = 0
calculated_path_size = +0
# The theoritical limit for this at the time of writing is 32 (python 3.12.2)
label_size = 0

# THIS IS AN VERY IMPORTANT CHECK
last = 0

while True:
while calculated_path_size < path_size:
possible_cominations = math.comb(combination_size, label_size)

if last > possible_cominations:
raise ValueError("We approached the limit of `math.comb`")

last = possible_cominations
calculated_path_size += possible_cominations

if calculated_path_size > path_size and label_size != 0:
break

label_size += 1

return label_size

0 comments on commit a1c858e

Please sign in to comment.