Skip to content

Commit

Permalink
refactor: add conflict trait api
Browse files Browse the repository at this point in the history
Signed-off-by: bsbds <[email protected]>
  • Loading branch information
bsbds committed Mar 6, 2024
1 parent 296105f commit d479a80
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
55 changes: 55 additions & 0 deletions crates/curp-external-api/src/conflict.rs
Original file line number Diff line number Diff line change
@@ -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<Self::Entry>;

/// 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<Self::Entry>;

/// 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<Self::Entry>;

/// Returns all commands in the pool
fn all(&self) -> Vec<Self::Entry>;

/// 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);
}
3 changes: 3 additions & 0 deletions crates/curp-external-api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

0 comments on commit d479a80

Please sign in to comment.