haleyhousellc / arboriculture

A simple tree library written in TypeScript.
https://haleyhousellc.github.io/arboriculture
ISC License
2 stars 0 forks source link

Reconsider iterative vs recursive trees #15

Closed haleyga closed 6 years ago

haleyga commented 6 years ago

Initially, all tree operations are implemented iteratively to reduce memory footprints in the browser. However, ES6 has proper tail-call optimization (finally). Therefore, it might improve code readability to reimplement the iterative approach in a more natural recursive style (trees and their operations are naturally recursive).

haleyga commented 6 years ago

Recursive implementations should reduce the code base, be easier to read and maintain, and should express the tree structure more naturally. Now that ES6 allows for compiler optimizations, this seems like a no-brainer.

I suppose in-browser usage may still experience memory performance issues when using extremely large trees. Perhaps a hybrid approach allowing the user to specifically select an iterative approach is the best compromise?

haleyga commented 6 years ago

This issue will also resolve #7 with recursive traversals only. Should iterative traversals be needed in the future, a new issue will be opened to address that use-case.