Adds a new node to the tree. If the conn_type is the same as the root's current connector type, the node is added to the first level. Otherwise, the whole tree is pushed down one level and a new root connector is created, connecting the existing tree and the new node
(self, node, conn_type)
| 317 | return other in self.children |
| 318 | |
| 319 | def add(self, node, conn_type): |
| 320 | """ |
| 321 | Adds a new node to the tree. If the conn_type is the same as the root's |
| 322 | current connector type, the node is added to the first level. |
| 323 | Otherwise, the whole tree is pushed down one level and a new root |
| 324 | connector is created, connecting the existing tree and the new node. |
| 325 | """ |
| 326 | if node in self.children and conn_type == self.connector: |
| 327 | return |
| 328 | if len(self.children) < 2: |
| 329 | self.connector = conn_type |
| 330 | if self.connector == conn_type: |
| 331 | if isinstance(node, SearchNode) and ( |
| 332 | node.connector == conn_type or len(node) == 1 |
| 333 | ): |
| 334 | self.children.extend(node.children) |
| 335 | else: |
| 336 | self.children.append(node) |
| 337 | else: |
| 338 | obj = self._new_instance(self.children, self.connector, self.negated) |
| 339 | self.connector = conn_type |
| 340 | self.children = [obj, node] |
| 341 | |
| 342 | def negate(self): |
| 343 | """ |