The Swift Programming Language shows a brief example of a recursive tree structure
enum Tree<T> {
case empty
indirect case node(value: T, left: Tree, right: Tree)
}
When and why might it be a better fit to structure data as an enum with indirection instead of a class, and vice-versa?
2 Likes
I did a quick & small project to compare:
Found out that (with large data sets) enum is significantly slower due to being value type, compared to classes.
Please let me know if you find places for improvements.