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

Add ZeroTrie probe function for stepwise iteration. #4725

Merged
merged 2 commits into from
Mar 26, 2024

Conversation

sffc
Copy link
Member

@sffc sffc commented Mar 23, 2024

probe is to iter as step is to get.

I created this in order to be more clever in how we canonicalize IANA names for #4031.

Happy to entertain other naming suggestions.

@sffc sffc requested a review from a team as a code owner March 23, 2024 02:03
///
/// assert_eq!(&results, data);
/// ```
pub fn probe(&mut self, index: usize) -> Option<u8> {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thought: We could also return the number of children in order to avoid re-checking the same node an extra time.

/// Probes the next byte in the cursor, stepping the cursor and returning the byte.
///
/// This function is similar to [`Self::step()`], but it takes an index instead of a char.
/// This enables stepwise iteration over the contents of the trie.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think I understand what this means

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you suggest wording that explains it better? This was my attempt at explaining it clearly+succinctly

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't suggest wording because I don't understand what this means :)

I'm looking at step and still not understanding how these relate. I suspect wording it less dependently on step will help, and you can mention the correlation after that.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reworded the first paragraph of the doc string. Does that help explain the second paragraph?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there is only one child node, step and probe have the same behavior. If there are multiple children, probe can walk them by their index, whereas step binary searches to find the desired child.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah this works

@sffc sffc merged commit 9622fb1 into unicode-org:main Mar 26, 2024
30 checks passed
@sffc sffc deleted the zt-probe-clean branch March 26, 2024 02:45
sffc added a commit that referenced this pull request Mar 29, 2024
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

Successfully merging this pull request may close these issues.

2 participants