Skip to content
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ members = ["crate/findex", "crate/memories"]
resolver = "2"

[workspace.package]
version = "8.0.1"
version = "8.1.0"
authors = [
"Bruno Grieder <[email protected]>",
"Célia Corsin <[email protected]>",
Expand All @@ -30,3 +30,4 @@ cosmian_crypto_core = { version = "10.2", default-features = false, features = [
criterion = { version = "0.6" }
smol-macros = { version = "0.1" }
tokio = { version = "1.46" }
futures = "0.3.31"
7 changes: 4 additions & 3 deletions crate/findex/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@ name = "cosmian_findex"
path = "src/lib.rs"

[features]
batch = ["cosmian_sse_memories/batch"]
test-utils = ["agnostic-lite", "criterion"]

[dependencies]
aes = "0.8"
cosmian_crypto_core.workspace = true
cosmian_sse_memories = { path = "../memories", version = "8.0" }
cosmian_sse_memories = { path = "../memories", version = "8.1.0" }
xts-mode = "0.5"

futures.workspace = true
# Optional dependencies for testing and benchmarking.
agnostic-lite = { workspace = true, optional = true, features = [
"tokio",
Expand All @@ -33,7 +34,7 @@ criterion = { workspace = true, optional = true }

[dev-dependencies]
agnostic-lite = { workspace = true, features = ["tokio"] }
cosmian_sse_memories = { path = "../memories", version = "8.0", features = [
cosmian_sse_memories = { path = "../memories", version = "8.1.0", features = [
"redis-mem",
"sqlite-mem",
"postgres-mem",
Expand Down
2 changes: 2 additions & 0 deletions crate/findex/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

This crate provides the core functionality of Findex, defining the abstract data types, cryptographic operations, and encoding algorithms.

Supports batching operations into a singe call to the memory interface, which reduces connection overhead and avoids file descriptor limits on some Linux systems.

## Setup

Add `cosmian_findex` as dependency to your project :
Expand Down
33 changes: 33 additions & 0 deletions crate/findex/src/adt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,39 @@ pub trait VectorADT: Send {
fn read(&self) -> impl Send + Future<Output = Result<Vec<Self::Value>, Self::Error>>;
}

/// This trait provides methods that let an index operate on multiple keywords or entries simultaneously.
#[cfg(feature = "batch")]
pub trait IndexBatcher<Keyword, Value> {
type Error: std::error::Error;

/// Search the index for the values bound to the given keywords.
fn batch_search(
&self,
keywords: Vec<&Keyword>,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Best not to use a vector to avoid imposing needless collection upon the client.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

I think I tried that, and probably stopped because of this. Not because we can't use lifetime specefier, but more because I think we cummonly try to avoid their usage

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks to github bugs, A comment I wrote here was lost

I remember saying that we had 3 solutions :

  • keep it as is
  • accept to add lifetimes to the definition
  • take ownership of the Keywords (I do not prefer doing this as it will induce non necessary cloning )

close this if you think we should keep it like it now

By the way,I agree with your comment and that I have implemented it for the other functions (batch_insert, etc...)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a general note

I found myself also obliged to add "ExactSizeIterator" bound - basically garantees that we can call len() . This is mandatory, to know how big the memory should be instantiated

    fn batch_insert<Values, Entries>(
        &self,
        entries: Entries,
    ) -> impl Send + Future<Output = Result<(), Self::Error>>
    where
        Values: Sync + Send + IntoIterator<Item = Value>,
        Entries: Send + IntoIterator<Item = (Keyword, Values)>,
        Entries::IntoIter: ExactSizeIterator;

) -> impl Future<Output = Result<Vec<HashSet<Value>>, Self::Error>>;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hasn't "async in trait" become stable by now? Maybe try with async fn batch_search(...) -> Result<..., ...>;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hell yeah looks like it, I will update the adequate traits https://blog.rust-lang.org/2023/12/21/async-fn-rpit-in-traits/

UPDATE : this won't be possible with all traits on this code since the async in trait does not garantee the send - I did a try on the branch called test/async_trait , which is pushed to the remot


/// Binds each value to their associated keyword in this index.
fn batch_insert<Values, Entries>(
&self,
entries: Entries,
) -> impl Send + Future<Output = Result<(), Self::Error>>
where
Values: Send + IntoIterator<Item = Value>,
Entries: Send + IntoIterator<Item = (Keyword, Values)>,
Entries::IntoIter: ExactSizeIterator,
<Entries as IntoIterator>::IntoIter: Send;

/// Removes the given values from the index.
fn batch_delete<Values, Entries>(
&self,
entries: Entries,
) -> impl Send + Future<Output = Result<(), Self::Error>>
where
Values: Send + IntoIterator<Item = Value>,
Entries: Send + IntoIterator<Item = (Keyword, Values)>,
Entries::IntoIter: ExactSizeIterator + Send;
}

#[cfg(test)]
pub mod tests {

Expand Down
59 changes: 59 additions & 0 deletions crate/findex/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
use std::fmt::{Debug, Display};

#[cfg(feature = "batch")]
pub use batch_findex_error::*;

#[derive(Debug)]
pub enum Error<Address> {
Parsing(String),
Expand All @@ -16,3 +19,59 @@ impl<Address: Debug> Display for Error<Address> {
}

impl<Address: Debug> std::error::Error for Error<Address> {}

#[cfg(feature = "batch")]
pub mod batch_findex_error {
use cosmian_sse_memories::{MemoryADT, MemoryBatcherError};

use super::*;

#[derive(Debug)]
pub enum BatchFindexError<M: MemoryADT>
where
<M as MemoryADT>::Word: Debug,
{
BatchingLayer(MemoryBatcherError<M>),
Findex(Error<M::Address>),
Other(String),
}

impl<M: MemoryADT + Debug> Display for BatchFindexError<M>
where
<M as MemoryADT>::Address: Debug,
<M as MemoryADT>::Word: Debug,
{
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::BatchingLayer(e) => write!(f, "Batching layer error: {e}"),
Self::Findex(error) => write!(f, "Findex error: {error:?}"),
Self::Other(msg) => write!(f, "{msg}"),
}
}
}

impl<M: MemoryADT + Debug> From<Error<M::Address>> for BatchFindexError<M>
where
<M as MemoryADT>::Word: Debug,
{
fn from(e: Error<M::Address>) -> Self {
Self::Findex(e)
}
}

impl<M: MemoryADT + Debug> From<MemoryBatcherError<M>> for BatchFindexError<M>
where
<M as MemoryADT>::Word: Debug,
{
fn from(e: MemoryBatcherError<M>) -> Self {
Self::BatchingLayer(e)
}
}

impl<M: MemoryADT + Debug> std::error::Error for BatchFindexError<M>
where
<M as MemoryADT>::Address: Debug,
<M as MemoryADT>::Word: Debug,
{
}
}
2 changes: 0 additions & 2 deletions crate/findex/src/findex.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![allow(clippy::type_complexity)]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

an outdated lint, for some reason


use std::{
collections::HashSet,
fmt::Debug,
Expand Down
Loading
Loading