Skip to content

Commit

Permalink
fix base trait
Browse files Browse the repository at this point in the history
Signed-off-by: Kosuke Morimoto <[email protected]>
  • Loading branch information
kmrmt committed Feb 21, 2024
1 parent eab39ea commit dbf693f
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 12 deletions.
14 changes: 8 additions & 6 deletions rust/libs/algorithm/src/base.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
pub mod algorithm {
use anyhow::Result;

pub trait Base<T, U, SP, SR, IP, IR, UP, UR, RP, RR, CP, CR> {
fn search(&self, v: &Vec<T>, p: Option<&SP>) -> Result<&SR>;
fn insert(&self, v: &Vec<T>, id: &U, p: Option<&IP>) -> Result<&IR>;
fn update(&self, v: &Vec<T>, id: &U, p: Option<&UP>) -> Result<&UR>;
fn remove(&self, id: &U, p: Option<&RP>) -> Result<&RR>;
fn commit(&self, p: Option<&CP>) -> Result<&CR>;
pub trait Base<T, U, SP, SR, IP, IR, UP, UR, RP, RR, CP, CR, P> {
fn search(&self, v: &Vec<T>, p: Option<SP>) -> Result<SR>;
fn insert(&self, v: &Vec<T>, id: &U, p: Option<IP>) -> Result<IR>;
fn update(&self, v: &Vec<T>, id: &U, p: Option<UP>) -> Result<UR>;
fn remove(&self, id: &U, p: Option<RP>) -> Result<RR>;
fn commit(&self, p: Option<CP>) -> Result<CR>;

fn new(p: Option<P>) -> Result<Self>;
}
}
34 changes: 28 additions & 6 deletions rust/libs/algorithm/src/ngt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,44 @@ pub mod ngt {
num: u32,
}

#[derive(Debug)]
#[derive(Debug)]
pub struct InsertParam {}

#[derive(Debug)]
pub struct UpdateParam {}

#[derive(Debug)]
pub struct RemoveParam {}

#[derive(Debug)]
pub struct CommitParam{}
pub struct CommitParam {}

#[derive(Debug)]
pub struct NGTParam {}

impl Base<f32, String, SearchParam, SearchResponse, InsertParam, (), UpdateParam, (), RemoveParam, (), CommitParam, ()> for NGT {
fn search()
impl
Base<
f32,
String,
SearchParam,
SearchResponse,
InsertParam,
(),
UpdateParam,
(),
RemoveParam,
(),
CommitParam,
(),
NGTParam,
> for NGT
{
fn search(&self, v: &Vec<T>, p: Option<SearchParam>) -> Result<SearchResponse>;
fn insert(&self, v: &Vec<T>, id: &U, p: Option<InsertParam>) -> Result<()>;
fn update(&self, v: &Vec<T>, id: &U, p: Option<UpdateParam>) -> Result<()>;
fn remove(&self, id: &U, p: Option<RemoveParam>) -> Result<()>;
fn commit(&self, p: Option<CommitParam>) -> Result<()>;

fn new(p: Option<NGTParam>) -> Result<Self>;
}
}
}

0 comments on commit dbf693f

Please sign in to comment.