Skip to content

Commit 2e6fe49

Browse files
committed
Fixed bug another with getting children from a node
1 parent 7addb5f commit 2e6fe49

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

cidr_trie/__init__.py

+9-2
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ def get_values(self, prefix: str) -> List[Tuple[str, Any]]:
7272
if m > mask:
7373
continue
7474

75+
# make sure this ip is within the network defined by the mask
7576
if self.ip == (ip & get_subnet_mask(m, v6)):
7677
ip_str = f"{ip_itoa(self.ip, v6)}/{m}"
7778
result.append((ip_str, self.masks[m]))
@@ -325,7 +326,7 @@ def find_all(self, prefix: str, children: bool=False) -> List[Tuple[str, Any]]:
325326
"""
326327
self.validate_ip_type_for_trie(prefix)
327328
result = []
328-
ip, _ = cidr_atoi(prefix)
329+
ip, mask = cidr_atoi(prefix)
329330

330331
# for each node on the way down
331332
last_node = None
@@ -338,7 +339,13 @@ def find_all(self, prefix: str, children: bool=False) -> List[Tuple[str, Any]]:
338339
if children and last_node.ip == ip:
339340
# for each child node underneath the last found node
340341
for node in self.traverse_inorder_from_node(last_node):
341-
result += node.get_child_values(prefix)
342+
# skip the first node, as it's already in the result
343+
if node.ip == last_node.ip:
344+
continue
345+
346+
# make sure this child is within the prefix
347+
if (node.ip & get_subnet_mask(mask, self.v6)) == (ip & get_subnet_mask(mask, self.v6)):
348+
result += node.get_child_values(prefix)
342349

343350
return result
344351

docs/conf.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
author = 'Figglewatts'
2323

2424
# The full version, including alpha/beta/rc tags
25-
release = '3.1.1'
25+
release = '3.1.2'
2626

2727

2828
# -- General configuration ---------------------------------------------------

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ def readme():
66
return r.read()
77

88
setup(name="cidr_trie",
9-
version="3.1.1",
9+
version="3.1.2",
1010
description="Store/search CIDR prefixes in a trie structure.",
1111
long_description=readme(),
1212
long_description_content_type="text/x-rst",

0 commit comments

Comments
 (0)