diff --git a/crates/curp-external-api/src/conflict.rs b/crates/curp-external-api/src/conflict.rs new file mode 100644 index 000000000..c80e8294c --- /dev/null +++ b/crates/curp-external-api/src/conflict.rs @@ -0,0 +1,55 @@ +#![allow(clippy::module_name_repetitions)] + +/// Insert into speculative pool +pub trait SpeculativePool { + /// Entry of the pool + type Entry; + + /// Inserts a command in to the pool + /// + /// Returns `Some(Entry)` if a conflict is detected + fn insert(&mut self, entry: Self::Entry) -> Option; + + /// Returns the number of commands in the pool + fn len(&self) -> usize; + + /// Checks if the pool contains some commands that will conflict with all other commands + fn is_empty(&self) -> bool; + + /// Removes a command from the pool + fn remove(&mut self, entry: Self::Entry); + + /// Returns all commands in the pool + fn all(&self) -> Vec; + + /// Clears all entries in the pool + fn clear(&mut self); +} + +/// Insert into speculative pool +pub trait UncommittedPool { + /// Entry of the pool + type Entry; + /// Inserts a command in to the pool + /// + /// Returns `true` if a conflict is detected + fn insert(&mut self, entry: Self::Entry) -> bool; + + /// Returns all commands in the pool that conflicts with the given command + fn all_conflict(&self, entry: &Self::Entry) -> Vec; + + /// Returns all commands in the pool + fn all(&self) -> Vec; + + /// Returns the number of commands in the pool + fn len(&self) -> usize; + + /// Checks if the pool will conflict with all commands + fn is_empty(&self) -> bool; + + /// Removes a command from the pool + fn remove(&mut self, entry: Self::Entry); + + /// Clears all entries in the pool + fn clear(&mut self); +} diff --git a/crates/curp-external-api/src/lib.rs b/crates/curp-external-api/src/lib.rs index 73421d4ae..81d9bd3af 100644 --- a/crates/curp-external-api/src/lib.rs +++ b/crates/curp-external-api/src/lib.rs @@ -149,3 +149,6 @@ pub type InflightId = u64; pub mod cmd; /// The command to be executed pub mod role_change; + +/// Conflict trait +pub mod conflict;