Adds a special EncodedTerm for the default graph

pull/10/head
Tpt 6 years ago
parent 439719732c
commit b01054a747
  1. 92
      src/store/numeric_encoder.rs
  2. 20
      src/store/rocksdb/storage.rs
  3. 87
      src/store/store.rs

@ -16,14 +16,17 @@ pub trait BytesStore {
fn get_bytes(&self, id: u64) -> Result<Option<Self::BytesOutput>>; fn get_bytes(&self, id: u64) -> Result<Option<Self::BytesOutput>>;
} }
const TYPE_NOTHING_ID: u8 = 0; const TYPE_DEFAULT_GRAPH_ID: u8 = 0;
const TYPE_NAMED_NODE_ID: u8 = 1; const TYPE_NAMED_NODE_ID: u8 = 1;
const TYPE_BLANK_NODE_ID: u8 = 2; const TYPE_BLANK_NODE_ID: u8 = 2;
const TYPE_LANG_STRING_LITERAL_ID: u8 = 3; const TYPE_LANG_STRING_LITERAL_ID: u8 = 3;
const TYPE_TYPED_LITERAL_ID: u8 = 4; const TYPE_TYPED_LITERAL_ID: u8 = 4;
pub static ENCODED_DEFAULT_GRAPH: EncodedTerm = EncodedTerm::DefaultGraph {};
#[derive(Eq, PartialEq, Ord, PartialOrd, Debug, Clone, Hash)] #[derive(Eq, PartialEq, Ord, PartialOrd, Debug, Clone, Hash)]
pub enum EncodedTerm { pub enum EncodedTerm {
DefaultGraph {},
NamedNode { iri_id: u64 }, NamedNode { iri_id: u64 },
BlankNode(Uuid), BlankNode(Uuid),
LangStringLiteral { value_id: u64, language_id: u64 }, LangStringLiteral { value_id: u64, language_id: u64 },
@ -33,6 +36,7 @@ pub enum EncodedTerm {
impl EncodedTerm { impl EncodedTerm {
fn type_id(&self) -> u8 { fn type_id(&self) -> u8 {
match self { match self {
EncodedTerm::DefaultGraph { .. } => TYPE_DEFAULT_GRAPH_ID,
EncodedTerm::NamedNode { .. } => TYPE_NAMED_NODE_ID, EncodedTerm::NamedNode { .. } => TYPE_NAMED_NODE_ID,
EncodedTerm::BlankNode(_) => TYPE_BLANK_NODE_ID, EncodedTerm::BlankNode(_) => TYPE_BLANK_NODE_ID,
EncodedTerm::LangStringLiteral { .. } => TYPE_LANG_STRING_LITERAL_ID, EncodedTerm::LangStringLiteral { .. } => TYPE_LANG_STRING_LITERAL_ID,
@ -46,12 +50,11 @@ pub struct EncodedQuad {
pub subject: EncodedTerm, pub subject: EncodedTerm,
pub predicate: EncodedTerm, pub predicate: EncodedTerm,
pub object: EncodedTerm, pub object: EncodedTerm,
pub graph_name: Option<EncodedTerm>, pub graph_name: EncodedTerm,
} }
pub trait TermReader { pub trait TermReader {
fn read_term(&mut self) -> Result<EncodedTerm>; fn read_term(&mut self) -> Result<EncodedTerm>;
fn read_optional_term(&mut self) -> Result<Option<EncodedTerm>>;
fn read_spog_quad(&mut self) -> Result<EncodedQuad>; fn read_spog_quad(&mut self) -> Result<EncodedQuad>;
fn read_posg_quad(&mut self) -> Result<EncodedQuad>; fn read_posg_quad(&mut self) -> Result<EncodedQuad>;
fn read_ospg_quad(&mut self) -> Result<EncodedQuad>; fn read_ospg_quad(&mut self) -> Result<EncodedQuad>;
@ -59,16 +62,25 @@ pub trait TermReader {
impl<R: Read> TermReader for R { impl<R: Read> TermReader for R {
fn read_term(&mut self) -> Result<EncodedTerm> { fn read_term(&mut self) -> Result<EncodedTerm> {
let type_id = self.read_u8()?; match self.read_u8()? {
read_term_after_type(self, type_id) TYPE_DEFAULT_GRAPH_ID => Ok(EncodedTerm::DefaultGraph {}),
TYPE_NAMED_NODE_ID => Ok(EncodedTerm::NamedNode {
iri_id: self.read_u64::<NetworkEndian>()?,
}),
TYPE_BLANK_NODE_ID => {
let mut uuid_buffer = [0 as u8; 16];
self.read_exact(&mut uuid_buffer)?;
Ok(EncodedTerm::BlankNode(Uuid::from_bytes(&uuid_buffer)?))
} }
TYPE_LANG_STRING_LITERAL_ID => Ok(EncodedTerm::LangStringLiteral {
fn read_optional_term(&mut self) -> Result<Option<EncodedTerm>> { language_id: self.read_u64::<NetworkEndian>()?,
let type_id = self.read_u8()?; value_id: self.read_u64::<NetworkEndian>()?,
if type_id == 0 { }),
Ok(None) TYPE_TYPED_LITERAL_ID => Ok(EncodedTerm::TypedLiteral {
} else { datatype_id: self.read_u64::<NetworkEndian>()?,
Ok(Some(read_term_after_type(self, type_id)?)) value_id: self.read_u64::<NetworkEndian>()?,
}),
_ => Err("the term buffer has an invalid type id".into()),
} }
} }
@ -76,7 +88,7 @@ impl<R: Read> TermReader for R {
let subject = self.read_term()?; let subject = self.read_term()?;
let predicate = self.read_term()?; let predicate = self.read_term()?;
let object = self.read_term()?; let object = self.read_term()?;
let graph_name = self.read_optional_term()?; let graph_name = self.read_term()?;
Ok(EncodedQuad { Ok(EncodedQuad {
subject, subject,
predicate, predicate,
@ -89,7 +101,7 @@ impl<R: Read> TermReader for R {
let predicate = self.read_term()?; let predicate = self.read_term()?;
let object = self.read_term()?; let object = self.read_term()?;
let subject = self.read_term()?; let subject = self.read_term()?;
let graph_name = self.read_optional_term()?; let graph_name = self.read_term()?;
Ok(EncodedQuad { Ok(EncodedQuad {
subject, subject,
predicate, predicate,
@ -102,7 +114,7 @@ impl<R: Read> TermReader for R {
let object = self.read_term()?; let object = self.read_term()?;
let subject = self.read_term()?; let subject = self.read_term()?;
let predicate = self.read_term()?; let predicate = self.read_term()?;
let graph_name = self.read_optional_term()?; let graph_name = self.read_term()?;
Ok(EncodedQuad { Ok(EncodedQuad {
subject, subject,
predicate, predicate,
@ -112,31 +124,8 @@ impl<R: Read> TermReader for R {
} }
} }
fn read_term_after_type(reader: &mut impl Read, type_id: u8) -> Result<EncodedTerm> {
match type_id {
TYPE_NAMED_NODE_ID => Ok(EncodedTerm::NamedNode {
iri_id: reader.read_u64::<NetworkEndian>()?,
}),
TYPE_BLANK_NODE_ID => {
let mut uuid_buffer = [0 as u8; 16];
reader.read_exact(&mut uuid_buffer)?;
Ok(EncodedTerm::BlankNode(Uuid::from_bytes(&uuid_buffer)?))
}
TYPE_LANG_STRING_LITERAL_ID => Ok(EncodedTerm::LangStringLiteral {
language_id: reader.read_u64::<NetworkEndian>()?,
value_id: reader.read_u64::<NetworkEndian>()?,
}),
TYPE_TYPED_LITERAL_ID => Ok(EncodedTerm::TypedLiteral {
datatype_id: reader.read_u64::<NetworkEndian>()?,
value_id: reader.read_u64::<NetworkEndian>()?,
}),
_ => Err("the term buffer has an invalid type id".into()),
}
}
pub trait TermWriter { pub trait TermWriter {
fn write_term(&mut self, term: &EncodedTerm) -> Result<()>; fn write_term(&mut self, term: &EncodedTerm) -> Result<()>;
fn write_optional_term(&mut self, term: &Option<EncodedTerm>) -> Result<()>;
fn write_spog_quad(&mut self, quad: &EncodedQuad) -> Result<()>; fn write_spog_quad(&mut self, quad: &EncodedQuad) -> Result<()>;
fn write_posg_quad(&mut self, quad: &EncodedQuad) -> Result<()>; fn write_posg_quad(&mut self, quad: &EncodedQuad) -> Result<()>;
fn write_ospg_quad(&mut self, quad: &EncodedQuad) -> Result<()>; fn write_ospg_quad(&mut self, quad: &EncodedQuad) -> Result<()>;
@ -146,6 +135,7 @@ impl<R: Write> TermWriter for R {
fn write_term(&mut self, term: &EncodedTerm) -> Result<()> { fn write_term(&mut self, term: &EncodedTerm) -> Result<()> {
self.write_u8(term.type_id())?; self.write_u8(term.type_id())?;
match term { match term {
EncodedTerm::DefaultGraph {} => {}
EncodedTerm::NamedNode { iri_id } => self.write_u64::<NetworkEndian>(*iri_id)?, EncodedTerm::NamedNode { iri_id } => self.write_u64::<NetworkEndian>(*iri_id)?,
EncodedTerm::BlankNode(id) => self.write_all(id.as_bytes())?, EncodedTerm::BlankNode(id) => self.write_all(id.as_bytes())?,
EncodedTerm::LangStringLiteral { EncodedTerm::LangStringLiteral {
@ -166,18 +156,11 @@ impl<R: Write> TermWriter for R {
Ok(()) Ok(())
} }
fn write_optional_term(&mut self, term: &Option<EncodedTerm>) -> Result<()> {
match term {
Some(term) => self.write_term(term),
None => Ok(self.write_u8(TYPE_NOTHING_ID)?),
}
}
fn write_spog_quad(&mut self, quad: &EncodedQuad) -> Result<()> { fn write_spog_quad(&mut self, quad: &EncodedQuad) -> Result<()> {
self.write_term(&quad.subject)?; self.write_term(&quad.subject)?;
self.write_term(&quad.predicate)?; self.write_term(&quad.predicate)?;
self.write_term(&quad.object)?; self.write_term(&quad.object)?;
self.write_optional_term(&quad.graph_name)?; self.write_term(&quad.graph_name)?;
Ok(()) Ok(())
} }
@ -185,7 +168,7 @@ impl<R: Write> TermWriter for R {
self.write_term(&quad.predicate)?; self.write_term(&quad.predicate)?;
self.write_term(&quad.object)?; self.write_term(&quad.object)?;
self.write_term(&quad.subject)?; self.write_term(&quad.subject)?;
self.write_optional_term(&quad.graph_name)?; self.write_term(&quad.graph_name)?;
Ok(()) Ok(())
} }
@ -193,7 +176,7 @@ impl<R: Write> TermWriter for R {
self.write_term(&quad.object)?; self.write_term(&quad.object)?;
self.write_term(&quad.subject)?; self.write_term(&quad.subject)?;
self.write_term(&quad.predicate)?; self.write_term(&quad.predicate)?;
self.write_optional_term(&quad.graph_name)?; self.write_term(&quad.graph_name)?;
Ok(()) Ok(())
} }
} }
@ -252,8 +235,8 @@ impl<S: BytesStore> Encoder<S> {
predicate: self.encode_named_node(quad.predicate())?, predicate: self.encode_named_node(quad.predicate())?,
object: self.encode_term(quad.object())?, object: self.encode_term(quad.object())?,
graph_name: match quad.graph_name() { graph_name: match quad.graph_name() {
Some(graph_name) => Some(self.encode_named_or_blank_node(&graph_name)?), Some(graph_name) => self.encode_named_or_blank_node(&graph_name)?,
None => None, None => ENCODED_DEFAULT_GRAPH.clone(),
}, },
}) })
} }
@ -261,18 +244,19 @@ impl<S: BytesStore> Encoder<S> {
pub fn encode_triple_in_graph( pub fn encode_triple_in_graph(
&self, &self,
triple: &Triple, triple: &Triple,
graph_name: Option<EncodedTerm>, graph_name: &EncodedTerm,
) -> Result<EncodedQuad> { ) -> Result<EncodedQuad> {
Ok(EncodedQuad { Ok(EncodedQuad {
subject: self.encode_named_or_blank_node(triple.subject())?, subject: self.encode_named_or_blank_node(triple.subject())?,
predicate: self.encode_named_node(triple.predicate())?, predicate: self.encode_named_node(triple.predicate())?,
object: self.encode_term(triple.object())?, object: self.encode_term(triple.object())?,
graph_name, graph_name: graph_name.clone(),
}) })
} }
pub fn decode_term(&self, encoded: &EncodedTerm) -> Result<Term> { pub fn decode_term(&self, encoded: &EncodedTerm) -> Result<Term> {
match encoded { match encoded {
EncodedTerm::DefaultGraph {} => Err("The default graph tag is not a valid term".into()),
EncodedTerm::NamedNode { iri_id } => { EncodedTerm::NamedNode { iri_id } => {
Ok(NamedNode::from(self.decode_url_value(*iri_id)?).into()) Ok(NamedNode::from(self.decode_url_value(*iri_id)?).into())
} }
@ -324,8 +308,8 @@ impl<S: BytesStore> Encoder<S> {
self.decode_named_node(&encoded.predicate)?, self.decode_named_node(&encoded.predicate)?,
self.decode_term(&encoded.object)?, self.decode_term(&encoded.object)?,
match encoded.graph_name { match encoded.graph_name {
Some(ref graph_name) => Some(self.decode_named_or_blank_node(&graph_name)?), EncodedTerm::DefaultGraph {} => None,
None => None, ref graph_name => Some(self.decode_named_or_blank_node(graph_name)?),
}, },
)) ))
} }

@ -230,7 +230,7 @@ impl EncodedQuadsStore for RocksDbStore {
fn quads_for_graph( fn quads_for_graph(
&self, &self,
graph_name: &Option<EncodedTerm>, graph_name: &EncodedTerm,
) -> Result<InGraphQuadsIterator<SPOGIndexIterator>> { ) -> Result<InGraphQuadsIterator<SPOGIndexIterator>> {
Ok(InGraphQuadsIterator { Ok(InGraphQuadsIterator {
iter: self.quads()?, iter: self.quads()?,
@ -241,7 +241,7 @@ impl EncodedQuadsStore for RocksDbStore {
fn quads_for_subject_graph( fn quads_for_subject_graph(
&self, &self,
subject: &EncodedTerm, subject: &EncodedTerm,
graph_name: &Option<EncodedTerm>, graph_name: &EncodedTerm,
) -> Result<InGraphQuadsIterator<FilteringEncodedQuadsIterator<SPOGIndexIterator>>> { ) -> Result<InGraphQuadsIterator<FilteringEncodedQuadsIterator<SPOGIndexIterator>>> {
Ok(InGraphQuadsIterator { Ok(InGraphQuadsIterator {
iter: self.quads_for_subject(subject)?, iter: self.quads_for_subject(subject)?,
@ -253,7 +253,7 @@ impl EncodedQuadsStore for RocksDbStore {
&self, &self,
subject: &EncodedTerm, subject: &EncodedTerm,
predicate: &EncodedTerm, predicate: &EncodedTerm,
graph_name: &Option<EncodedTerm>, graph_name: &EncodedTerm,
) -> Result<InGraphQuadsIterator<FilteringEncodedQuadsIterator<SPOGIndexIterator>>> { ) -> Result<InGraphQuadsIterator<FilteringEncodedQuadsIterator<SPOGIndexIterator>>> {
Ok(InGraphQuadsIterator { Ok(InGraphQuadsIterator {
iter: self.quads_for_subject_predicate(subject, predicate)?, iter: self.quads_for_subject_predicate(subject, predicate)?,
@ -265,7 +265,7 @@ impl EncodedQuadsStore for RocksDbStore {
&self, &self,
subject: &EncodedTerm, subject: &EncodedTerm,
object: &EncodedTerm, object: &EncodedTerm,
graph_name: &Option<EncodedTerm>, graph_name: &EncodedTerm,
) -> Result<InGraphQuadsIterator<FilteringEncodedQuadsIterator<OSPGIndexIterator>>> { ) -> Result<InGraphQuadsIterator<FilteringEncodedQuadsIterator<OSPGIndexIterator>>> {
Ok(InGraphQuadsIterator { Ok(InGraphQuadsIterator {
iter: self.quads_for_subject_object(subject, object)?, iter: self.quads_for_subject_object(subject, object)?,
@ -276,7 +276,7 @@ impl EncodedQuadsStore for RocksDbStore {
fn quads_for_predicate_graph( fn quads_for_predicate_graph(
&self, &self,
predicate: &EncodedTerm, predicate: &EncodedTerm,
graph_name: &Option<EncodedTerm>, graph_name: &EncodedTerm,
) -> Result<InGraphQuadsIterator<FilteringEncodedQuadsIterator<POSGIndexIterator>>> { ) -> Result<InGraphQuadsIterator<FilteringEncodedQuadsIterator<POSGIndexIterator>>> {
Ok(InGraphQuadsIterator { Ok(InGraphQuadsIterator {
iter: self.quads_for_predicate(predicate)?, iter: self.quads_for_predicate(predicate)?,
@ -288,7 +288,7 @@ impl EncodedQuadsStore for RocksDbStore {
&self, &self,
predicate: &EncodedTerm, predicate: &EncodedTerm,
object: &EncodedTerm, object: &EncodedTerm,
graph_name: &Option<EncodedTerm>, graph_name: &EncodedTerm,
) -> Result<InGraphQuadsIterator<FilteringEncodedQuadsIterator<POSGIndexIterator>>> { ) -> Result<InGraphQuadsIterator<FilteringEncodedQuadsIterator<POSGIndexIterator>>> {
Ok(InGraphQuadsIterator { Ok(InGraphQuadsIterator {
iter: self.quads_for_predicate_object(predicate, object)?, iter: self.quads_for_predicate_object(predicate, object)?,
@ -299,7 +299,7 @@ impl EncodedQuadsStore for RocksDbStore {
fn quads_for_object_graph( fn quads_for_object_graph(
&self, &self,
object: &EncodedTerm, object: &EncodedTerm,
graph_name: &Option<EncodedTerm>, graph_name: &EncodedTerm,
) -> Result<InGraphQuadsIterator<FilteringEncodedQuadsIterator<OSPGIndexIterator>>> { ) -> Result<InGraphQuadsIterator<FilteringEncodedQuadsIterator<OSPGIndexIterator>>> {
Ok(InGraphQuadsIterator { Ok(InGraphQuadsIterator {
iter: self.quads_for_object(object)?, iter: self.quads_for_object(object)?,
@ -363,7 +363,7 @@ struct EncodedQuadPattern {
subject: Option<EncodedTerm>, subject: Option<EncodedTerm>,
predicate: Option<EncodedTerm>, predicate: Option<EncodedTerm>,
object: Option<EncodedTerm>, object: Option<EncodedTerm>,
graph_name: Option<Option<EncodedTerm>>, graph_name: Option<EncodedTerm>,
} }
impl EncodedQuadPattern { impl EncodedQuadPattern {
@ -371,7 +371,7 @@ impl EncodedQuadPattern {
subject: Option<EncodedTerm>, subject: Option<EncodedTerm>,
predicate: Option<EncodedTerm>, predicate: Option<EncodedTerm>,
object: Option<EncodedTerm>, object: Option<EncodedTerm>,
graph_name: Option<Option<EncodedTerm>>, graph_name: Option<EncodedTerm>,
) -> Self { ) -> Self {
Self { Self {
subject, subject,
@ -508,7 +508,7 @@ impl<I: Iterator<Item = Result<EncodedQuad>>> Iterator for FilteringEncodedQuads
pub struct InGraphQuadsIterator<I: Iterator<Item = Result<EncodedQuad>>> { pub struct InGraphQuadsIterator<I: Iterator<Item = Result<EncodedQuad>>> {
iter: I, iter: I,
graph_name: Option<EncodedTerm>, graph_name: EncodedTerm,
} }
impl<I: Iterator<Item = Result<EncodedQuad>>> Iterator for InGraphQuadsIterator<I> { impl<I: Iterator<Item = Result<EncodedQuad>>> Iterator for InGraphQuadsIterator<I> {

@ -1,10 +1,7 @@
use errors::*; use errors::*;
use model::*; use model::*;
use std::sync::Arc; use std::sync::Arc;
use store::numeric_encoder::BytesStore; use store::numeric_encoder::*;
use store::numeric_encoder::EncodedQuad;
use store::numeric_encoder::EncodedTerm;
use store::numeric_encoder::Encoder;
use store::Dataset; use store::Dataset;
use store::Graph; use store::Graph;
use store::NamedGraph; use store::NamedGraph;
@ -60,42 +57,39 @@ pub trait EncodedQuadsStore: BytesStore + Sized {
object: &EncodedTerm, object: &EncodedTerm,
) -> Result<Self::QuadsForPredicateObjectIterator>; ) -> Result<Self::QuadsForPredicateObjectIterator>;
fn quads_for_object(&self, object: &EncodedTerm) -> Result<Self::QuadsForObjectIterator>; fn quads_for_object(&self, object: &EncodedTerm) -> Result<Self::QuadsForObjectIterator>;
fn quads_for_graph( fn quads_for_graph(&self, graph_name: &EncodedTerm) -> Result<Self::QuadsForGraphIterator>;
&self,
graph_name: &Option<EncodedTerm>,
) -> Result<Self::QuadsForGraphIterator>;
fn quads_for_subject_graph( fn quads_for_subject_graph(
&self, &self,
subject: &EncodedTerm, subject: &EncodedTerm,
graph_name: &Option<EncodedTerm>, graph_name: &EncodedTerm,
) -> Result<Self::QuadsForSubjectGraphIterator>; ) -> Result<Self::QuadsForSubjectGraphIterator>;
fn quads_for_subject_predicate_graph( fn quads_for_subject_predicate_graph(
&self, &self,
subject: &EncodedTerm, subject: &EncodedTerm,
predicate: &EncodedTerm, predicate: &EncodedTerm,
graph_name: &Option<EncodedTerm>, graph_name: &EncodedTerm,
) -> Result<Self::QuadsForSubjectPredicateGraphIterator>; ) -> Result<Self::QuadsForSubjectPredicateGraphIterator>;
fn quads_for_subject_object_graph( fn quads_for_subject_object_graph(
&self, &self,
subject: &EncodedTerm, subject: &EncodedTerm,
object: &EncodedTerm, object: &EncodedTerm,
graph_name: &Option<EncodedTerm>, graph_name: &EncodedTerm,
) -> Result<Self::QuadsForSubjectObjectGraphIterator>; ) -> Result<Self::QuadsForSubjectObjectGraphIterator>;
fn quads_for_predicate_graph( fn quads_for_predicate_graph(
&self, &self,
predicate: &EncodedTerm, predicate: &EncodedTerm,
graph_name: &Option<EncodedTerm>, graph_name: &EncodedTerm,
) -> Result<Self::QuadsForPredicateGraphIterator>; ) -> Result<Self::QuadsForPredicateGraphIterator>;
fn quads_for_predicate_object_graph( fn quads_for_predicate_object_graph(
&self, &self,
predicate: &EncodedTerm, predicate: &EncodedTerm,
object: &EncodedTerm, object: &EncodedTerm,
graph_name: &Option<EncodedTerm>, graph_name: &EncodedTerm,
) -> Result<Self::QuadsForPredicateObjectGraphIterator>; ) -> Result<Self::QuadsForPredicateObjectGraphIterator>;
fn quads_for_object_graph( fn quads_for_object_graph(
&self, &self,
object: &EncodedTerm, object: &EncodedTerm,
graph_name: &Option<EncodedTerm>, graph_name: &EncodedTerm,
) -> Result<Self::QuadsForObjectGraphIterator>; ) -> Result<Self::QuadsForObjectGraphIterator>;
fn contains(&self, quad: &EncodedQuad) -> Result<bool>; fn contains(&self, quad: &EncodedQuad) -> Result<bool>;
fn insert(&self, quad: &EncodedQuad) -> Result<()>; fn insert(&self, quad: &EncodedQuad) -> Result<()>;
@ -132,7 +126,7 @@ impl<S: EncodedQuadsStore> Dataset for StoreDataset<S> {
Ok(StoreNamedGraph { Ok(StoreNamedGraph {
store: self.store.clone(), store: self.store.clone(),
name: name.clone(), name: name.clone(),
encoded_name: Some(self.store.encoder().encode_named_or_blank_node(name)?), encoded_name: self.store.encoder().encode_named_or_blank_node(name)?,
}) })
} }
@ -279,7 +273,7 @@ impl<S: EncodedQuadsStore> Dataset for StoreDataset<S> {
pub struct StoreNamedGraph<S: EncodedQuadsStore> { pub struct StoreNamedGraph<S: EncodedQuadsStore> {
store: Arc<S>, store: Arc<S>,
name: NamedOrBlankNode, name: NamedOrBlankNode,
encoded_name: Option<EncodedTerm>, encoded_name: EncodedTerm,
} }
impl<S: EncodedQuadsStore> Graph for StoreNamedGraph<S> { impl<S: EncodedQuadsStore> Graph for StoreNamedGraph<S> {
@ -390,7 +384,7 @@ impl<S: EncodedQuadsStore> Graph for StoreNamedGraph<S> {
&self &self
.store .store
.encoder() .encoder()
.encode_triple_in_graph(triple, self.encoded_name.clone())?, .encode_triple_in_graph(triple, &self.encoded_name)?,
) )
} }
@ -399,7 +393,7 @@ impl<S: EncodedQuadsStore> Graph for StoreNamedGraph<S> {
&self &self
.store .store
.encoder() .encoder()
.encode_triple_in_graph(triple, self.encoded_name.clone())?, .encode_triple_in_graph(triple, &self.encoded_name)?,
) )
} }
@ -408,7 +402,7 @@ impl<S: EncodedQuadsStore> Graph for StoreNamedGraph<S> {
&self &self
.store .store
.encoder() .encoder()
.encode_triple_in_graph(triple, self.encoded_name.clone())?, .encode_triple_in_graph(triple, &self.encoded_name)?,
) )
} }
@ -448,7 +442,7 @@ impl<S: EncodedQuadsStore> Graph for StoreDefaultGraph<S> {
fn triples(&self) -> Result<TriplesIterator<S::QuadsForGraphIterator, S>> { fn triples(&self) -> Result<TriplesIterator<S::QuadsForGraphIterator, S>> {
Ok(TriplesIterator { Ok(TriplesIterator {
iter: self.store.quads_for_graph(&None)?, iter: self.store.quads_for_graph(&ENCODED_DEFAULT_GRAPH)?,
store: self.store.clone(), store: self.store.clone(),
}) })
} }
@ -459,9 +453,10 @@ impl<S: EncodedQuadsStore> Graph for StoreDefaultGraph<S> {
) -> Result<TriplesIterator<S::QuadsForSubjectGraphIterator, S>> { ) -> Result<TriplesIterator<S::QuadsForSubjectGraphIterator, S>> {
let encoder = self.store.encoder(); let encoder = self.store.encoder();
Ok(TriplesIterator { Ok(TriplesIterator {
iter: self iter: self.store.quads_for_subject_graph(
.store &encoder.encode_named_or_blank_node(subject)?,
.quads_for_subject_graph(&encoder.encode_named_or_blank_node(subject)?, &None)?, &ENCODED_DEFAULT_GRAPH,
)?,
store: self.store.clone(), store: self.store.clone(),
}) })
} }
@ -475,7 +470,7 @@ impl<S: EncodedQuadsStore> Graph for StoreDefaultGraph<S> {
iter: self.store.quads_for_subject_predicate_graph( iter: self.store.quads_for_subject_predicate_graph(
&encoder.encode_named_or_blank_node(subject)?, &encoder.encode_named_or_blank_node(subject)?,
&encoder.encode_named_node(predicate)?, &encoder.encode_named_node(predicate)?,
&None, &ENCODED_DEFAULT_GRAPH,
)?, )?,
store: self.store.clone(), store: self.store.clone(),
}) })
@ -490,7 +485,7 @@ impl<S: EncodedQuadsStore> Graph for StoreDefaultGraph<S> {
iter: self.store.quads_for_subject_object_graph( iter: self.store.quads_for_subject_object_graph(
&encoder.encode_named_or_blank_node(subject)?, &encoder.encode_named_or_blank_node(subject)?,
&encoder.encode_term(object)?, &encoder.encode_term(object)?,
&None, &ENCODED_DEFAULT_GRAPH,
)?, )?,
store: self.store.clone(), store: self.store.clone(),
}) })
@ -501,9 +496,10 @@ impl<S: EncodedQuadsStore> Graph for StoreDefaultGraph<S> {
) -> Result<TriplesIterator<S::QuadsForPredicateGraphIterator, S>> { ) -> Result<TriplesIterator<S::QuadsForPredicateGraphIterator, S>> {
let encoder = self.store.encoder(); let encoder = self.store.encoder();
Ok(TriplesIterator { Ok(TriplesIterator {
iter: self iter: self.store.quads_for_predicate_graph(
.store &encoder.encode_named_node(predicate)?,
.quads_for_predicate_graph(&encoder.encode_named_node(predicate)?, &None)?, &ENCODED_DEFAULT_GRAPH,
)?,
store: self.store.clone(), store: self.store.clone(),
}) })
} }
@ -517,7 +513,7 @@ impl<S: EncodedQuadsStore> Graph for StoreDefaultGraph<S> {
iter: self.store.quads_for_predicate_object_graph( iter: self.store.quads_for_predicate_object_graph(
&encoder.encode_named_node(predicate)?, &encoder.encode_named_node(predicate)?,
&encoder.encode_term(object)?, &encoder.encode_term(object)?,
&None, &ENCODED_DEFAULT_GRAPH,
)?, )?,
store: self.store.clone(), store: self.store.clone(),
}) })
@ -530,32 +526,47 @@ impl<S: EncodedQuadsStore> Graph for StoreDefaultGraph<S> {
Ok(TriplesIterator { Ok(TriplesIterator {
iter: self iter: self
.store .store
.quads_for_object_graph(&encoder.encode_term(object)?, &None)?, .quads_for_object_graph(&encoder.encode_term(object)?, &ENCODED_DEFAULT_GRAPH)?,
store: self.store.clone(), store: self.store.clone(),
}) })
} }
fn contains(&self, triple: &Triple) -> Result<bool> { fn contains(&self, triple: &Triple) -> Result<bool> {
self.store self.store.contains(
.contains(&self.store.encoder().encode_triple_in_graph(triple, None)?) &self
.store
.encoder()
.encode_triple_in_graph(triple, &ENCODED_DEFAULT_GRAPH)?,
)
} }
fn insert(&self, triple: &Triple) -> Result<()> { fn insert(&self, triple: &Triple) -> Result<()> {
self.store self.store.insert(
.insert(&self.store.encoder().encode_triple_in_graph(triple, None)?) &self
.store
.encoder()
.encode_triple_in_graph(triple, &ENCODED_DEFAULT_GRAPH)?,
)
} }
fn remove(&self, triple: &Triple) -> Result<()> { fn remove(&self, triple: &Triple) -> Result<()> {
self.store self.store.remove(
.remove(&self.store.encoder().encode_triple_in_graph(triple, None)?) &self
.store
.encoder()
.encode_triple_in_graph(triple, &ENCODED_DEFAULT_GRAPH)?,
)
} }
fn len(&self) -> Result<usize> { fn len(&self) -> Result<usize> {
Ok(self.store.quads_for_graph(&None)?.count()) Ok(self.store.quads_for_graph(&ENCODED_DEFAULT_GRAPH)?.count())
} }
fn is_empty(&self) -> Result<bool> { fn is_empty(&self) -> Result<bool> {
Ok(self.store.quads_for_graph(&None)?.any(|_| true)) Ok(self
.store
.quads_for_graph(&ENCODED_DEFAULT_GRAPH)?
.any(|_| true))
} }
} }

Loading…
Cancel
Save