I'm trying to optimize my maze generation algorithm. At the moment i have a list of sets of nodes and a list of nodes themselves. Nodes are stored as (x,y) tuples. At the beginning each set contains only one node. I pick a random border between two nodes and check if they are in the same set. Here's the problem - i have to iterate through the list of sets and look at every single item until i find the set which contains given node/nodes. I want to be able to access sets as a property of Node class, but also i want my sets to contain objects of "Node" class and i run into this:
class Node:
def __init__(self, xy:tuple, group:set):
self.xy = xy
self.group = group
node = Node((10, 10),{Node(10, 10),{Node(10, 10),{... and so on }}})
How do i create such a relation so that i can access sets as node.group and at the same time group property would point to the needed set with other Node objects without recursion?