'Is there a tree-like structure where nodes can appear multiple times and even be ancestors of themselves?
I'm crawling some web pages, recursively getting all the existing links, and I would like to preserve in some kind of structure the history of links I've had to visit to get to each link. This means it's possible to find the same link multiple times in the process.
I already store the links in a Set
to make sure I don't visit the same link more than once, but probably this is not the right kind of structure to keep the history
Solution 1:[1]
As commented by John Bollinger
Any way around, the generalization you're looking for is a graph, presumably a directed one to match the directed nature of hyperlinks. You might need to augment that with, say, an index.
That's what I was looking for at the time of the question. It's not what I used in the end, though. Turns out keeping all the links, info and references can be quite heavy on the memory
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | DSantiagoBC |