mavoweb / treecle

WIP. A toolbox for hierarchical JS objects.
https://treecle.mavo.io
MIT License
7 stars 0 forks source link

General `findPath` function #27

Open adamjanicki2 opened 7 months ago

adamjanicki2 commented 7 months ago

One of our use cases is a general findPath function, so I wanted to make an issue to discuss design before diving into implementing it. My thoughts are it should be a function like follows

function findPath(start, end) { ... }

which returns a path of type Array<string | number> to get from start to end. The function should attempt to use parent pointers to climb from end to start, but do a BFS/DFS if no parents are set. Before implementing this, we will need to resolve #26 because in a situation like this where parents aren't necessary but helpful, it would be nice to do a console.warn about it (see end of #26)

LeaVerou commented 7 months ago

I don't think #26 is a blocker. But if this function ends up walking, it should definitely set parent pointers as it goes!

LeaVerou commented 7 months ago

One issue is: you'd expect this function to stop once it finds the requested node. But currently, we assume that if a node has a parent pointer, its descendants also have parent pointers.

adamjanicki2 commented 7 months ago

One issue is: you'd expect this function to stop once it finds the requested node. But currently, we assume that if a node has a parent pointer, its descendants also have parent pointers.

Yeah, maybe we should wait on setting parent pointers here

LeaVerou commented 7 months ago

Not sure. When we really care we do tend to use force. Maybe we should invert force and make it be the default behavior of updateParents().

karger commented 7 months ago

I am unclear on the usage of this function so can't assess the design

On Mar 25, 2024, 8:42 PM, at 8:42 PM, Lea Verou @.***> wrote:

Not sure. When we really care we do tend to use force. Maybe we should invert force and make it be the default behavior of updateParents().

-- Reply to this email directly or view it on GitHub: https://github.com/mavoweb/treecle/issues/27#issuecomment-2019183805 You are receiving this because you are subscribed to this thread.

Message ID: @.***>