-
Notifications
You must be signed in to change notification settings - Fork 258
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
feat(linked chunk): add a way to reconstruct a linked chunk from its raw representation #4318
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #4318 +/- ##
=======================================
Coverage 85.05% 85.05%
=======================================
Files 275 276 +1
Lines 30301 30376 +75
=======================================
+ Hits 25772 25836 +64
- Misses 4529 4540 +11 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, I've left a lot of comments but (!) I like the strategy you've taken: I think it's a valid one!
I am hesitant to ask the modify the build()
method to run 2 phases:
- check data consistency,
- build the actual
LinkedChunk
I suppose you've merged the 2 phases in a single one for performance reason, but it makes it a bit more complex to understand. Not a big deal though. I wonder if it has any performance impact in reality, as we may not build huge LinkedChunk
, vs. having super clear and easy-to-understand code.
1215b8b
to
0504265
Compare
Alright, please take another look. I'm not super satisfied with the splitting of the building into two parts (you'll see that some checks are redundant, with some branches that can't be hit, because of this), but this is likely semi-temporary code anyways. The one thing I'm tempted to do is to get rid of all the error types and keep a single one "MalformedList", because the detail of what the error is only matters for the testing purposes… |
0504265
to
e8bfd38
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we are good!
let mut first_id = None; | ||
|
||
for (id, chunk) in self.chunks.iter() { | ||
if chunk.previous.is_none() { | ||
// This chunk is a good candidate to be the first chunk. | ||
first_id = Some(*id); | ||
break; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpicking: This could have been a nice candidate for a:
let mut first_id = None; | |
for (id, chunk) in self.chunks.iter() { | |
if chunk.previous.is_none() { | |
// This chunk is a good candidate to be the first chunk. | |
first_id = Some(*id); | |
break; | |
} | |
} | |
let first_id = self.chunks.iter().find_map(|(id, chunk)| chunk.previous.is_none().then_some(*id)); |
} | ||
} | ||
|
||
// There's no first chunk, but we've checked that `self.chunks` isn't empty: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// There's no first chunk, but we've checked that `self.chunks` isn't empty: | |
// There's no first chunk, but we've checked that `self.chunks` isn't empty in `Self::build`: |
// If there are more chunks than those we've visited: some of them were not | ||
// linked to the "main" branch of the linked list, so we had multiple connected | ||
// components. | ||
if visited.len() != self.chunks.len() { | ||
return Err(LinkedChunkBuilderError::MultipleConnectedComponents); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
e8bfd38
to
6e48c07
Compare
What it says on the tin. Extracted from #4308, with extra testing and better error handling.
In particular, we must be careful that the passed set of chunks form a linked list, and not a looser kind of a graph.
Two things I'm not very sure about:
self.chunks
while constructing, ensureself.chunks
is empty after iterating), but an explicit pass might be more straightforward and clearer in its intent.Ends::last
is always set? It's not clear to me why it should be optional, since its users will either take it, or takefirst
when it's not set.Part of #3280.