Skip to content

Commit f2139ab

Browse files
authored
Merge pull request #17 from jkramarz/separators
refactored converting alphabet chars into separators in constructor
2 parents ff1e1ac + cb7d7a1 commit f2139ab

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

hashids.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -199,14 +199,12 @@ def __init__(self, salt='', min_length=0, alphabet=ALPHABET):
199199
separators = _reorder(separators, salt)
200200

201201
min_separators = _index_from_ratio(len_alphabet, RATIO_SEPARATORS)
202-
if not separators or len_separators < min_separators:
203-
if min_separators == 1:
204-
min_separators = 2
205-
if min_separators > len_separators:
206-
split_at = min_separators - len_separators
207-
separators += alphabet[:split_at]
208-
alphabet = alphabet[split_at:]
209-
len_alphabet = len(alphabet)
202+
203+
number_of_missing_separators = min_separators - len_separators
204+
if number_of_missing_separators > 0:
205+
separators += alphabet[:number_of_missing_separators]
206+
alphabet = alphabet[number_of_missing_separators:]
207+
len_alphabet = len(alphabet)
210208

211209
alphabet = _reorder(alphabet, salt)
212210
num_guards = _index_from_ratio(len_alphabet, RATIO_GUARDS)

0 commit comments

Comments
 (0)