diff --git a/round-based/src/rounds/store.rs b/round-based/src/rounds/store.rs index 007806c..9ad6f54 100644 --- a/round-based/src/rounds/store.rs +++ b/round-based/src/rounds/store.rs @@ -233,6 +233,20 @@ impl RoundInput { expected_msg_type: msg_type, } } + + /// Construct a new store for broadcast messages + /// + /// The same as `RoundInput::new(i, n, MessageType::Broadcast)` + pub fn broadcast(i: u16, n: u16) -> Self { + Self::new(i, n, MessageType::Broadcast) + } + + /// Construct a new store for p2p messages + /// + /// The same as `RoundInput::new(i, n, MessageType::P2P)` + pub fn p2p(i: u16, n: u16) -> Self { + Self::new(i, n, MessageType::P2P) + } } impl MessagesStore for RoundInput @@ -304,6 +318,22 @@ impl RoundMsgs { self.messages.insert(usize::from(self.i), my_msg); self.messages } + + /// Returns iterator over messages with sender indexes + /// + /// Iterator yields `(sender_index, message)` + pub fn into_iter_indexed(self) -> impl Iterator { + let indexes = (0..self.i).chain(self.i + 1..); + indexes.zip(self.messages) + } + + /// Returns iterator over messages with sender indexes + /// + /// Iterator yields `(sender_index, &message)` + pub fn iter_indexed(&self) -> impl Iterator { + let indexes = (0..self.i).chain(self.i + 1..); + indexes.zip(&self.messages) + } } #[derive(Debug, Error)]