Skip to content

Depth of the currently traversed element in constant time #94

Open
@mgoldenbe

Description

@mgoldenbe

Can I access the depth of the currently traversed (e.g. during the depth-first walk) element in constant time? Right now, the only way of getting the depth that I see (besides storing it with the node) is by calling getPath:

root.walk(el => {console.log(el.model.id, el.getPath().length);})

Activity

changed the title [-]Access to current depth during the walk[/-] [+]Depth of the currently traversed element[/+] on Oct 31, 2021
changed the title [-]Depth of the currently traversed element[/-] [+]Depth of the currently traversed element in constant time[/+] on Oct 31, 2021
joaonuno

joaonuno commented on Nov 1, 2021

@joaonuno
Owner

You're right, that's the only way as of now and it's not constant time as you noted. I'll leave this open because it seems a nice improvement for a future version.

coreymunn3

coreymunn3 commented on Mar 16, 2022

@coreymunn3

Wow, if it weren't for this issue I wouldn't have even know that getting depth was possible using this library, or that you even get something with a "getPath" method on it. The documentation here is painfully inadequate.

joaonuno

joaonuno commented on Mar 16, 2022

@joaonuno
Owner

Hi, getPath is documented here and there's an example on the lib's page:
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @joaonuno@mgoldenbe@coreymunn3

        Issue actions

          Depth of the currently traversed element in constant time · Issue #94 · joaonuno/tree-model-js