From 3197fa1663a4e099475afde662f5effbf7c7e58e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Geoffrey=20=E2=80=9CFrogeye=E2=80=9D=20Preud=27homme?= Date: Mon, 16 Dec 2019 06:54:18 +0100 Subject: [PATCH] Remove list usage for IpTreeNode --- database.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/database.py b/database.py index 5522013..99ea3ad 100644 --- a/database.py +++ b/database.py @@ -88,7 +88,8 @@ class DomainTreeNode(): class IpTreeNode(): def __init__(self) -> None: - self.children: typing.List[typing.Optional[IpTreeNode]] = [None, None] + self.zero: typing.Optional[IpTreeNode] = None + self.one: typing.Optional[IpTreeNode] = None self.match = Match() @@ -131,7 +132,7 @@ class Profiler(): class Database(Profiler): - VERSION = 10 + VERSION = 11 PATH = "blocking.p" def initialize(self) -> None: @@ -258,7 +259,7 @@ class Database(Profiler): callback(_par, _dic, arg) # 0 - dic = _dic.children[0] + dic = _dic.zero if dic: addr0 = _par.value & (0xFFFFFFFF ^ (1 << (32-_par.prefixlen))) assert addr0 == _par.value @@ -269,7 +270,7 @@ class Database(Profiler): _par=Ip4Path(addr0, _par.prefixlen+1) ) # 1 - dic = _dic.children[1] + dic = _dic.one if dic: addr1 = _par.value | (1 << (32-_par.prefixlen)) yield from self.exec_each_ip4( @@ -351,7 +352,7 @@ class Database(Profiler): self.enter_step('get_ip4_yield') yield Ip4Path(ip4.value, 32-i) self.enter_step('get_ip4_brws') - next_dic = dic.children[part] + next_dic = dic.one if part else dic.zero if next_dic is None: return dic = next_dic @@ -432,10 +433,13 @@ class Database(Profiler): if dic.match.active(): # Refuse to add ip4* whose network is already matching return - next_dic = dic.children[part] + next_dic = dic.one if part else dic.zero if next_dic is None: next_dic = IpTreeNode() - dic.children[part] = next_dic + if part: + dic.one = next_dic + else: + dic.zero = next_dic dic = next_dic dic.match.set( updated,