Skip to content

Commit

Permalink
Merge pull request #3 from theStack/simplify_tree_rows
Browse files Browse the repository at this point in the history
simplify `tree_rows` helper by only counting bits
  • Loading branch information
kcalvinalvin authored Oct 28, 2022
2 parents 29227ac + 8446862 commit 072c6ed
Showing 1 changed file with 1 addition and 6 deletions.
7 changes: 1 addition & 6 deletions pytreexo.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import copy
import math
import hashlib


Expand Down Expand Up @@ -82,12 +81,8 @@ def parent(pos: int, total_rows: int) -> int:
return (pos >> 1) | (1 << total_rows)


def next_power_of_2(x: int) -> int:
return 1 if x == 0 else 2**(x - 1).bit_length()


def tree_rows(n: int) -> int:
return int(math.log2(next_power_of_2(n)))
return 0 if n == 0 else (n - 1).bit_length()


def row_maxpos(row: int, total_row: int) -> int:
Expand Down

0 comments on commit 072c6ed

Please sign in to comment.