Skip to content

Small refactorings in apportionment seat assignment#3336

Open
NikoWil wants to merge 18 commits into
kiesraad:mainfrom
NikoWil:refactoring
Open

Small refactorings in apportionment seat assignment#3336
NikoWil wants to merge 18 commits into
kiesraad:mainfrom
NikoWil:refactoring

Conversation

@NikoWil

@NikoWil NikoWil commented May 21, 2026

Copy link
Copy Markdown

I did some small refactorings in the code base.
The only interface change was to save an allocation by returning an Iterator over a Vec. All tests (as performed by 'cargo test') are still green, so I'm reasonably sure the changes are fine :)

NikoWil added 16 commits May 21, 2026 17:09
…d_lists. Makes the whole function body less indented.
The only thing assign_remainder did with the slice was cloning it into a vec. Now the information that assign_remainder needs to own the memory is part of the signature.
All callers do not need the Vecs themselves right now, so just handing in ownership is no problem.
All the function did was clone the slice into a vector, and all callers no longer need ownership of the value (or passed in an empty slice which can be replaced with an empty Vec without needing allocation either)
…modifies the element that is folded over.

Specifically, the fold was not depending on the previous value but just extending the Vec.
This may enable further refactorings where we can remove the collecting into a container.
…pty:

* the for loop just becomes an empty loop
* seats_to_reassign is zero, so  assign_remainder is called with the same number for total_residual_seats and current_residual_seat_number, resulting in another noop.
The overall function result remains the same.
There should exist exactly one ListStanding with number list_number, so the inner loop always operates on the same element (for each iteration of the outer loop).
I.e., full_seat is false until that element's residual_seats is exhausted and then is always false.
@NikoWil NikoWil requested a review from a team as a code owner May 21, 2026 15:11
@codecov

codecov Bot commented May 21, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.60%. Comparing base (dad991b) to head (6857a0c).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3336      +/-   ##
==========================================
- Coverage   90.60%   90.60%   -0.01%     
==========================================
  Files         476      476              
  Lines       22694    22680      -14     
  Branches     2390     2386       -4     
==========================================
- Hits        20563    20550      -13     
  Misses       2009     2009              
+ Partials      122      121       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Lionqueen94 Lionqueen94 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for this awesome refactor and the explanatory commits as well. I have just 2 comments 👍

Comment thread backend/pdf_gen/src/embedded/world.rs Outdated
Comment thread backend/apportionment/src/seat_assignment/residual_seat_assignment.rs Outdated
NikoWil and others added 2 commits May 22, 2026 20:35
@Lionqueen94 Lionqueen94 requested a review from a team May 22, 2026 21:19
@Lionqueen94 Lionqueen94 requested a review from a team May 22, 2026 21:33
@Lionqueen94

Copy link
Copy Markdown
Contributor

@NikoWil I'm afraid there's something we forgot: our repositories require signed commits. Would you be able to sign your commits?

list_votes: &[T],
assigned_residual_seats: u32,
previous_steps: Vec<SeatChangeStep<T::ListNumber>>,
mut current_steps: Vec<SeatChangeStep<T::ListNumber>>,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

iirc we explicitly chose to use immutable arguments, @stacktraceghost @rnijveld @Lionqueen94 do you remember?

@NikoWil

NikoWil commented May 31, 2026

Copy link
Copy Markdown
Author

@Lionqueen94 , of course I can sign the commits :)
Should I use GPG or is SSH also okay with you?

@stacktraceghost

Copy link
Copy Markdown
Contributor

@Lionqueen94 , of course I can sign the commits :) Should I use GPG or is SSH also okay with you?

Both are fine!

@praseodym praseodym changed the title Refactoring - RustWeek 2026 Hackathon Small refactorings in apportionment seat assignment Jun 9, 2026
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.

4 participants