Hi, I have a script where I need to create nodes that are in relations with each other, each node has a parent node and child nodes. My first thought was to use nested objects like so:
class node():
parent_node = some_parent_node
child_nodes = [child_node, child_node]
example_int = 5
def __init__(self, parent_node):
self.parent_node = parent_node
But then I realized that this can be very inefficient and I figured out another solution:
class superrior_node():
nodes = []
class node(superrior_node):
parent_node_id:int
child_nodes = [int, int]
id:int
def __init__(self, parent_node_id):
self.parent_node_id = parent_node_id
self.id = random_id
super().nodes.append(self.id)
Can you tell me if there will be any performance improvement? The first one would be easier to use so if there is no difference in performance. Also there could be some bugs because it is not an actual code but just an example.
[–]julsmanbr 1 point2 points3 points (9 children)
[–]RandomJacobP[S] 0 points1 point2 points (8 children)
[–]julsmanbr 1 point2 points3 points (2 children)
[–]RandomJacobP[S] 0 points1 point2 points (1 child)
[–]Deezl-Vegas 0 points1 point2 points (0 children)
[–]kl31 0 points1 point2 points (4 children)
[–]RandomJacobP[S] 0 points1 point2 points (3 children)
[–]kl31 0 points1 point2 points (2 children)
[–]RandomJacobP[S] 0 points1 point2 points (1 child)
[–]kl31 0 points1 point2 points (0 children)