Makes StoreConnection.(insert|remove) take mut references

pull/10/head
Tpt 5 years ago
parent 2d9d33c8be
commit a017d6e1c3
  1. 4
      lib/src/store/memory.rs
  2. 22
      lib/src/store/mod.rs
  3. 4
      lib/src/store/rocksdb.rs

@ -105,7 +105,7 @@ impl<'a> StoreConnection for &'a MemoryStore {
})) }))
} }
fn insert(&self, quad: &EncodedQuad) -> Result<()> { fn insert(&mut self, quad: &EncodedQuad) -> Result<()> {
let mut quad_indexes = self.quad_indexes_mut()?; let mut quad_indexes = self.quad_indexes_mut()?;
insert_into_quad_map( insert_into_quad_map(
&mut quad_indexes.gosp, &mut quad_indexes.gosp,
@ -152,7 +152,7 @@ impl<'a> StoreConnection for &'a MemoryStore {
Ok(()) Ok(())
} }
fn remove(&self, quad: &EncodedQuad) -> Result<()> { fn remove(&mut self, quad: &EncodedQuad) -> Result<()> {
let mut quad_indexes = self.quad_indexes_mut()?; let mut quad_indexes = self.quad_indexes_mut()?;
remove_from_quad_map( remove_from_quad_map(
&mut quad_indexes.gosp, &mut quad_indexes.gosp,

@ -30,8 +30,8 @@ pub trait Store {
/// A connection to a `Store` /// A connection to a `Store`
pub trait StoreConnection: StringStore + Sized + Clone { pub trait StoreConnection: StringStore + Sized + Clone {
fn contains(&self, quad: &EncodedQuad) -> Result<bool>; fn contains(&self, quad: &EncodedQuad) -> Result<bool>;
fn insert(&self, quad: &EncodedQuad) -> Result<()>; fn insert(&mut self, quad: &EncodedQuad) -> Result<()>;
fn remove(&self, quad: &EncodedQuad) -> Result<()>; fn remove(&mut self, quad: &EncodedQuad) -> Result<()>;
fn quads_for_pattern<'a>( fn quads_for_pattern<'a>(
&'a self, &'a self,
subject: Option<EncodedTerm>, subject: Option<EncodedTerm>,
@ -168,7 +168,7 @@ impl<S: StoreConnection> RepositoryConnection for StoreRepositoryConnection<S> {
impl<S: StoreConnection> StoreRepositoryConnection<S> { impl<S: StoreConnection> StoreRepositoryConnection<S> {
fn load_from_triple_parser<P: TriplesParser>( fn load_from_triple_parser<P: TriplesParser>(
&self, &mut self,
mut parser: P, mut parser: P,
to_graph_name: Option<&NamedOrBlankNode>, to_graph_name: Option<&NamedOrBlankNode>,
) -> Result<()> ) -> Result<()>
@ -176,28 +176,32 @@ impl<S: StoreConnection> StoreRepositoryConnection<S> {
P::Error: Send + Sync + 'static, P::Error: Send + Sync + 'static,
{ {
let mut bnode_map = HashMap::default(); let mut bnode_map = HashMap::default();
let encoder = self.inner.encoder();
let graph_name = if let Some(graph_name) = to_graph_name { let graph_name = if let Some(graph_name) = to_graph_name {
encoder.encode_named_or_blank_node(graph_name)? self.inner
.encoder()
.encode_named_or_blank_node(graph_name)?
} else { } else {
EncodedTerm::DefaultGraph EncodedTerm::DefaultGraph
}; };
parser.parse_all(&mut move |t| { parser.parse_all(&mut move |t| {
self.inner self.inner
.insert(&encoder.encode_rio_triple_in_graph(t, graph_name, &mut bnode_map)?) .insert(&self.inner.encoder().encode_rio_triple_in_graph(
t,
graph_name,
&mut bnode_map,
)?)
})?; })?;
Ok(()) Ok(())
} }
fn load_from_quad_parser<P: QuadsParser>(&self, mut parser: P) -> Result<()> fn load_from_quad_parser<P: QuadsParser>(&mut self, mut parser: P) -> Result<()>
where where
P::Error: Send + Sync + 'static, P::Error: Send + Sync + 'static,
{ {
let mut bnode_map = HashMap::default(); let mut bnode_map = HashMap::default();
let encoder = self.inner.encoder();
parser.parse_all(&mut move |q| { parser.parse_all(&mut move |q| {
self.inner self.inner
.insert(&encoder.encode_rio_quad(q, &mut bnode_map)?) .insert(&self.inner.encoder().encode_rio_quad(q, &mut bnode_map)?)
})?; })?;
Ok(()) Ok(())
} }

@ -176,7 +176,7 @@ impl<'a> StoreConnection for RocksDbStoreConnection<'a> {
.is_some()) .is_some())
} }
fn insert(&self, quad: &EncodedQuad) -> Result<()> { fn insert(&mut self, quad: &EncodedQuad) -> Result<()> {
let mut batch = WriteBatch::default(); let mut batch = WriteBatch::default();
batch.put_cf(self.spog_cf, &encode_spog_quad(quad)?, &EMPTY_BUF)?; batch.put_cf(self.spog_cf, &encode_spog_quad(quad)?, &EMPTY_BUF)?;
batch.put_cf(self.posg_cf, &encode_posg_quad(quad)?, &EMPTY_BUF)?; batch.put_cf(self.posg_cf, &encode_posg_quad(quad)?, &EMPTY_BUF)?;
@ -185,7 +185,7 @@ impl<'a> StoreConnection for RocksDbStoreConnection<'a> {
Ok(()) Ok(())
} }
fn remove(&self, quad: &EncodedQuad) -> Result<()> { fn remove(&mut self, quad: &EncodedQuad) -> Result<()> {
let mut batch = WriteBatch::default(); let mut batch = WriteBatch::default();
batch.delete_cf(self.spog_cf, &encode_spog_quad(quad)?)?; batch.delete_cf(self.spog_cf, &encode_spog_quad(quad)?)?;
batch.delete_cf(self.posg_cf, &encode_posg_quad(quad)?)?; batch.delete_cf(self.posg_cf, &encode_posg_quad(quad)?)?;

Loading…
Cancel
Save