fix calc_dip
This commit is contained in:
@@ -88,6 +88,13 @@ def test_find_parent__with_exception():
|
||||
|
||||
|
||||
def test_calc_dip():
|
||||
assert calc_dip(26, 26) == 0
|
||||
|
||||
assert calc_dip(26, 27) == 67108864
|
||||
assert calc_dip(27, 26) == 67108864
|
||||
|
||||
assert calc_dip(26, 28) == 201326592
|
||||
assert calc_dip(28, 26) == 201326592
|
||||
|
||||
assert calc_dip(26, 29) == 469762048
|
||||
assert calc_dip(29, 26) == 469762048
|
||||
|
||||
@@ -44,9 +44,10 @@ def find_parent(a: Node, b: Node) -> Node:
|
||||
|
||||
def calc_dip(mask_len_a: int, mask_len_b: int) -> int:
|
||||
dip = 0
|
||||
while mask_len_a < mask_len_b:
|
||||
dip += 1 << mask_len_a
|
||||
mask_len_a += 1
|
||||
len_min, len_max = sorted((mask_len_a, mask_len_b))
|
||||
while len_min < len_max:
|
||||
dip += 1 << len_min
|
||||
len_min += 1
|
||||
return dip
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user