Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace Indexes with a len: I field in the Links struct #15

Open
spencerwhite opened this issue Jul 13, 2023 · 0 comments
Open

Replace Indexes with a len: I field in the Links struct #15

spencerwhite opened this issue Jul 13, 2023 · 0 comments

Comments

@spencerwhite
Copy link

Currently Indexes acts like a lookup table between absolute positions and IDs. However, this makes modification to the tree as discussed in #13 expensive since the entire Indexes struct would have to be updated, or remade from scratch. Instead each Links could store the length of the token and functions could iteratively search the tree to find the token at that position.

Advantages

  • Links stores one usize for len instead of two for Span
  • Searching for an index goes from O(log_2 n) to O(log_a n) where a is the average number of child nodes per parent. This could be an advantage or disadvantage depending on the language's grammar.
  • Modification-in-place as discussed in Support modifying trees in-place #13 is much easier and the tree doesn't need to be rebuilt

I may be missing something obvious, but as far as I can tell all of the current API could be implemented this way. I'll prototype it later tonight and see how it goes 🤷‍♂️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant