Avoid references to EncodedTerm

It is a small copyable struct
pull/10/head
Tpt 6 years ago
parent 5afc8b4314
commit fbd5d1f6ed
  1. 156
      src/store/memory.rs
  2. 74
      src/store/numeric_encoder.rs
  3. 104
      src/store/rocksdb.rs
  4. 193
      src/store/store.rs

@ -67,7 +67,7 @@ impl EncodedQuadsStore for MemoryStore {
for (s, pos) in &graph.spo {
for (p, os) in pos.iter() {
for o in os.iter() {
result.push(Ok(encoded_quad(s, p, o, graph_name)))
result.push(Ok(EncodedQuad::new(*s, *p, *o, *graph_name)))
}
}
}
@ -77,14 +77,14 @@ impl EncodedQuadsStore for MemoryStore {
fn quads_for_subject(
&self,
subject: &EncodedTerm,
subject: EncodedTerm,
) -> Result<<Vec<Result<EncodedQuad>> as IntoIterator>::IntoIter> {
let mut result = Vec::default();
for (graph_name, graph) in self.graph_indexes.read()?.iter() {
if let Some(pos) = graph.spo.get(subject) {
if let Some(pos) = graph.spo.get(&subject) {
for (p, os) in pos.iter() {
for o in os.iter() {
result.push(Ok(encoded_quad(subject, p, o, graph_name)))
result.push(Ok(EncodedQuad::new(subject, *p, *o, *graph_name)))
}
}
}
@ -94,15 +94,15 @@ impl EncodedQuadsStore for MemoryStore {
fn quads_for_subject_predicate(
&self,
subject: &EncodedTerm,
predicate: &EncodedTerm,
subject: EncodedTerm,
predicate: EncodedTerm,
) -> Result<<Vec<Result<EncodedQuad>> as IntoIterator>::IntoIter> {
let mut result = Vec::default();
for (graph_name, graph) in self.graph_indexes.read()?.iter() {
if let Some(pos) = graph.spo.get(subject) {
if let Some(os) = pos.get(predicate) {
if let Some(pos) = graph.spo.get(&subject) {
if let Some(os) = pos.get(&predicate) {
for o in os.iter() {
result.push(Ok(encoded_quad(subject, predicate, o, graph_name)))
result.push(Ok(EncodedQuad::new(subject, predicate, *o, *graph_name)))
}
}
}
@ -112,16 +112,21 @@ impl EncodedQuadsStore for MemoryStore {
fn quads_for_subject_predicate_object(
&self,
subject: &EncodedTerm,
predicate: &EncodedTerm,
object: &EncodedTerm,
subject: EncodedTerm,
predicate: EncodedTerm,
object: EncodedTerm,
) -> Result<<Vec<Result<EncodedQuad>> as IntoIterator>::IntoIter> {
let mut result = Vec::default();
for (graph_name, graph) in self.graph_indexes.read()?.iter() {
if let Some(pos) = graph.spo.get(subject) {
if let Some(os) = pos.get(predicate) {
if os.contains(object) {
result.push(Ok(encoded_quad(subject, predicate, object, graph_name)))
if let Some(pos) = graph.spo.get(&subject) {
if let Some(os) = pos.get(&predicate) {
if os.contains(&object) {
result.push(Ok(EncodedQuad::new(
subject,
predicate,
object,
*graph_name,
)))
}
}
}
@ -131,15 +136,15 @@ impl EncodedQuadsStore for MemoryStore {
fn quads_for_subject_object(
&self,
subject: &EncodedTerm,
object: &EncodedTerm,
subject: EncodedTerm,
object: EncodedTerm,
) -> Result<<Vec<Result<EncodedQuad>> as IntoIterator>::IntoIter> {
let mut result = Vec::default();
for (graph_name, graph) in self.graph_indexes.read()?.iter() {
if let Some(sps) = graph.osp.get(object) {
if let Some(ps) = sps.get(subject) {
if let Some(sps) = graph.osp.get(&object) {
if let Some(ps) = sps.get(&subject) {
for p in ps.iter() {
result.push(Ok(encoded_quad(subject, p, object, graph_name)))
result.push(Ok(EncodedQuad::new(subject, *p, object, *graph_name)))
}
}
}
@ -149,14 +154,14 @@ impl EncodedQuadsStore for MemoryStore {
fn quads_for_predicate(
&self,
predicate: &EncodedTerm,
predicate: EncodedTerm,
) -> Result<<Vec<Result<EncodedQuad>> as IntoIterator>::IntoIter> {
let mut result = Vec::default();
for (graph_name, graph) in self.graph_indexes.read()?.iter() {
if let Some(oss) = graph.pos.get(predicate) {
if let Some(oss) = graph.pos.get(&predicate) {
for (o, ss) in oss.iter() {
for s in ss.iter() {
result.push(Ok(encoded_quad(s, predicate, o, graph_name)))
result.push(Ok(EncodedQuad::new(*s, predicate, *o, *graph_name)))
}
}
}
@ -166,15 +171,15 @@ impl EncodedQuadsStore for MemoryStore {
fn quads_for_predicate_object(
&self,
predicate: &EncodedTerm,
object: &EncodedTerm,
predicate: EncodedTerm,
object: EncodedTerm,
) -> Result<<Vec<Result<EncodedQuad>> as IntoIterator>::IntoIter> {
let mut result = Vec::default();
for (graph_name, graph) in self.graph_indexes.read()?.iter() {
if let Some(oss) = graph.pos.get(predicate) {
if let Some(ss) = oss.get(object) {
if let Some(oss) = graph.pos.get(&predicate) {
if let Some(ss) = oss.get(&object) {
for s in ss.iter() {
result.push(Ok(encoded_quad(s, predicate, object, graph_name)))
result.push(Ok(EncodedQuad::new(*s, predicate, object, *graph_name)))
}
}
}
@ -184,14 +189,14 @@ impl EncodedQuadsStore for MemoryStore {
fn quads_for_object(
&self,
object: &EncodedTerm,
object: EncodedTerm,
) -> Result<<Vec<Result<EncodedQuad>> as IntoIterator>::IntoIter> {
let mut result = Vec::default();
for (graph_name, graph) in self.graph_indexes.read()?.iter() {
if let Some(sps) = graph.osp.get(object) {
if let Some(sps) = graph.osp.get(&object) {
for (s, ps) in sps.iter() {
for p in ps.iter() {
result.push(Ok(encoded_quad(s, p, object, graph_name)))
result.push(Ok(EncodedQuad::new(*s, *p, object, *graph_name)))
}
}
}
@ -201,14 +206,14 @@ impl EncodedQuadsStore for MemoryStore {
fn quads_for_graph(
&self,
graph_name: &EncodedTerm,
graph_name: EncodedTerm,
) -> Result<<Vec<Result<EncodedQuad>> as IntoIterator>::IntoIter> {
let mut result = Vec::default();
if let Some(graph) = self.graph_indexes.read()?.get(graph_name) {
if let Some(graph) = self.graph_indexes.read()?.get(&graph_name) {
for (s, pos) in &graph.spo {
for (p, os) in pos.iter() {
for o in os.iter() {
result.push(Ok(encoded_quad(s, p, o, graph_name)))
result.push(Ok(EncodedQuad::new(*s, *p, *o, graph_name)))
}
}
}
@ -218,15 +223,15 @@ impl EncodedQuadsStore for MemoryStore {
fn quads_for_subject_graph(
&self,
subject: &EncodedTerm,
graph_name: &EncodedTerm,
subject: EncodedTerm,
graph_name: EncodedTerm,
) -> Result<<Vec<Result<EncodedQuad>> as IntoIterator>::IntoIter> {
let mut result = Vec::default();
if let Some(graph) = self.graph_indexes.read()?.get(graph_name) {
if let Some(pos) = graph.spo.get(subject) {
if let Some(graph) = self.graph_indexes.read()?.get(&graph_name) {
if let Some(pos) = graph.spo.get(&subject) {
for (p, os) in pos.iter() {
for o in os.iter() {
result.push(Ok(encoded_quad(subject, p, o, graph_name)))
result.push(Ok(EncodedQuad::new(subject, *p, *o, graph_name)))
}
}
}
@ -236,16 +241,16 @@ impl EncodedQuadsStore for MemoryStore {
fn quads_for_subject_predicate_graph(
&self,
subject: &EncodedTerm,
predicate: &EncodedTerm,
graph_name: &EncodedTerm,
subject: EncodedTerm,
predicate: EncodedTerm,
graph_name: EncodedTerm,
) -> Result<<Vec<Result<EncodedQuad>> as IntoIterator>::IntoIter> {
let mut result = Vec::default();
if let Some(graph) = self.graph_indexes.read()?.get(graph_name) {
if let Some(pos) = graph.spo.get(subject) {
if let Some(os) = pos.get(predicate) {
if let Some(graph) = self.graph_indexes.read()?.get(&graph_name) {
if let Some(pos) = graph.spo.get(&subject) {
if let Some(os) = pos.get(&predicate) {
for o in os.iter() {
result.push(Ok(encoded_quad(subject, predicate, o, graph_name)))
result.push(Ok(EncodedQuad::new(subject, predicate, *o, graph_name)))
}
}
}
@ -255,16 +260,16 @@ impl EncodedQuadsStore for MemoryStore {
fn quads_for_subject_object_graph(
&self,
subject: &EncodedTerm,
object: &EncodedTerm,
graph_name: &EncodedTerm,
subject: EncodedTerm,
object: EncodedTerm,
graph_name: EncodedTerm,
) -> Result<<Vec<Result<EncodedQuad>> as IntoIterator>::IntoIter> {
let mut result = Vec::default();
if let Some(graph) = self.graph_indexes.read()?.get(graph_name) {
if let Some(sps) = graph.osp.get(object) {
if let Some(ps) = sps.get(subject) {
if let Some(graph) = self.graph_indexes.read()?.get(&graph_name) {
if let Some(sps) = graph.osp.get(&object) {
if let Some(ps) = sps.get(&subject) {
for p in ps.iter() {
result.push(Ok(encoded_quad(subject, p, object, graph_name)))
result.push(Ok(EncodedQuad::new(subject, *p, object, graph_name)))
}
}
}
@ -274,15 +279,15 @@ impl EncodedQuadsStore for MemoryStore {
fn quads_for_predicate_graph(
&self,
predicate: &EncodedTerm,
graph_name: &EncodedTerm,
predicate: EncodedTerm,
graph_name: EncodedTerm,
) -> Result<<Vec<Result<EncodedQuad>> as IntoIterator>::IntoIter> {
let mut result = Vec::default();
if let Some(graph) = self.graph_indexes.read()?.get(graph_name) {
if let Some(oss) = graph.pos.get(predicate) {
if let Some(graph) = self.graph_indexes.read()?.get(&graph_name) {
if let Some(oss) = graph.pos.get(&predicate) {
for (o, ss) in oss.iter() {
for s in ss.iter() {
result.push(Ok(encoded_quad(s, predicate, o, graph_name)))
result.push(Ok(EncodedQuad::new(*s, predicate, *o, graph_name)))
}
}
}
@ -292,16 +297,16 @@ impl EncodedQuadsStore for MemoryStore {
fn quads_for_predicate_object_graph(
&self,
predicate: &EncodedTerm,
object: &EncodedTerm,
graph_name: &EncodedTerm,
predicate: EncodedTerm,
object: EncodedTerm,
graph_name: EncodedTerm,
) -> Result<<Vec<Result<EncodedQuad>> as IntoIterator>::IntoIter> {
let mut result = Vec::default();
if let Some(graph) = self.graph_indexes.read()?.get(graph_name) {
if let Some(oss) = graph.pos.get(predicate) {
if let Some(ss) = oss.get(object) {
if let Some(graph) = self.graph_indexes.read()?.get(&graph_name) {
if let Some(oss) = graph.pos.get(&predicate) {
if let Some(ss) = oss.get(&object) {
for s in ss.iter() {
result.push(Ok(encoded_quad(s, predicate, object, graph_name)))
result.push(Ok(EncodedQuad::new(*s, predicate, object, graph_name)))
}
}
}
@ -311,15 +316,15 @@ impl EncodedQuadsStore for MemoryStore {
fn quads_for_object_graph(
&self,
object: &EncodedTerm,
graph_name: &EncodedTerm,
object: EncodedTerm,
graph_name: EncodedTerm,
) -> Result<<Vec<Result<EncodedQuad>> as IntoIterator>::IntoIter> {
let mut result = Vec::default();
if let Some(graph) = self.graph_indexes.read()?.get(graph_name) {
if let Some(sps) = graph.osp.get(object) {
if let Some(graph) = self.graph_indexes.read()?.get(&graph_name) {
if let Some(sps) = graph.osp.get(&object) {
for (s, ps) in sps.iter() {
for p in ps.iter() {
result.push(Ok(encoded_quad(s, p, object, graph_name)))
result.push(Ok(EncodedQuad::new(*s, *p, object, graph_name)))
}
}
}
@ -439,12 +444,3 @@ impl EncodedQuadsStore for MemoryStore {
Ok(())
}
}
fn encoded_quad(
subject: &EncodedTerm,
predicate: &EncodedTerm,
object: &EncodedTerm,
graph_name: &EncodedTerm,
) -> EncodedQuad {
EncodedQuad::new(*subject, *predicate, *object, *graph_name)
}

@ -141,58 +141,58 @@ impl<R: Read> TermReader for R {
}
pub trait TermWriter {
fn write_term(&mut self, term: &EncodedTerm) -> Result<()>;
fn write_term(&mut self, term: EncodedTerm) -> Result<()>;
fn write_spog_quad(&mut self, quad: &EncodedQuad) -> Result<()>;
fn write_posg_quad(&mut self, quad: &EncodedQuad) -> Result<()>;
fn write_ospg_quad(&mut self, quad: &EncodedQuad) -> Result<()>;
}
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())?;
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::LangStringLiteral {
value_id,
language_id,
} => {
self.write_u64::<NetworkEndian>(*language_id)?;
self.write_u64::<NetworkEndian>(*value_id)?;
self.write_u64::<NetworkEndian>(language_id)?;
self.write_u64::<NetworkEndian>(value_id)?;
}
EncodedTerm::TypedLiteral {
value_id,
datatype_id,
} => {
self.write_u64::<NetworkEndian>(*datatype_id)?;
self.write_u64::<NetworkEndian>(*value_id)?;
self.write_u64::<NetworkEndian>(datatype_id)?;
self.write_u64::<NetworkEndian>(value_id)?;
}
}
Ok(())
}
fn write_spog_quad(&mut self, quad: &EncodedQuad) -> Result<()> {
self.write_term(&quad.subject)?;
self.write_term(&quad.predicate)?;
self.write_term(&quad.object)?;
self.write_term(&quad.graph_name)?;
self.write_term(quad.subject)?;
self.write_term(quad.predicate)?;
self.write_term(quad.object)?;
self.write_term(quad.graph_name)?;
Ok(())
}
fn write_posg_quad(&mut self, quad: &EncodedQuad) -> Result<()> {
self.write_term(&quad.predicate)?;
self.write_term(&quad.object)?;
self.write_term(&quad.subject)?;
self.write_term(&quad.graph_name)?;
self.write_term(quad.predicate)?;
self.write_term(quad.object)?;
self.write_term(quad.subject)?;
self.write_term(quad.graph_name)?;
Ok(())
}
fn write_ospg_quad(&mut self, quad: &EncodedQuad) -> Result<()> {
self.write_term(&quad.object)?;
self.write_term(&quad.subject)?;
self.write_term(&quad.predicate)?;
self.write_term(&quad.graph_name)?;
self.write_term(quad.object)?;
self.write_term(quad.subject)?;
self.write_term(quad.predicate)?;
self.write_term(quad.graph_name)?;
Ok(())
}
}
@ -260,41 +260,41 @@ impl<S: BytesStore> Encoder<S> {
pub fn encode_triple_in_graph(
&self,
triple: &Triple,
graph_name: &EncodedTerm,
graph_name: EncodedTerm,
) -> Result<EncodedQuad> {
Ok(EncodedQuad {
subject: self.encode_named_or_blank_node(triple.subject())?,
predicate: self.encode_named_node(triple.predicate())?,
object: self.encode_term(triple.object())?,
graph_name: *graph_name,
graph_name,
})
}
pub fn decode_term(&self, encoded: &EncodedTerm) -> Result<Term> {
pub fn decode_term(&self, encoded: EncodedTerm) -> Result<Term> {
match encoded {
EncodedTerm::DefaultGraph {} => Err("The default graph tag is not a valid term".into()),
EncodedTerm::NamedNode { iri_id } => {
Ok(NamedNode::from(self.decode_url_value(*iri_id)?).into())
Ok(NamedNode::from(self.decode_url_value(iri_id)?).into())
}
EncodedTerm::BlankNode(id) => Ok(BlankNode::from(*id).into()),
EncodedTerm::BlankNode(id) => Ok(BlankNode::from(id).into()),
EncodedTerm::LangStringLiteral {
value_id,
language_id,
} => Ok(Literal::new_language_tagged_literal(
self.decode_str_value(*value_id)?,
self.decode_str_value(*language_id)?,
self.decode_str_value(value_id)?,
self.decode_str_value(language_id)?,
).into()),
EncodedTerm::TypedLiteral {
value_id,
datatype_id,
} => Ok(Literal::new_typed_literal(
self.decode_str_value(*value_id)?,
NamedNode::from(self.decode_url_value(*datatype_id)?),
self.decode_str_value(value_id)?,
NamedNode::from(self.decode_url_value(datatype_id)?),
).into()),
}
}
pub fn decode_named_or_blank_node(&self, encoded: &EncodedTerm) -> Result<NamedOrBlankNode> {
pub fn decode_named_or_blank_node(&self, encoded: EncodedTerm) -> Result<NamedOrBlankNode> {
match self.decode_term(encoded)? {
Term::NamedNode(named_node) => Ok(named_node.into()),
Term::BlankNode(blank_node) => Ok(blank_node.into()),
@ -302,7 +302,7 @@ impl<S: BytesStore> Encoder<S> {
}
}
pub fn decode_named_node(&self, encoded: &EncodedTerm) -> Result<NamedNode> {
pub fn decode_named_node(&self, encoded: EncodedTerm) -> Result<NamedNode> {
match self.decode_term(encoded)? {
Term::NamedNode(named_node) => Ok(named_node),
Term::BlankNode(_) => Err("A blank node has been found instead of a named node".into()),
@ -312,20 +312,20 @@ impl<S: BytesStore> Encoder<S> {
pub fn decode_triple(&self, encoded: &EncodedQuad) -> Result<Triple> {
Ok(Triple::new(
self.decode_named_or_blank_node(&encoded.subject)?,
self.decode_named_node(&encoded.predicate)?,
self.decode_term(&encoded.object)?,
self.decode_named_or_blank_node(encoded.subject)?,
self.decode_named_node(encoded.predicate)?,
self.decode_term(encoded.object)?,
))
}
pub fn decode_quad(&self, encoded: &EncodedQuad) -> Result<Quad> {
Ok(Quad::new(
self.decode_named_or_blank_node(&encoded.subject)?,
self.decode_named_node(&encoded.predicate)?,
self.decode_term(&encoded.object)?,
self.decode_named_or_blank_node(encoded.subject)?,
self.decode_named_node(encoded.predicate)?,
self.decode_term(encoded.object)?,
match encoded.graph_name {
EncodedTerm::DefaultGraph {} => None,
ref graph_name => Some(self.decode_named_or_blank_node(graph_name)?),
graph_name => Some(self.decode_named_or_blank_node(graph_name)?),
},
))
}

@ -124,169 +124,169 @@ impl EncodedQuadsStore for RocksDbStore {
fn quads_for_subject(
&self,
subject: &EncodedTerm,
subject: EncodedTerm,
) -> Result<FilteringEncodedQuadsIterator<SPOGIndexIterator>> {
let mut iter = self.db.raw_iterator_cf(self.spog_cf)?;
iter.seek(&encode_term(subject)?);
Ok(FilteringEncodedQuadsIterator {
iter: SPOGIndexIterator { iter },
filter: EncodedQuadPattern::new(Some(*subject), None, None, None),
filter: EncodedQuadPattern::new(Some(subject), None, None, None),
})
}
fn quads_for_subject_predicate(
&self,
subject: &EncodedTerm,
predicate: &EncodedTerm,
subject: EncodedTerm,
predicate: EncodedTerm,
) -> Result<FilteringEncodedQuadsIterator<SPOGIndexIterator>> {
let mut iter = self.db.raw_iterator_cf(self.spog_cf)?;
iter.seek(&encode_term_pair(subject, predicate)?);
Ok(FilteringEncodedQuadsIterator {
iter: SPOGIndexIterator { iter },
filter: EncodedQuadPattern::new(Some(*subject), Some(*predicate), None, None),
filter: EncodedQuadPattern::new(Some(subject), Some(predicate), None, None),
})
}
fn quads_for_subject_predicate_object(
&self,
subject: &EncodedTerm,
predicate: &EncodedTerm,
object: &EncodedTerm,
subject: EncodedTerm,
predicate: EncodedTerm,
object: EncodedTerm,
) -> Result<FilteringEncodedQuadsIterator<SPOGIndexIterator>> {
let mut iter = self.db.raw_iterator_cf(self.spog_cf)?;
iter.seek(&encode_term_triple(subject, predicate, object)?);
Ok(FilteringEncodedQuadsIterator {
iter: SPOGIndexIterator { iter },
filter: EncodedQuadPattern::new(Some(*subject), Some(*predicate), Some(*object), None),
filter: EncodedQuadPattern::new(Some(subject), Some(predicate), Some(object), None),
})
}
fn quads_for_subject_object(
&self,
subject: &EncodedTerm,
object: &EncodedTerm,
subject: EncodedTerm,
object: EncodedTerm,
) -> Result<FilteringEncodedQuadsIterator<OSPGIndexIterator>> {
let mut iter = self.db.raw_iterator_cf(self.spog_cf)?;
iter.seek(&encode_term_pair(object, subject)?);
Ok(FilteringEncodedQuadsIterator {
iter: OSPGIndexIterator { iter },
filter: EncodedQuadPattern::new(Some(*subject), None, Some(*object), None),
filter: EncodedQuadPattern::new(Some(subject), None, Some(object), None),
})
}
fn quads_for_predicate(
&self,
predicate: &EncodedTerm,
predicate: EncodedTerm,
) -> Result<FilteringEncodedQuadsIterator<POSGIndexIterator>> {
let mut iter = self.db.raw_iterator_cf(self.posg_cf)?;
iter.seek(&encode_term(predicate)?);
Ok(FilteringEncodedQuadsIterator {
iter: POSGIndexIterator { iter },
filter: EncodedQuadPattern::new(None, Some(*predicate), None, None),
filter: EncodedQuadPattern::new(None, Some(predicate), None, None),
})
}
fn quads_for_predicate_object(
&self,
predicate: &EncodedTerm,
object: &EncodedTerm,
predicate: EncodedTerm,
object: EncodedTerm,
) -> Result<FilteringEncodedQuadsIterator<POSGIndexIterator>> {
let mut iter = self.db.raw_iterator_cf(self.spog_cf)?;
iter.seek(&encode_term_pair(predicate, object)?);
Ok(FilteringEncodedQuadsIterator {
iter: POSGIndexIterator { iter },
filter: EncodedQuadPattern::new(None, Some(*predicate), Some(*object), None),
filter: EncodedQuadPattern::new(None, Some(predicate), Some(object), None),
})
}
fn quads_for_object(
&self,
object: &EncodedTerm,
object: EncodedTerm,
) -> Result<FilteringEncodedQuadsIterator<OSPGIndexIterator>> {
let mut iter = self.db.raw_iterator_cf(self.ospg_cf)?;
iter.seek(&encode_term(&object)?);
iter.seek(&encode_term(object)?);
Ok(FilteringEncodedQuadsIterator {
iter: OSPGIndexIterator { iter },
filter: EncodedQuadPattern::new(None, None, Some(*object), None),
filter: EncodedQuadPattern::new(None, None, Some(object), None),
})
}
fn quads_for_graph(
&self,
graph_name: &EncodedTerm,
graph_name: EncodedTerm,
) -> Result<InGraphQuadsIterator<SPOGIndexIterator>> {
Ok(InGraphQuadsIterator {
iter: self.quads()?,
graph_name: *graph_name,
graph_name,
})
}
fn quads_for_subject_graph(
&self,
subject: &EncodedTerm,
graph_name: &EncodedTerm,
subject: EncodedTerm,
graph_name: EncodedTerm,
) -> Result<InGraphQuadsIterator<FilteringEncodedQuadsIterator<SPOGIndexIterator>>> {
Ok(InGraphQuadsIterator {
iter: self.quads_for_subject(subject)?,
graph_name: *graph_name,
graph_name,
})
}
fn quads_for_subject_predicate_graph(
&self,
subject: &EncodedTerm,
predicate: &EncodedTerm,
graph_name: &EncodedTerm,
subject: EncodedTerm,
predicate: EncodedTerm,
graph_name: EncodedTerm,
) -> Result<InGraphQuadsIterator<FilteringEncodedQuadsIterator<SPOGIndexIterator>>> {
Ok(InGraphQuadsIterator {
iter: self.quads_for_subject_predicate(subject, predicate)?,
graph_name: *graph_name,
graph_name,
})
}
fn quads_for_subject_object_graph(
&self,
subject: &EncodedTerm,
object: &EncodedTerm,
graph_name: &EncodedTerm,
subject: EncodedTerm,
object: EncodedTerm,
graph_name: EncodedTerm,
) -> Result<InGraphQuadsIterator<FilteringEncodedQuadsIterator<OSPGIndexIterator>>> {
Ok(InGraphQuadsIterator {
iter: self.quads_for_subject_object(subject, object)?,
graph_name: *graph_name,
graph_name,
})
}
fn quads_for_predicate_graph(
&self,
predicate: &EncodedTerm,
graph_name: &EncodedTerm,
predicate: EncodedTerm,
graph_name: EncodedTerm,
) -> Result<InGraphQuadsIterator<FilteringEncodedQuadsIterator<POSGIndexIterator>>> {
Ok(InGraphQuadsIterator {
iter: self.quads_for_predicate(predicate)?,
graph_name: *graph_name,
graph_name,
})
}
fn quads_for_predicate_object_graph(
&self,
predicate: &EncodedTerm,
object: &EncodedTerm,
graph_name: &EncodedTerm,
predicate: EncodedTerm,
object: EncodedTerm,
graph_name: EncodedTerm,
) -> Result<InGraphQuadsIterator<FilteringEncodedQuadsIterator<POSGIndexIterator>>> {
Ok(InGraphQuadsIterator {
iter: self.quads_for_predicate_object(predicate, object)?,
graph_name: *graph_name,
graph_name,
})
}
fn quads_for_object_graph(
&self,
object: &EncodedTerm,
graph_name: &EncodedTerm,
object: EncodedTerm,
graph_name: EncodedTerm,
) -> Result<InGraphQuadsIterator<FilteringEncodedQuadsIterator<OSPGIndexIterator>>> {
Ok(InGraphQuadsIterator {
iter: self.quads_for_object(object)?,
graph_name: *graph_name,
graph_name,
})
}
@ -387,24 +387,24 @@ impl EncodedQuadPattern {
}
}
fn encode_term(t: &EncodedTerm) -> Result<Vec<u8>> {
fn encode_term(t: EncodedTerm) -> Result<Vec<u8>> {
let mut vec = Vec::default();
vec.write_term(&t)?;
vec.write_term(t)?;
Ok(vec)
}
fn encode_term_pair(t1: &EncodedTerm, t2: &EncodedTerm) -> Result<Vec<u8>> {
fn encode_term_pair(t1: EncodedTerm, t2: EncodedTerm) -> Result<Vec<u8>> {
let mut vec = Vec::default();
vec.write_term(&t1)?;
vec.write_term(&t2)?;
vec.write_term(t1)?;
vec.write_term(t2)?;
Ok(vec)
}
fn encode_term_triple(t1: &EncodedTerm, t2: &EncodedTerm, t3: &EncodedTerm) -> Result<Vec<u8>> {
fn encode_term_triple(t1: EncodedTerm, t2: EncodedTerm, t3: EncodedTerm) -> Result<Vec<u8>> {
let mut vec = Vec::default();
vec.write_term(&t1)?;
vec.write_term(&t2)?;
vec.write_term(&t3)?;
vec.write_term(t1)?;
vec.write_term(t2)?;
vec.write_term(t3)?;
Ok(vec)
}

@ -33,66 +33,66 @@ pub trait EncodedQuadsStore: BytesStore + Sized {
}
fn quads(&self) -> Result<Self::QuadsIterator>;
fn quads_for_subject(&self, subject: &EncodedTerm) -> Result<Self::QuadsForSubjectIterator>;
fn quads_for_subject(&self, subject: EncodedTerm) -> Result<Self::QuadsForSubjectIterator>;
fn quads_for_subject_predicate(
&self,
subject: &EncodedTerm,
predicate: &EncodedTerm,
subject: EncodedTerm,
predicate: EncodedTerm,
) -> Result<Self::QuadsForSubjectPredicateIterator>;
fn quads_for_subject_predicate_object(
&self,
subject: &EncodedTerm,
predicate: &EncodedTerm,
object: &EncodedTerm,
subject: EncodedTerm,
predicate: EncodedTerm,
object: EncodedTerm,
) -> Result<Self::QuadsForSubjectPredicateObjectIterator>;
fn quads_for_subject_object(
&self,
subject: &EncodedTerm,
object: &EncodedTerm,
subject: EncodedTerm,
object: EncodedTerm,
) -> Result<Self::QuadsForSubjectObjectIterator>;
fn quads_for_predicate(
&self,
predicate: &EncodedTerm,
predicate: EncodedTerm,
) -> Result<Self::QuadsForPredicateIterator>;
fn quads_for_predicate_object(
&self,
predicate: &EncodedTerm,
object: &EncodedTerm,
predicate: EncodedTerm,
object: EncodedTerm,
) -> Result<Self::QuadsForPredicateObjectIterator>;
fn quads_for_object(&self, object: &EncodedTerm) -> Result<Self::QuadsForObjectIterator>;
fn quads_for_graph(&self, graph_name: &EncodedTerm) -> Result<Self::QuadsForGraphIterator>;
fn quads_for_object(&self, object: EncodedTerm) -> Result<Self::QuadsForObjectIterator>;
fn quads_for_graph(&self, graph_name: EncodedTerm) -> Result<Self::QuadsForGraphIterator>;
fn quads_for_subject_graph(
&self,
subject: &EncodedTerm,
graph_name: &EncodedTerm,
subject: EncodedTerm,
graph_name: EncodedTerm,
) -> Result<Self::QuadsForSubjectGraphIterator>;
fn quads_for_subject_predicate_graph(
&self,
subject: &EncodedTerm,
predicate: &EncodedTerm,
graph_name: &EncodedTerm,
subject: EncodedTerm,
predicate: EncodedTerm,
graph_name: EncodedTerm,
) -> Result<Self::QuadsForSubjectPredicateGraphIterator>;
fn quads_for_subject_object_graph(
&self,
subject: &EncodedTerm,
object: &EncodedTerm,
graph_name: &EncodedTerm,
subject: EncodedTerm,
object: EncodedTerm,
graph_name: EncodedTerm,
) -> Result<Self::QuadsForSubjectObjectGraphIterator>;
fn quads_for_predicate_graph(
&self,
predicate: &EncodedTerm,
graph_name: &EncodedTerm,
predicate: EncodedTerm,
graph_name: EncodedTerm,
) -> Result<Self::QuadsForPredicateGraphIterator>;
fn quads_for_predicate_object_graph(
&self,
predicate: &EncodedTerm,
object: &EncodedTerm,
graph_name: &EncodedTerm,
predicate: EncodedTerm,
object: EncodedTerm,
graph_name: EncodedTerm,
) -> Result<Self::QuadsForPredicateObjectGraphIterator>;
fn quads_for_object_graph(
&self,
object: &EncodedTerm,
graph_name: &EncodedTerm,
object: EncodedTerm,
graph_name: EncodedTerm,
) -> Result<Self::QuadsForObjectGraphIterator>;
fn contains(&self, quad: &EncodedQuad) -> Result<bool>;
fn insert(&self, quad: &EncodedQuad) -> Result<()>;
@ -160,7 +160,7 @@ impl<S: EncodedQuadsStore> Dataset for StoreDataset<S> {
Ok(QuadsIterator {
iter: self
.store
.quads_for_subject(&encoder.encode_named_or_blank_node(subject)?)?,
.quads_for_subject(encoder.encode_named_or_blank_node(subject)?)?,
store: self.store.clone(),
})
}
@ -173,8 +173,8 @@ impl<S: EncodedQuadsStore> Dataset for StoreDataset<S> {
let encoder = self.store.encoder();
Ok(QuadsIterator {
iter: self.store.quads_for_subject_predicate(
&encoder.encode_named_or_blank_node(subject)?,
&encoder.encode_named_node(predicate)?,
encoder.encode_named_or_blank_node(subject)?,
encoder.encode_named_node(predicate)?,
)?,
store: self.store.clone(),
})
@ -189,9 +189,9 @@ impl<S: EncodedQuadsStore> Dataset for StoreDataset<S> {
let encoder = self.store.encoder();
Ok(QuadsIterator {
iter: self.store.quads_for_subject_predicate_object(
&encoder.encode_named_or_blank_node(subject)?,
&encoder.encode_named_node(predicate)?,
&encoder.encode_term(object)?,
encoder.encode_named_or_blank_node(subject)?,
encoder.encode_named_node(predicate)?,
encoder.encode_term(object)?,
)?,
store: self.store.clone(),
})
@ -205,8 +205,8 @@ impl<S: EncodedQuadsStore> Dataset for StoreDataset<S> {
let encoder = self.store.encoder();
Ok(QuadsIterator {
iter: self.store.quads_for_subject_object(
&encoder.encode_named_or_blank_node(subject)?,
&encoder.encode_term(object)?,
encoder.encode_named_or_blank_node(subject)?,
encoder.encode_term(object)?,
)?,
store: self.store.clone(),
})
@ -220,7 +220,7 @@ impl<S: EncodedQuadsStore> Dataset for StoreDataset<S> {
Ok(QuadsIterator {
iter: self
.store
.quads_for_predicate(&encoder.encode_named_node(predicate)?)?,
.quads_for_predicate(encoder.encode_named_node(predicate)?)?,
store: self.store.clone(),
})
}
@ -233,8 +233,8 @@ impl<S: EncodedQuadsStore> Dataset for StoreDataset<S> {
let encoder = self.store.encoder();
Ok(QuadsIterator {
iter: self.store.quads_for_predicate_object(
&encoder.encode_named_node(predicate)?,
&encoder.encode_term(object)?,
encoder.encode_named_node(predicate)?,
encoder.encode_term(object)?,
)?,
store: self.store.clone(),
})
@ -246,7 +246,7 @@ impl<S: EncodedQuadsStore> Dataset for StoreDataset<S> {
) -> Result<QuadsIterator<S::QuadsForObjectIterator, S>> {
let encoder = self.store.encoder();
Ok(QuadsIterator {
iter: self.store.quads_for_object(&encoder.encode_term(object)?)?,
iter: self.store.quads_for_object(encoder.encode_term(object)?)?,
store: self.store.clone(),
})
}
@ -328,7 +328,7 @@ impl<S: EncodedQuadsStore> Graph for StoreNamedGraph<S> {
fn triples(&self) -> Result<TriplesIterator<S::QuadsForGraphIterator, S>> {
Ok(TriplesIterator {
iter: self.store.quads_for_graph(&self.encoded_name)?,
iter: self.store.quads_for_graph(self.encoded_name)?,
store: self.store.clone(),
})
}
@ -340,8 +340,8 @@ impl<S: EncodedQuadsStore> Graph for StoreNamedGraph<S> {
let encoder = self.store.encoder();
Ok(TriplesIterator {
iter: self.store.quads_for_subject_graph(
&encoder.encode_named_or_blank_node(subject)?,
&self.encoded_name,
encoder.encode_named_or_blank_node(subject)?,
self.encoded_name,
)?,
store: self.store.clone(),
})
@ -354,9 +354,9 @@ impl<S: EncodedQuadsStore> Graph for StoreNamedGraph<S> {
let encoder = self.store.encoder();
Ok(ObjectsIterator {
iter: self.store.quads_for_subject_predicate_graph(
&encoder.encode_named_or_blank_node(subject)?,
&encoder.encode_named_node(predicate)?,
&self.encoded_name,
encoder.encode_named_or_blank_node(subject)?,
encoder.encode_named_node(predicate)?,
self.encoded_name,
)?,
store: self.store.clone(),
})
@ -369,9 +369,9 @@ impl<S: EncodedQuadsStore> Graph for StoreNamedGraph<S> {
let encoder = self.store.encoder();
Ok(PredicatesIterator {
iter: self.store.quads_for_subject_object_graph(
&encoder.encode_named_or_blank_node(subject)?,
&encoder.encode_term(object)?,
&self.encoded_name,
encoder.encode_named_or_blank_node(subject)?,
encoder.encode_term(object)?,
self.encoded_name,
)?,
store: self.store.clone(),
})
@ -383,8 +383,8 @@ impl<S: EncodedQuadsStore> Graph for StoreNamedGraph<S> {
let encoder = self.store.encoder();
Ok(TriplesIterator {
iter: self.store.quads_for_predicate_graph(
&encoder.encode_named_node(predicate)?,
&self.encoded_name,
encoder.encode_named_node(predicate)?,
self.encoded_name,
)?,
store: self.store.clone(),
})
@ -397,9 +397,9 @@ impl<S: EncodedQuadsStore> Graph for StoreNamedGraph<S> {
let encoder = self.store.encoder();
Ok(SubjectsIterator {
iter: self.store.quads_for_predicate_object_graph(
&encoder.encode_named_node(predicate)?,
&encoder.encode_term(object)?,
&self.encoded_name,
encoder.encode_named_node(predicate)?,
encoder.encode_term(object)?,
self.encoded_name,
)?,
store: self.store.clone(),
})
@ -412,7 +412,7 @@ impl<S: EncodedQuadsStore> Graph for StoreNamedGraph<S> {
Ok(TriplesIterator {
iter: self
.store
.quads_for_object_graph(&encoder.encode_term(object)?, &self.encoded_name)?,
.quads_for_object_graph(encoder.encode_term(object)?, self.encoded_name)?,
store: self.store.clone(),
})
}
@ -422,7 +422,7 @@ impl<S: EncodedQuadsStore> Graph for StoreNamedGraph<S> {
&self
.store
.encoder()
.encode_triple_in_graph(triple, &self.encoded_name)?,
.encode_triple_in_graph(triple, self.encoded_name)?,
)
}
@ -431,7 +431,7 @@ impl<S: EncodedQuadsStore> Graph for StoreNamedGraph<S> {
&self
.store
.encoder()
.encode_triple_in_graph(triple, &self.encoded_name)?,
.encode_triple_in_graph(triple, self.encoded_name)?,
)
}
@ -440,19 +440,16 @@ impl<S: EncodedQuadsStore> Graph for StoreNamedGraph<S> {
&self
.store
.encoder()
.encode_triple_in_graph(triple, &self.encoded_name)?,
.encode_triple_in_graph(triple, self.encoded_name)?,
)
}
fn len(&self) -> Result<usize> {
Ok(self.store.quads_for_graph(&self.encoded_name)?.count())
Ok(self.store.quads_for_graph(self.encoded_name)?.count())
}
fn is_empty(&self) -> Result<bool> {
Ok(self
.store
.quads_for_graph(&self.encoded_name)?
.any(|_| true))
Ok(self.store.quads_for_graph(self.encoded_name)?.any(|_| true))
}
}
@ -489,7 +486,7 @@ impl<S: EncodedQuadsStore> Graph for StoreDefaultGraph<S> {
fn triples(&self) -> Result<TriplesIterator<S::QuadsForGraphIterator, S>> {
Ok(TriplesIterator {
iter: self.store.quads_for_graph(&ENCODED_DEFAULT_GRAPH)?,
iter: self.store.quads_for_graph(ENCODED_DEFAULT_GRAPH)?,
store: self.store.clone(),
})
}
@ -501,8 +498,8 @@ impl<S: EncodedQuadsStore> Graph for StoreDefaultGraph<S> {
let encoder = self.store.encoder();
Ok(TriplesIterator {
iter: self.store.quads_for_subject_graph(
&encoder.encode_named_or_blank_node(subject)?,
&ENCODED_DEFAULT_GRAPH,
encoder.encode_named_or_blank_node(subject)?,
ENCODED_DEFAULT_GRAPH,
)?,
store: self.store.clone(),
})
@ -515,9 +512,9 @@ impl<S: EncodedQuadsStore> Graph for StoreDefaultGraph<S> {
let encoder = self.store.encoder();
Ok(ObjectsIterator {
iter: self.store.quads_for_subject_predicate_graph(
&encoder.encode_named_or_blank_node(subject)?,
&encoder.encode_named_node(predicate)?,
&ENCODED_DEFAULT_GRAPH,
encoder.encode_named_or_blank_node(subject)?,
encoder.encode_named_node(predicate)?,
ENCODED_DEFAULT_GRAPH,
)?,
store: self.store.clone(),
})
@ -530,9 +527,9 @@ impl<S: EncodedQuadsStore> Graph for StoreDefaultGraph<S> {
let encoder = self.store.encoder();
Ok(PredicatesIterator {
iter: self.store.quads_for_subject_object_graph(
&encoder.encode_named_or_blank_node(subject)?,
&encoder.encode_term(object)?,
&ENCODED_DEFAULT_GRAPH,
encoder.encode_named_or_blank_node(subject)?,
encoder.encode_term(object)?,
ENCODED_DEFAULT_GRAPH,
)?,
store: self.store.clone(),
})
@ -544,8 +541,8 @@ impl<S: EncodedQuadsStore> Graph for StoreDefaultGraph<S> {
let encoder = self.store.encoder();
Ok(TriplesIterator {
iter: self.store.quads_for_predicate_graph(
&encoder.encode_named_node(predicate)?,
&ENCODED_DEFAULT_GRAPH,
encoder.encode_named_node(predicate)?,
ENCODED_DEFAULT_GRAPH,
)?,
store: self.store.clone(),
})
@ -558,9 +555,9 @@ impl<S: EncodedQuadsStore> Graph for StoreDefaultGraph<S> {
let encoder = self.store.encoder();
Ok(SubjectsIterator {
iter: self.store.quads_for_predicate_object_graph(
&encoder.encode_named_node(predicate)?,
&encoder.encode_term(object)?,
&ENCODED_DEFAULT_GRAPH,
encoder.encode_named_node(predicate)?,
encoder.encode_term(object)?,
ENCODED_DEFAULT_GRAPH,
)?,
store: self.store.clone(),
})
@ -573,7 +570,7 @@ impl<S: EncodedQuadsStore> Graph for StoreDefaultGraph<S> {
Ok(TriplesIterator {
iter: self
.store
.quads_for_object_graph(&encoder.encode_term(object)?, &ENCODED_DEFAULT_GRAPH)?,
.quads_for_object_graph(encoder.encode_term(object)?, ENCODED_DEFAULT_GRAPH)?,
store: self.store.clone(),
})
}
@ -583,7 +580,7 @@ impl<S: EncodedQuadsStore> Graph for StoreDefaultGraph<S> {
&self
.store
.encoder()
.encode_triple_in_graph(triple, &ENCODED_DEFAULT_GRAPH)?,
.encode_triple_in_graph(triple, ENCODED_DEFAULT_GRAPH)?,
)
}
@ -592,7 +589,7 @@ impl<S: EncodedQuadsStore> Graph for StoreDefaultGraph<S> {
&self
.store
.encoder()
.encode_triple_in_graph(triple, &ENCODED_DEFAULT_GRAPH)?,
.encode_triple_in_graph(triple, ENCODED_DEFAULT_GRAPH)?,
)
}
@ -601,18 +598,18 @@ impl<S: EncodedQuadsStore> Graph for StoreDefaultGraph<S> {
&self
.store
.encoder()
.encode_triple_in_graph(triple, &ENCODED_DEFAULT_GRAPH)?,
.encode_triple_in_graph(triple, ENCODED_DEFAULT_GRAPH)?,
)
}
fn len(&self) -> Result<usize> {
Ok(self.store.quads_for_graph(&ENCODED_DEFAULT_GRAPH)?.count())
Ok(self.store.quads_for_graph(ENCODED_DEFAULT_GRAPH)?.count())
}
fn is_empty(&self) -> Result<bool> {
Ok(self
.store
.quads_for_graph(&ENCODED_DEFAULT_GRAPH)?
.quads_for_graph(ENCODED_DEFAULT_GRAPH)?
.any(|_| true))
}
}
@ -683,7 +680,7 @@ impl<S: EncodedQuadsStore> Graph for StoreUnionGraph<S> {
Ok(TriplesIterator {
iter: self
.store
.quads_for_subject(&encoder.encode_named_or_blank_node(subject)?)?,
.quads_for_subject(encoder.encode_named_or_blank_node(subject)?)?,
store: self.store.clone(),
})
}
@ -695,8 +692,8 @@ impl<S: EncodedQuadsStore> Graph for StoreUnionGraph<S> {
let encoder = self.store.encoder();
Ok(ObjectsIterator {
iter: self.store.quads_for_subject_predicate(
&encoder.encode_named_or_blank_node(subject)?,
&encoder.encode_named_node(predicate)?,
encoder.encode_named_or_blank_node(subject)?,
encoder.encode_named_node(predicate)?,
)?,
store: self.store.clone(),
})
@ -709,8 +706,8 @@ impl<S: EncodedQuadsStore> Graph for StoreUnionGraph<S> {
let encoder = self.store.encoder();
Ok(PredicatesIterator {
iter: self.store.quads_for_subject_object(
&encoder.encode_named_or_blank_node(subject)?,
&encoder.encode_term(object)?,
encoder.encode_named_or_blank_node(subject)?,
encoder.encode_term(object)?,
)?,
store: self.store.clone(),
})
@ -723,7 +720,7 @@ impl<S: EncodedQuadsStore> Graph for StoreUnionGraph<S> {
Ok(TriplesIterator {
iter: self
.store
.quads_for_predicate(&encoder.encode_named_node(predicate)?)?,
.quads_for_predicate(encoder.encode_named_node(predicate)?)?,
store: self.store.clone(),
})
}
@ -735,8 +732,8 @@ impl<S: EncodedQuadsStore> Graph for StoreUnionGraph<S> {
let encoder = self.store.encoder();
Ok(SubjectsIterator {
iter: self.store.quads_for_predicate_object(
&encoder.encode_named_node(predicate)?,
&encoder.encode_term(object)?,
encoder.encode_named_node(predicate)?,
encoder.encode_term(object)?,
)?,
store: self.store.clone(),
})
@ -748,7 +745,7 @@ impl<S: EncodedQuadsStore> Graph for StoreUnionGraph<S> {
) -> Result<TriplesIterator<S::QuadsForObjectIterator, S>> {
let encoder = self.store.encoder();
Ok(TriplesIterator {
iter: self.store.quads_for_object(&encoder.encode_term(object)?)?,
iter: self.store.quads_for_object(encoder.encode_term(object)?)?,
store: self.store.clone(),
})
}
@ -758,9 +755,9 @@ impl<S: EncodedQuadsStore> Graph for StoreUnionGraph<S> {
Ok(self
.store
.quads_for_subject_predicate_object(
&encoder.encode_named_or_blank_node(triple.subject())?,
&encoder.encode_named_node(triple.predicate())?,
&encoder.encode_term(triple.object())?,
encoder.encode_named_or_blank_node(triple.subject())?,
encoder.encode_named_node(triple.predicate())?,
encoder.encode_term(triple.object())?,
)?.any(|_| true))
}
@ -853,7 +850,7 @@ impl<I: Iterator<Item = Result<EncodedQuad>>, S: EncodedQuadsStore> Iterator
k.and_then(|quad| {
self.store
.encoder()
.decode_named_or_blank_node(&quad.subject)
.decode_named_or_blank_node(quad.subject)
})
})
}
@ -872,7 +869,7 @@ impl<I: Iterator<Item = Result<EncodedQuad>>, S: EncodedQuadsStore> Iterator
fn next(&mut self) -> Option<Result<NamedNode>> {
self.iter
.next()
.map(|k| k.and_then(|quad| self.store.encoder().decode_named_node(&quad.predicate)))
.map(|k| k.and_then(|quad| self.store.encoder().decode_named_node(quad.predicate)))
}
}
@ -889,6 +886,6 @@ impl<I: Iterator<Item = Result<EncodedQuad>>, S: EncodedQuadsStore> Iterator
fn next(&mut self) -> Option<Result<Term>> {
self.iter
.next()
.map(|k| k.and_then(|quad| self.store.encoder().decode_term(&quad.object)))
.map(|k| k.and_then(|quad| self.store.encoder().decode_term(quad.object)))
}
}

Loading…
Cancel
Save