Skip to content

Commit

Permalink
Use map().max() instead of fold_commutative()
Browse files Browse the repository at this point in the history
  • Loading branch information
davidchuyaya committed Jan 9, 2025
1 parent 3787c0d commit 651801e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 19 deletions.
17 changes: 3 additions & 14 deletions hydro_test/src/cluster/paxos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -483,20 +483,9 @@ fn recommit_after_leader_election<'a, P: PaxosPayload>(
Stream<P2a<P>, Tick<Cluster<'a, Proposer>>, Bounded, NoOrder>,
Optional<usize, Tick<Cluster<'a, Proposer>>, Bounded>,
) {
let p_p1b_max_checkpoint = accepted_logs.clone().fold_commutative(
q!(|| None),
q!(|curr_max, (checkpoint, _log)| {
if let Some(checkpoint) = checkpoint {
if let Some(curr_max_val) = *curr_max {
if checkpoint > curr_max_val {
*curr_max = Some(checkpoint);
}
} else {
*curr_max = Some(checkpoint);
}
}
}),
);
let p_p1b_max_checkpoint = accepted_logs.clone()
.map(q!(|(checkpoint, _log)| checkpoint))
.max();
let p_p1b_highest_entries_and_count = accepted_logs
.map(q!(|(_checkpoint, log)| log))
.flatten_unordered() // Convert HashMap log back to stream
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -788,11 +788,13 @@ expression: built.ir()
},
),
Tee {
inner: <tee 27>: Fold {
init: stageleft :: runtime_support :: fn0_type_hint :: < core :: option :: Option < usize > > ({ use crate :: __staged :: cluster :: paxos :: * ; | | None }),
acc: stageleft :: runtime_support :: fn2_borrow_mut_type_hint :: < core :: option :: Option < usize > , (core :: option :: Option < usize > , std :: collections :: hash_map :: HashMap < usize , hydro_test :: cluster :: paxos :: LogValue < hydro_test :: cluster :: paxos_kv :: KvPayload < u32 , (hydro_lang :: location :: cluster :: cluster_id :: ClusterId < hydro_test :: cluster :: paxos_bench :: Client > , u32) > > >) , () > ({ use crate :: __staged :: cluster :: paxos :: * ; | curr_max , (checkpoint , _log) | { if let Some (checkpoint) = checkpoint { if let Some (curr_max_val) = * curr_max { if checkpoint > curr_max_val { * curr_max = Some (checkpoint) ; } } else { * curr_max = Some (checkpoint) ; } } } }),
input: Tee {
inner: <tee 20>,
inner: <tee 27>: Reduce {
f: stageleft :: runtime_support :: fn2_borrow_mut_type_hint :: < core :: option :: Option < usize > , core :: option :: Option < usize > , () > ({ use hydro_lang :: __staged :: stream :: * ; | curr , new | { if new > * curr { * curr = new ; } } }),
input: Map {
f: stageleft :: runtime_support :: fn1_type_hint :: < (core :: option :: Option < usize > , std :: collections :: hash_map :: HashMap < usize , hydro_test :: cluster :: paxos :: LogValue < hydro_test :: cluster :: paxos_kv :: KvPayload < u32 , (hydro_lang :: location :: cluster :: cluster_id :: ClusterId < hydro_test :: cluster :: paxos_bench :: Client > , u32) > > >) , core :: option :: Option < usize > > ({ use crate :: __staged :: cluster :: paxos :: * ; | (checkpoint , _log) | checkpoint }),
input: Tee {
inner: <tee 20>,
},
},
},
},
Expand Down

0 comments on commit 651801e

Please sign in to comment.