Skip to content

Conversation

@senekor
Copy link
Contributor

@senekor senekor commented Sep 9, 2025

Co-authored-by: devcyjung [email protected]

senekor and others added 7 commits September 9, 2025 18:17
rustc has actually gotten smart enough to not warn about unused
variables with the type `PhantomData`. Pretty cool!
This would unnecessarily prime students to use a vector internally.
@senekor senekor force-pushed the senekor/vowxmpvryksw branch from dc007fc to d189ccb Compare September 9, 2025 16:43
Avoiding unnecessary allocations is important to the design of Rust.
In order to ensure students do not cheat, we add a test with a custom,
non-Clone type so their implementation fails to compile if they add the
Clone bound.

* TODO: add custom test with non-Clone item type to prevent cheating

* TODO: add myself to authors in pov/.meta/config.json
@senekor senekor force-pushed the senekor/vowxmpvryksw branch from ddc6473 to be808c6 Compare September 9, 2025 16:52
@senekor
Copy link
Contributor Author

senekor commented Sep 9, 2025

supersedes #2077

I already had a lot of back-and-forth with the original author. I guess they tapped out at some point 🙁 I pinged them after a month and still haven't heard back a second month later.

I think this is a pretty cool exercise and unique on the track. No other exercise deals with mutating trees. So I want to get it over the finish line. I made sure to keep the original author in .meta/config.json. Once we squash-merge, the PR description will become the commit message, so the Co-authored-by trailer will attribute the commit to them as well.

I did change quite a bit of stuff though. The API design was geared towards immutability before, I changed that to allow an implementation without unnecessary allocations. I think the mutable API is not only important because of performance, but also because cloning everything kinda takes away the challenge unique to Rust in this case. That would be a missed opportunity for special learning moments in my opinion.

@senekor senekor marked this pull request as ready for review September 9, 2025 16:54
@senekor senekor requested a review from ellnix September 9, 2025 16:55
@senekor senekor mentioned this pull request Sep 9, 2025
Copy link
Contributor

@ellnix ellnix left a comment

Choose a reason for hiding this comment

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

Unfortunately I don't think I have enough knowledge of rust to solve this mutably. I couldn't think of a way to implement the tree swapping that the borrow checker approved of. Looking at example.rs it looks like I had to mem::swap which I haven't done in ages, if ever, so I can't say I reached for it.

I agree that it would be much less interesting if you could clone everything. In it's current state this is a very short exercise that requires you to know the borrow checker well and know some graph theory. I think this would be one of the best exercises on the track.

I only have some minor feedback:

  • path_to could maybe be renamed to path_between
  • path_to only presents a challenge of implementing a tree search algorithm, which pov_from also requires you to implement
    • as a twist, it might make sense to make path_to immutable to prevent the student from reusing pov_from and having them implement a tree search for two nodes from the root and returning the path between them

I'll approve this so that you have the discretion to disagree with those points and merge 😄

@senekor
Copy link
Contributor Author

senekor commented Sep 9, 2025

path_to could maybe be renamed to path_between

That's a great point. The name comes from problem-specifications, so I didn't question it. But we can just rename it. path_between makes much more sense.

path_to only presents a challenge of implementing a tree search algorithm, which pov_from also requires you to implement

as a twist, it might make sense to make path_to immutable to prevent the student from reusing pov_from and having them implement a tree search for two nodes from the root and returning the path between them

Also a great thought. I think in this case it's kind of a feature that path_to is easy to implement, based on pov_from. The point is basically to show to the user: "Look how easy it is to find a path, now that we can reparent the tree!"

So, I think I'll leave that part as-is.

@senekor
Copy link
Contributor Author

senekor commented Sep 9, 2025

Thanks for the review!

@senekor senekor merged commit 64b1a0d into main Sep 9, 2025
10 checks passed
@senekor senekor deleted the senekor/vowxmpvryksw branch September 9, 2025 19:23
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.

3 participants