Fill before you walk
transcript
A chat workspace has channels. Channels link to each other. You must copy them all. Cycles must not trap you. Here is the rule in one line.
Keep a map from channel to its copy. The same map is the visited set. Fill it when you first reach a channel.
Copies are numbered from the number of channels. Each channel gets the next number when it is first reached. So the walk order sets the numbers.
Channel zero is copied first. It gets four. Its links get five and six. Channel three gets seven. A link back finds an entry. The walk stops.
Write the entry after the walk, and a cycle never ends. Write it before, and a link back finds it.
Shared channels are never copied. The walk never goes through them. Copies link to the original.
Decide what the map stores. Fill it on first reach. A link back reuses it. Full breakdown in the lecture.