-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into hvanz/votekeeper-sum-types
- Loading branch information
Showing
10 changed files
with
449 additions
and
183 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ mod driver; | |
mod error; | ||
mod input; | ||
mod output; | ||
mod proposals; | ||
mod proposer; | ||
mod util; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
use alloc::collections::BTreeMap; | ||
use alloc::vec::Vec; | ||
|
||
use malachite_common::ValueId; | ||
use malachite_common::{Context, Proposal, Value}; | ||
|
||
/// Stores proposals at each round, indexed by their value id. | ||
pub struct Proposals<Ctx> | ||
where | ||
Ctx: Context, | ||
{ | ||
pub(crate) proposals: BTreeMap<ValueId<Ctx>, Vec<Ctx::Proposal>>, | ||
} | ||
|
||
impl<Ctx> Proposals<Ctx> | ||
where | ||
Ctx: Context, | ||
{ | ||
pub fn new() -> Self { | ||
Self { | ||
proposals: BTreeMap::new(), | ||
} | ||
} | ||
|
||
pub fn insert(&mut self, proposal: Ctx::Proposal) { | ||
let value_id = proposal.value().id(); | ||
self.proposals.entry(value_id).or_default().push(proposal); | ||
} | ||
|
||
pub fn find( | ||
&self, | ||
value_id: &ValueId<Ctx>, | ||
p: impl Fn(&Ctx::Proposal) -> bool, | ||
) -> Option<&Ctx::Proposal> { | ||
self.proposals | ||
.get(value_id) | ||
.and_then(|proposals| proposals.iter().find(|proposal| p(proposal))) | ||
} | ||
} | ||
|
||
impl<Ctx> Default for Proposals<Ctx> | ||
where | ||
Ctx: Context, | ||
{ | ||
fn default() -> Self { | ||
Self::new() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.