Cidr4 merge algorithm #5

Merged
PavelPatsey merged 91 commits from CIDR4_merge_algorithm into main 2025-01-27 22:05:39 +03:00
2 changed files with 11 additions and 3 deletions
Showing only changes of commit adc569af21 - Show all commits
+7
View File
@@ -88,6 +88,13 @@ def test_find_parent__with_exception():
def test_calc_dip(): def test_calc_dip():
assert calc_dip(26, 26) == 0
assert calc_dip(26, 27) == 67108864 assert calc_dip(26, 27) == 67108864
assert calc_dip(27, 26) == 67108864
assert calc_dip(26, 28) == 201326592 assert calc_dip(26, 28) == 201326592
assert calc_dip(28, 26) == 201326592
assert calc_dip(26, 29) == 469762048 assert calc_dip(26, 29) == 469762048
assert calc_dip(29, 26) == 469762048
+4 -3
View File
@@ -44,9 +44,10 @@ def find_parent(a: Node, b: Node) -> Node:
def calc_dip(mask_len_a: int, mask_len_b: int) -> int: def calc_dip(mask_len_a: int, mask_len_b: int) -> int:
dip = 0 dip = 0
while mask_len_a < mask_len_b: len_min, len_max = sorted((mask_len_a, mask_len_b))
dip += 1 << mask_len_a while len_min < len_max:
mask_len_a += 1 dip += 1 << len_min
len_min += 1
return dip return dip