Skip to content

[lca] doubling#202

Merged
ia7ck merged 3 commits intomasterfrom
lca-doubling
Feb 8, 2026
Merged

[lca] doubling#202
ia7ck merged 3 commits intomasterfrom
lca-doubling

Conversation

@ia7ck
Copy link
Owner

@ia7ck ia7ck commented Feb 7, 2026

No description provided.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR refactors the lowest_common_ancestor library to use the shared doubling crate for binary lifting, replacing its bespoke ancestor table implementation.

Changes:

  • Replace ancestor table in LowestCommonAncestor with Doubling<()>-based transitions.
  • Add doubling as a dependency of the lowest_common_ancestor crate.
  • Add a Value trait implementation for () in the doubling crate to support value-less transitions.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
libs/lowest_common_ancestor/src/lib.rs Replaces manual binary-lifting table with Doubling<()> and sentinel state logic.
libs/lowest_common_ancestor/Cargo.toml Adds the local doubling crate as a dependency.
libs/doubling/src/lib.rs Implements Value for () to allow Doubling<()> usage.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 59 to 67
let sentinel = n;
let doubling = Doubling::new(n + 1, n, |i| {
if i < n {
let next = parent[i].unwrap_or(sentinel);
Transition::new(next, ())
} else {
Transition::new(sentinel, ())
}
});
Copy link

Copilot AI Feb 7, 2026

Choose a reason for hiding this comment

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

Doubling::new is instantiated with max_steps = n, but the maximum number of upward steps needed in an n-node tree is n-1 (max depth). With max_steps = n, Doubling builds one extra level when n is a power of two (since log2_max_steps = floor(log2(n))), increasing memory/time for large n while never being queried. Consider using max_steps = n.saturating_sub(1).max(1) (or depth.iter().max() if you want the exact bound) to avoid the extra table row while keeping the n == 1 case valid.

Copilot uses AI. Check for mistakes.
}

impl Value for () {
fn op(&self, _other: &Self) -> Self {}
Copy link

Copilot AI Feb 7, 2026

Choose a reason for hiding this comment

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

The Value for () implementation relies on an empty block to return unit. This compiles, but it’s easy to misread as an unfinished implementation and can be flagged by style/lint tooling. Prefer returning () explicitly (and you can also omit the unused self name by using _ if desired) to make the intent clear.

Suggested change
fn op(&self, _other: &Self) -> Self {}
fn op(&self, _other: &Self) -> Self {
()
}

Copilot uses AI. Check for mistakes.
@ia7ck ia7ck enabled auto-merge February 8, 2026 11:13
@ia7ck ia7ck disabled auto-merge February 8, 2026 11:13
@ia7ck ia7ck enabled auto-merge February 8, 2026 11:16
@ia7ck ia7ck merged commit a348463 into master Feb 8, 2026
6 checks passed
@ia7ck ia7ck deleted the lca-doubling branch February 8, 2026 11:17
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.

1 participant

Comments