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 (s, pos) in &graph.spo {
for (p, os) in pos.iter() { for (p, os) in pos.iter() {
for o in os.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( fn quads_for_subject(
&self, &self,
subject: &EncodedTerm, subject: EncodedTerm,
) -> Result<<Vec<Result<EncodedQuad>> as IntoIterator>::IntoIter> { ) -> Result<<Vec<Result<EncodedQuad>> as IntoIterator>::IntoIter> {
let mut result = Vec::default(); let mut result = Vec::default();
for (graph_name, graph) in self.graph_indexes.read()?.iter() { 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 (p, os) in pos.iter() {
for o in os.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( fn quads_for_subject_predicate(
&self, &self,
subject: &EncodedTerm, subject: EncodedTerm,
predicate: &EncodedTerm, predicate: EncodedTerm,
) -> Result<<Vec<Result<EncodedQuad>> as IntoIterator>::IntoIter> { ) -> Result<<Vec<Result<EncodedQuad>> as IntoIterator>::IntoIter> {
let mut result = Vec::default(); let mut result = Vec::default();
for (graph_name, graph) in self.graph_indexes.read()?.iter() { 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) {
if let Some(os) = pos.get(predicate) { if let Some(os) = pos.get(&predicate) {
for o in os.iter() { 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( fn quads_for_subject_predicate_object(
&self, &self,
subject: &EncodedTerm, subject: EncodedTerm,
predicate: &EncodedTerm, predicate: EncodedTerm,
object: &EncodedTerm, object: EncodedTerm,
) -> Result<<Vec<Result<EncodedQuad>> as IntoIterator>::IntoIter> { ) -> Result<<Vec<Result<EncodedQuad>> as IntoIterator>::IntoIter> {
let mut result = Vec::default(); let mut result = Vec::default();
for (graph_name, graph) in self.graph_indexes.read()?.iter() { 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) {
if let Some(os) = pos.get(predicate) { if let Some(os) = pos.get(&predicate) {
if os.contains(object) { if os.contains(&object) {
result.push(Ok(encoded_quad(subject, predicate, object, graph_name))) result.push(Ok(EncodedQuad::new(
subject,
predicate,
object,
*graph_name,
)))
} }
} }
} }
@ -131,15 +136,15 @@ impl EncodedQuadsStore for MemoryStore {
fn quads_for_subject_object( fn quads_for_subject_object(
&self, &self,
subject: &EncodedTerm, subject: EncodedTerm,
object: &EncodedTerm, object: EncodedTerm,
) -> Result<<Vec<Result<EncodedQuad>> as IntoIterator>::IntoIter> { ) -> Result<<Vec<Result<EncodedQuad>> as IntoIterator>::IntoIter> {
let mut result = Vec::default(); let mut result = Vec::default();
for (graph_name, graph) in self.graph_indexes.read()?.iter() { 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) {
if let Some(ps) = sps.get(subject) { if let Some(ps) = sps.get(&subject) {
for p in ps.iter() { 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( fn quads_for_predicate(
&self, &self,
predicate: &EncodedTerm, predicate: EncodedTerm,
) -> Result<<Vec<Result<EncodedQuad>> as IntoIterator>::IntoIter> { ) -> Result<<Vec<Result<EncodedQuad>> as IntoIterator>::IntoIter> {
let mut result = Vec::default(); let mut result = Vec::default();
for (graph_name, graph) in self.graph_indexes.read()?.iter() { 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 (o, ss) in oss.iter() {
for s in ss.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( fn quads_for_predicate_object(
&self, &self,
predicate: &EncodedTerm, predicate: EncodedTerm,
object: &EncodedTerm, object: EncodedTerm,
) -> Result<<Vec<Result<EncodedQuad>> as IntoIterator>::IntoIter> { ) -> Result<<Vec<Result<EncodedQuad>> as IntoIterator>::IntoIter> {
let mut result = Vec::default(); let mut result = Vec::default();
for (graph_name, graph) in self.graph_indexes.read()?.iter() { 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) {
if let Some(ss) = oss.get(object) { if let Some(ss) = oss.get(&object) {
for s in ss.iter() { 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( fn quads_for_object(
&self, &self,
object: &EncodedTerm, object: EncodedTerm,
) -> Result<<Vec<Result<EncodedQuad>> as IntoIterator>::IntoIter> { ) -> Result<<Vec<Result<EncodedQuad>> as IntoIterator>::IntoIter> {
let mut result = Vec::default(); let mut result = Vec::default();
for (graph_name, graph) in self.graph_indexes.read()?.iter() { 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 (s, ps) in sps.iter() {
for p in ps.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( fn quads_for_graph(
&self, &self,
graph_name: &EncodedTerm, graph_name: EncodedTerm,
) -> Result<<Vec<Result<EncodedQuad>> as IntoIterator>::IntoIter> { ) -> Result<<Vec<Result<EncodedQuad>> as IntoIterator>::IntoIter> {
let mut result = Vec::default(); 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 (s, pos) in &graph.spo {
for (p, os) in pos.iter() { for (p, os) in pos.iter() {
for o in os.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( fn quads_for_subject_graph(
&self, &self,
subject: &EncodedTerm, subject: EncodedTerm,
graph_name: &EncodedTerm, graph_name: EncodedTerm,
) -> Result<<Vec<Result<EncodedQuad>> as IntoIterator>::IntoIter> { ) -> Result<<Vec<Result<EncodedQuad>> as IntoIterator>::IntoIter> {
let mut result = Vec::default(); 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) {
if let Some(pos) = graph.spo.get(subject) { if let Some(pos) = graph.spo.get(&subject) {
for (p, os) in pos.iter() { for (p, os) in pos.iter() {
for o in os.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( fn quads_for_subject_predicate_graph(
&self, &self,
subject: &EncodedTerm, subject: EncodedTerm,
predicate: &EncodedTerm, predicate: EncodedTerm,
graph_name: &EncodedTerm, graph_name: EncodedTerm,
) -> Result<<Vec<Result<EncodedQuad>> as IntoIterator>::IntoIter> { ) -> Result<<Vec<Result<EncodedQuad>> as IntoIterator>::IntoIter> {
let mut result = Vec::default(); 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) {
if let Some(pos) = graph.spo.get(subject) { if let Some(pos) = graph.spo.get(&subject) {
if let Some(os) = pos.get(predicate) { if let Some(os) = pos.get(&predicate) {
for o in os.iter() { 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( fn quads_for_subject_object_graph(
&self, &self,
subject: &EncodedTerm, subject: EncodedTerm,
object: &EncodedTerm, object: EncodedTerm,
graph_name: &EncodedTerm, graph_name: EncodedTerm,
) -> Result<<Vec<Result<EncodedQuad>> as IntoIterator>::IntoIter> { ) -> Result<<Vec<Result<EncodedQuad>> as IntoIterator>::IntoIter> {
let mut result = Vec::default(); 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) {
if let Some(sps) = graph.osp.get(object) { if let Some(sps) = graph.osp.get(&object) {
if let Some(ps) = sps.get(subject) { if let Some(ps) = sps.get(&subject) {
for p in ps.iter() { 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( fn quads_for_predicate_graph(
&self, &self,
predicate: &EncodedTerm, predicate: EncodedTerm,
graph_name: &EncodedTerm, graph_name: EncodedTerm,
) -> Result<<Vec<Result<EncodedQuad>> as IntoIterator>::IntoIter> { ) -> Result<<Vec<Result<EncodedQuad>> as IntoIterator>::IntoIter> {
let mut result = Vec::default(); 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) {
if let Some(oss) = graph.pos.get(predicate) { if let Some(oss) = graph.pos.get(&predicate) {
for (o, ss) in oss.iter() { for (o, ss) in oss.iter() {
for s in ss.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( fn quads_for_predicate_object_graph(
&self, &self,
predicate: &EncodedTerm, predicate: EncodedTerm,
object: &EncodedTerm, object: EncodedTerm,
graph_name: &EncodedTerm, graph_name: EncodedTerm,
) -> Result<<Vec<Result<EncodedQuad>> as IntoIterator>::IntoIter> { ) -> Result<<Vec<Result<EncodedQuad>> as IntoIterator>::IntoIter> {
let mut result = Vec::default(); 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) {
if let Some(oss) = graph.pos.get(predicate) { if let Some(oss) = graph.pos.get(&predicate) {
if let Some(ss) = oss.get(object) { if let Some(ss) = oss.get(&object) {
for s in ss.iter() { 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( fn quads_for_object_graph(
&self, &self,
object: &EncodedTerm, object: EncodedTerm,
graph_name: &EncodedTerm, graph_name: EncodedTerm,
) -> Result<<Vec<Result<EncodedQuad>> as IntoIterator>::IntoIter> { ) -> Result<<Vec<Result<EncodedQuad>> as IntoIterator>::IntoIter> {
let mut result = Vec::default(); 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) {
if let Some(sps) = graph.osp.get(object) { if let Some(sps) = graph.osp.get(&object) {
for (s, ps) in sps.iter() { for (s, ps) in sps.iter() {
for p in ps.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(()) 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 { 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_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<()>;
} }
impl<R: Write> TermWriter for R { 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::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 {
value_id, value_id,
language_id, language_id,
} => { } => {
self.write_u64::<NetworkEndian>(*language_id)?; self.write_u64::<NetworkEndian>(language_id)?;
self.write_u64::<NetworkEndian>(*value_id)?; self.write_u64::<NetworkEndian>(value_id)?;
} }
EncodedTerm::TypedLiteral { EncodedTerm::TypedLiteral {
value_id, value_id,
datatype_id, datatype_id,
} => { } => {
self.write_u64::<NetworkEndian>(*datatype_id)?; self.write_u64::<NetworkEndian>(datatype_id)?;
self.write_u64::<NetworkEndian>(*value_id)?; self.write_u64::<NetworkEndian>(value_id)?;
} }
} }
Ok(()) Ok(())
} }
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_term(&quad.graph_name)?; self.write_term(quad.graph_name)?;
Ok(()) Ok(())
} }
fn write_posg_quad(&mut self, quad: &EncodedQuad) -> Result<()> { fn write_posg_quad(&mut self, quad: &EncodedQuad) -> Result<()> {
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_term(&quad.graph_name)?; self.write_term(quad.graph_name)?;
Ok(()) Ok(())
} }
fn write_ospg_quad(&mut self, quad: &EncodedQuad) -> Result<()> { fn write_ospg_quad(&mut self, quad: &EncodedQuad) -> Result<()> {
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_term(&quad.graph_name)?; self.write_term(quad.graph_name)?;
Ok(()) Ok(())
} }
} }
@ -260,41 +260,41 @@ 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: &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,
}) })
} }
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::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())
} }
EncodedTerm::BlankNode(id) => Ok(BlankNode::from(*id).into()), EncodedTerm::BlankNode(id) => Ok(BlankNode::from(id).into()),
EncodedTerm::LangStringLiteral { EncodedTerm::LangStringLiteral {
value_id, value_id,
language_id, language_id,
} => Ok(Literal::new_language_tagged_literal( } => Ok(Literal::new_language_tagged_literal(
self.decode_str_value(*value_id)?, self.decode_str_value(value_id)?,
self.decode_str_value(*language_id)?, self.decode_str_value(language_id)?,
).into()), ).into()),
EncodedTerm::TypedLiteral { EncodedTerm::TypedLiteral {
value_id, value_id,
datatype_id, datatype_id,
} => Ok(Literal::new_typed_literal( } => Ok(Literal::new_typed_literal(
self.decode_str_value(*value_id)?, self.decode_str_value(value_id)?,
NamedNode::from(self.decode_url_value(*datatype_id)?), NamedNode::from(self.decode_url_value(datatype_id)?),
).into()), ).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)? { match self.decode_term(encoded)? {
Term::NamedNode(named_node) => Ok(named_node.into()), Term::NamedNode(named_node) => Ok(named_node.into()),
Term::BlankNode(blank_node) => Ok(blank_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)? { match self.decode_term(encoded)? {
Term::NamedNode(named_node) => Ok(named_node), Term::NamedNode(named_node) => Ok(named_node),
Term::BlankNode(_) => Err("A blank node has been found instead of a named node".into()), 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> { pub fn decode_triple(&self, encoded: &EncodedQuad) -> Result<Triple> {
Ok(Triple::new( Ok(Triple::new(
self.decode_named_or_blank_node(&encoded.subject)?, self.decode_named_or_blank_node(encoded.subject)?,
self.decode_named_node(&encoded.predicate)?, self.decode_named_node(encoded.predicate)?,
self.decode_term(&encoded.object)?, self.decode_term(encoded.object)?,
)) ))
} }
pub fn decode_quad(&self, encoded: &EncodedQuad) -> Result<Quad> { pub fn decode_quad(&self, encoded: &EncodedQuad) -> Result<Quad> {
Ok(Quad::new( Ok(Quad::new(
self.decode_named_or_blank_node(&encoded.subject)?, self.decode_named_or_blank_node(encoded.subject)?,
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 {
EncodedTerm::DefaultGraph {} => None, 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( fn quads_for_subject(
&self, &self,
subject: &EncodedTerm, subject: EncodedTerm,
) -> Result<FilteringEncodedQuadsIterator<SPOGIndexIterator>> { ) -> Result<FilteringEncodedQuadsIterator<SPOGIndexIterator>> {
let mut iter = self.db.raw_iterator_cf(self.spog_cf)?; let mut iter = self.db.raw_iterator_cf(self.spog_cf)?;
iter.seek(&encode_term(subject)?); iter.seek(&encode_term(subject)?);
Ok(FilteringEncodedQuadsIterator { Ok(FilteringEncodedQuadsIterator {
iter: SPOGIndexIterator { iter }, iter: SPOGIndexIterator { iter },
filter: EncodedQuadPattern::new(Some(*subject), None, None, None), filter: EncodedQuadPattern::new(Some(subject), None, None, None),
}) })
} }
fn quads_for_subject_predicate( fn quads_for_subject_predicate(
&self, &self,
subject: &EncodedTerm, subject: EncodedTerm,
predicate: &EncodedTerm, predicate: EncodedTerm,
) -> Result<FilteringEncodedQuadsIterator<SPOGIndexIterator>> { ) -> Result<FilteringEncodedQuadsIterator<SPOGIndexIterator>> {
let mut iter = self.db.raw_iterator_cf(self.spog_cf)?; let mut iter = self.db.raw_iterator_cf(self.spog_cf)?;
iter.seek(&encode_term_pair(subject, predicate)?); iter.seek(&encode_term_pair(subject, predicate)?);
Ok(FilteringEncodedQuadsIterator { Ok(FilteringEncodedQuadsIterator {
iter: SPOGIndexIterator { iter }, 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( fn quads_for_subject_predicate_object(
&self, &self,
subject: &EncodedTerm, subject: EncodedTerm,
predicate: &EncodedTerm, predicate: EncodedTerm,
object: &EncodedTerm, object: EncodedTerm,
) -> Result<FilteringEncodedQuadsIterator<SPOGIndexIterator>> { ) -> Result<FilteringEncodedQuadsIterator<SPOGIndexIterator>> {
let mut iter = self.db.raw_iterator_cf(self.spog_cf)?; let mut iter = self.db.raw_iterator_cf(self.spog_cf)?;
iter.seek(&encode_term_triple(subject, predicate, object)?); iter.seek(&encode_term_triple(subject, predicate, object)?);
Ok(FilteringEncodedQuadsIterator { Ok(FilteringEncodedQuadsIterator {
iter: SPOGIndexIterator { iter }, 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( fn quads_for_subject_object(
&self, &self,
subject: &EncodedTerm, subject: EncodedTerm,
object: &EncodedTerm, object: EncodedTerm,
) -> Result<FilteringEncodedQuadsIterator<OSPGIndexIterator>> { ) -> Result<FilteringEncodedQuadsIterator<OSPGIndexIterator>> {
let mut iter = self.db.raw_iterator_cf(self.spog_cf)?; let mut iter = self.db.raw_iterator_cf(self.spog_cf)?;
iter.seek(&encode_term_pair(object, subject)?); iter.seek(&encode_term_pair(object, subject)?);
Ok(FilteringEncodedQuadsIterator { Ok(FilteringEncodedQuadsIterator {
iter: OSPGIndexIterator { iter }, 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( fn quads_for_predicate(
&self, &self,
predicate: &EncodedTerm, predicate: EncodedTerm,
) -> Result<FilteringEncodedQuadsIterator<POSGIndexIterator>> { ) -> Result<FilteringEncodedQuadsIterator<POSGIndexIterator>> {
let mut iter = self.db.raw_iterator_cf(self.posg_cf)?; let mut iter = self.db.raw_iterator_cf(self.posg_cf)?;
iter.seek(&encode_term(predicate)?); iter.seek(&encode_term(predicate)?);
Ok(FilteringEncodedQuadsIterator { Ok(FilteringEncodedQuadsIterator {
iter: POSGIndexIterator { iter }, iter: POSGIndexIterator { iter },
filter: EncodedQuadPattern::new(None, Some(*predicate), None, None), filter: EncodedQuadPattern::new(None, Some(predicate), None, None),
}) })
} }
fn quads_for_predicate_object( fn quads_for_predicate_object(
&self, &self,
predicate: &EncodedTerm, predicate: EncodedTerm,
object: &EncodedTerm, object: EncodedTerm,
) -> Result<FilteringEncodedQuadsIterator<POSGIndexIterator>> { ) -> Result<FilteringEncodedQuadsIterator<POSGIndexIterator>> {
let mut iter = self.db.raw_iterator_cf(self.spog_cf)?; let mut iter = self.db.raw_iterator_cf(self.spog_cf)?;
iter.seek(&encode_term_pair(predicate, object)?); iter.seek(&encode_term_pair(predicate, object)?);
Ok(FilteringEncodedQuadsIterator { Ok(FilteringEncodedQuadsIterator {
iter: POSGIndexIterator { iter }, 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( fn quads_for_object(
&self, &self,
object: &EncodedTerm, object: EncodedTerm,
) -> Result<FilteringEncodedQuadsIterator<OSPGIndexIterator>> { ) -> Result<FilteringEncodedQuadsIterator<OSPGIndexIterator>> {
let mut iter = self.db.raw_iterator_cf(self.ospg_cf)?; let mut iter = self.db.raw_iterator_cf(self.ospg_cf)?;
iter.seek(&encode_term(&object)?); iter.seek(&encode_term(object)?);
Ok(FilteringEncodedQuadsIterator { Ok(FilteringEncodedQuadsIterator {
iter: OSPGIndexIterator { iter }, iter: OSPGIndexIterator { iter },
filter: EncodedQuadPattern::new(None, None, Some(*object), None), filter: EncodedQuadPattern::new(None, None, Some(object), None),
}) })
} }
fn quads_for_graph( fn quads_for_graph(
&self, &self,
graph_name: &EncodedTerm, graph_name: EncodedTerm,
) -> Result<InGraphQuadsIterator<SPOGIndexIterator>> { ) -> Result<InGraphQuadsIterator<SPOGIndexIterator>> {
Ok(InGraphQuadsIterator { Ok(InGraphQuadsIterator {
iter: self.quads()?, iter: self.quads()?,
graph_name: *graph_name, graph_name,
}) })
} }
fn quads_for_subject_graph( fn quads_for_subject_graph(
&self, &self,
subject: &EncodedTerm, subject: EncodedTerm,
graph_name: &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)?,
graph_name: *graph_name, graph_name,
}) })
} }
fn quads_for_subject_predicate_graph( fn quads_for_subject_predicate_graph(
&self, &self,
subject: &EncodedTerm, subject: EncodedTerm,
predicate: &EncodedTerm, predicate: EncodedTerm,
graph_name: &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)?,
graph_name: *graph_name, graph_name,
}) })
} }
fn quads_for_subject_object_graph( fn quads_for_subject_object_graph(
&self, &self,
subject: &EncodedTerm, subject: EncodedTerm,
object: &EncodedTerm, object: EncodedTerm,
graph_name: &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)?,
graph_name: *graph_name, graph_name,
}) })
} }
fn quads_for_predicate_graph( fn quads_for_predicate_graph(
&self, &self,
predicate: &EncodedTerm, predicate: EncodedTerm,
graph_name: &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)?,
graph_name: *graph_name, graph_name,
}) })
} }
fn quads_for_predicate_object_graph( fn quads_for_predicate_object_graph(
&self, &self,
predicate: &EncodedTerm, predicate: EncodedTerm,
object: &EncodedTerm, object: EncodedTerm,
graph_name: &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)?,
graph_name: *graph_name, graph_name,
}) })
} }
fn quads_for_object_graph( fn quads_for_object_graph(
&self, &self,
object: &EncodedTerm, object: EncodedTerm,
graph_name: &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)?,
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(); let mut vec = Vec::default();
vec.write_term(&t)?; vec.write_term(t)?;
Ok(vec) 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(); let mut vec = Vec::default();
vec.write_term(&t1)?; vec.write_term(t1)?;
vec.write_term(&t2)?; vec.write_term(t2)?;
Ok(vec) 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(); let mut vec = Vec::default();
vec.write_term(&t1)?; vec.write_term(t1)?;
vec.write_term(&t2)?; vec.write_term(t2)?;
vec.write_term(&t3)?; vec.write_term(t3)?;
Ok(vec) Ok(vec)
} }

@ -33,66 +33,66 @@ pub trait EncodedQuadsStore: BytesStore + Sized {
} }
fn quads(&self) -> Result<Self::QuadsIterator>; 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( fn quads_for_subject_predicate(
&self, &self,
subject: &EncodedTerm, subject: EncodedTerm,
predicate: &EncodedTerm, predicate: EncodedTerm,
) -> Result<Self::QuadsForSubjectPredicateIterator>; ) -> Result<Self::QuadsForSubjectPredicateIterator>;
fn quads_for_subject_predicate_object( fn quads_for_subject_predicate_object(
&self, &self,
subject: &EncodedTerm, subject: EncodedTerm,
predicate: &EncodedTerm, predicate: EncodedTerm,
object: &EncodedTerm, object: EncodedTerm,
) -> Result<Self::QuadsForSubjectPredicateObjectIterator>; ) -> Result<Self::QuadsForSubjectPredicateObjectIterator>;
fn quads_for_subject_object( fn quads_for_subject_object(
&self, &self,
subject: &EncodedTerm, subject: EncodedTerm,
object: &EncodedTerm, object: EncodedTerm,
) -> Result<Self::QuadsForSubjectObjectIterator>; ) -> Result<Self::QuadsForSubjectObjectIterator>;
fn quads_for_predicate( fn quads_for_predicate(
&self, &self,
predicate: &EncodedTerm, predicate: EncodedTerm,
) -> Result<Self::QuadsForPredicateIterator>; ) -> Result<Self::QuadsForPredicateIterator>;
fn quads_for_predicate_object( fn quads_for_predicate_object(
&self, &self,
predicate: &EncodedTerm, predicate: EncodedTerm,
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(&self, graph_name: &EncodedTerm) -> Result<Self::QuadsForGraphIterator>; fn quads_for_graph(&self, graph_name: EncodedTerm) -> Result<Self::QuadsForGraphIterator>;
fn quads_for_subject_graph( fn quads_for_subject_graph(
&self, &self,
subject: &EncodedTerm, subject: EncodedTerm,
graph_name: &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: &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: &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: &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: &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: &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<()>;
@ -160,7 +160,7 @@ impl<S: EncodedQuadsStore> Dataset for StoreDataset<S> {
Ok(QuadsIterator { Ok(QuadsIterator {
iter: self iter: self
.store .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(), store: self.store.clone(),
}) })
} }
@ -173,8 +173,8 @@ impl<S: EncodedQuadsStore> Dataset for StoreDataset<S> {
let encoder = self.store.encoder(); let encoder = self.store.encoder();
Ok(QuadsIterator { Ok(QuadsIterator {
iter: self.store.quads_for_subject_predicate( iter: self.store.quads_for_subject_predicate(
&encoder.encode_named_or_blank_node(subject)?, encoder.encode_named_or_blank_node(subject)?,
&encoder.encode_named_node(predicate)?, encoder.encode_named_node(predicate)?,
)?, )?,
store: self.store.clone(), store: self.store.clone(),
}) })
@ -189,9 +189,9 @@ impl<S: EncodedQuadsStore> Dataset for StoreDataset<S> {
let encoder = self.store.encoder(); let encoder = self.store.encoder();
Ok(QuadsIterator { Ok(QuadsIterator {
iter: self.store.quads_for_subject_predicate_object( iter: self.store.quads_for_subject_predicate_object(
&encoder.encode_named_or_blank_node(subject)?, encoder.encode_named_or_blank_node(subject)?,
&encoder.encode_named_node(predicate)?, encoder.encode_named_node(predicate)?,
&encoder.encode_term(object)?, encoder.encode_term(object)?,
)?, )?,
store: self.store.clone(), store: self.store.clone(),
}) })
@ -205,8 +205,8 @@ impl<S: EncodedQuadsStore> Dataset for StoreDataset<S> {
let encoder = self.store.encoder(); let encoder = self.store.encoder();
Ok(QuadsIterator { Ok(QuadsIterator {
iter: self.store.quads_for_subject_object( iter: self.store.quads_for_subject_object(
&encoder.encode_named_or_blank_node(subject)?, encoder.encode_named_or_blank_node(subject)?,
&encoder.encode_term(object)?, encoder.encode_term(object)?,
)?, )?,
store: self.store.clone(), store: self.store.clone(),
}) })
@ -220,7 +220,7 @@ impl<S: EncodedQuadsStore> Dataset for StoreDataset<S> {
Ok(QuadsIterator { Ok(QuadsIterator {
iter: self iter: self
.store .store
.quads_for_predicate(&encoder.encode_named_node(predicate)?)?, .quads_for_predicate(encoder.encode_named_node(predicate)?)?,
store: self.store.clone(), store: self.store.clone(),
}) })
} }
@ -233,8 +233,8 @@ impl<S: EncodedQuadsStore> Dataset for StoreDataset<S> {
let encoder = self.store.encoder(); let encoder = self.store.encoder();
Ok(QuadsIterator { Ok(QuadsIterator {
iter: self.store.quads_for_predicate_object( iter: self.store.quads_for_predicate_object(
&encoder.encode_named_node(predicate)?, encoder.encode_named_node(predicate)?,
&encoder.encode_term(object)?, encoder.encode_term(object)?,
)?, )?,
store: self.store.clone(), store: self.store.clone(),
}) })
@ -246,7 +246,7 @@ impl<S: EncodedQuadsStore> Dataset for StoreDataset<S> {
) -> Result<QuadsIterator<S::QuadsForObjectIterator, S>> { ) -> Result<QuadsIterator<S::QuadsForObjectIterator, S>> {
let encoder = self.store.encoder(); let encoder = self.store.encoder();
Ok(QuadsIterator { 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(), store: self.store.clone(),
}) })
} }
@ -328,7 +328,7 @@ impl<S: EncodedQuadsStore> Graph for StoreNamedGraph<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(&self.encoded_name)?, iter: self.store.quads_for_graph(self.encoded_name)?,
store: self.store.clone(), store: self.store.clone(),
}) })
} }
@ -340,8 +340,8 @@ impl<S: EncodedQuadsStore> Graph for StoreNamedGraph<S> {
let encoder = self.store.encoder(); let encoder = self.store.encoder();
Ok(TriplesIterator { Ok(TriplesIterator {
iter: self.store.quads_for_subject_graph( iter: self.store.quads_for_subject_graph(
&encoder.encode_named_or_blank_node(subject)?, encoder.encode_named_or_blank_node(subject)?,
&self.encoded_name, self.encoded_name,
)?, )?,
store: self.store.clone(), store: self.store.clone(),
}) })
@ -354,9 +354,9 @@ impl<S: EncodedQuadsStore> Graph for StoreNamedGraph<S> {
let encoder = self.store.encoder(); let encoder = self.store.encoder();
Ok(ObjectsIterator { Ok(ObjectsIterator {
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)?,
&self.encoded_name, self.encoded_name,
)?, )?,
store: self.store.clone(), store: self.store.clone(),
}) })
@ -369,9 +369,9 @@ impl<S: EncodedQuadsStore> Graph for StoreNamedGraph<S> {
let encoder = self.store.encoder(); let encoder = self.store.encoder();
Ok(PredicatesIterator { Ok(PredicatesIterator {
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)?,
&self.encoded_name, self.encoded_name,
)?, )?,
store: self.store.clone(), store: self.store.clone(),
}) })
@ -383,8 +383,8 @@ impl<S: EncodedQuadsStore> Graph for StoreNamedGraph<S> {
let encoder = self.store.encoder(); let encoder = self.store.encoder();
Ok(TriplesIterator { Ok(TriplesIterator {
iter: self.store.quads_for_predicate_graph( iter: self.store.quads_for_predicate_graph(
&encoder.encode_named_node(predicate)?, encoder.encode_named_node(predicate)?,
&self.encoded_name, self.encoded_name,
)?, )?,
store: self.store.clone(), store: self.store.clone(),
}) })
@ -397,9 +397,9 @@ impl<S: EncodedQuadsStore> Graph for StoreNamedGraph<S> {
let encoder = self.store.encoder(); let encoder = self.store.encoder();
Ok(SubjectsIterator { Ok(SubjectsIterator {
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)?,
&self.encoded_name, self.encoded_name,
)?, )?,
store: self.store.clone(), store: self.store.clone(),
}) })
@ -412,7 +412,7 @@ impl<S: EncodedQuadsStore> Graph for StoreNamedGraph<S> {
Ok(TriplesIterator { Ok(TriplesIterator {
iter: self iter: self
.store .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(), store: self.store.clone(),
}) })
} }
@ -422,7 +422,7 @@ impl<S: EncodedQuadsStore> Graph for StoreNamedGraph<S> {
&self &self
.store .store
.encoder() .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 &self
.store .store
.encoder() .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 &self
.store .store
.encoder() .encoder()
.encode_triple_in_graph(triple, &self.encoded_name)?, .encode_triple_in_graph(triple, self.encoded_name)?,
) )
} }
fn len(&self) -> Result<usize> { 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> { fn is_empty(&self) -> Result<bool> {
Ok(self Ok(self.store.quads_for_graph(self.encoded_name)?.any(|_| true))
.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>> { fn triples(&self) -> Result<TriplesIterator<S::QuadsForGraphIterator, S>> {
Ok(TriplesIterator { Ok(TriplesIterator {
iter: self.store.quads_for_graph(&ENCODED_DEFAULT_GRAPH)?, iter: self.store.quads_for_graph(ENCODED_DEFAULT_GRAPH)?,
store: self.store.clone(), store: self.store.clone(),
}) })
} }
@ -501,8 +498,8 @@ impl<S: EncodedQuadsStore> Graph for StoreDefaultGraph<S> {
let encoder = self.store.encoder(); let encoder = self.store.encoder();
Ok(TriplesIterator { Ok(TriplesIterator {
iter: self.store.quads_for_subject_graph( iter: self.store.quads_for_subject_graph(
&encoder.encode_named_or_blank_node(subject)?, encoder.encode_named_or_blank_node(subject)?,
&ENCODED_DEFAULT_GRAPH, ENCODED_DEFAULT_GRAPH,
)?, )?,
store: self.store.clone(), store: self.store.clone(),
}) })
@ -515,9 +512,9 @@ impl<S: EncodedQuadsStore> Graph for StoreDefaultGraph<S> {
let encoder = self.store.encoder(); let encoder = self.store.encoder();
Ok(ObjectsIterator { Ok(ObjectsIterator {
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)?,
&ENCODED_DEFAULT_GRAPH, ENCODED_DEFAULT_GRAPH,
)?, )?,
store: self.store.clone(), store: self.store.clone(),
}) })
@ -530,9 +527,9 @@ impl<S: EncodedQuadsStore> Graph for StoreDefaultGraph<S> {
let encoder = self.store.encoder(); let encoder = self.store.encoder();
Ok(PredicatesIterator { Ok(PredicatesIterator {
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)?,
&ENCODED_DEFAULT_GRAPH, ENCODED_DEFAULT_GRAPH,
)?, )?,
store: self.store.clone(), store: self.store.clone(),
}) })
@ -544,8 +541,8 @@ impl<S: EncodedQuadsStore> Graph for StoreDefaultGraph<S> {
let encoder = self.store.encoder(); let encoder = self.store.encoder();
Ok(TriplesIterator { Ok(TriplesIterator {
iter: self.store.quads_for_predicate_graph( iter: self.store.quads_for_predicate_graph(
&encoder.encode_named_node(predicate)?, encoder.encode_named_node(predicate)?,
&ENCODED_DEFAULT_GRAPH, ENCODED_DEFAULT_GRAPH,
)?, )?,
store: self.store.clone(), store: self.store.clone(),
}) })
@ -558,9 +555,9 @@ impl<S: EncodedQuadsStore> Graph for StoreDefaultGraph<S> {
let encoder = self.store.encoder(); let encoder = self.store.encoder();
Ok(SubjectsIterator { Ok(SubjectsIterator {
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)?,
&ENCODED_DEFAULT_GRAPH, ENCODED_DEFAULT_GRAPH,
)?, )?,
store: self.store.clone(), store: self.store.clone(),
}) })
@ -573,7 +570,7 @@ 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)?, &ENCODED_DEFAULT_GRAPH)?, .quads_for_object_graph(encoder.encode_term(object)?, ENCODED_DEFAULT_GRAPH)?,
store: self.store.clone(), store: self.store.clone(),
}) })
} }
@ -583,7 +580,7 @@ impl<S: EncodedQuadsStore> Graph for StoreDefaultGraph<S> {
&self &self
.store .store
.encoder() .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 &self
.store .store
.encoder() .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 &self
.store .store
.encoder() .encoder()
.encode_triple_in_graph(triple, &ENCODED_DEFAULT_GRAPH)?, .encode_triple_in_graph(triple, ENCODED_DEFAULT_GRAPH)?,
) )
} }
fn len(&self) -> Result<usize> { 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> { fn is_empty(&self) -> Result<bool> {
Ok(self Ok(self
.store .store
.quads_for_graph(&ENCODED_DEFAULT_GRAPH)? .quads_for_graph(ENCODED_DEFAULT_GRAPH)?
.any(|_| true)) .any(|_| true))
} }
} }
@ -683,7 +680,7 @@ impl<S: EncodedQuadsStore> Graph for StoreUnionGraph<S> {
Ok(TriplesIterator { Ok(TriplesIterator {
iter: self iter: self
.store .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(), store: self.store.clone(),
}) })
} }
@ -695,8 +692,8 @@ impl<S: EncodedQuadsStore> Graph for StoreUnionGraph<S> {
let encoder = self.store.encoder(); let encoder = self.store.encoder();
Ok(ObjectsIterator { Ok(ObjectsIterator {
iter: self.store.quads_for_subject_predicate( iter: self.store.quads_for_subject_predicate(
&encoder.encode_named_or_blank_node(subject)?, encoder.encode_named_or_blank_node(subject)?,
&encoder.encode_named_node(predicate)?, encoder.encode_named_node(predicate)?,
)?, )?,
store: self.store.clone(), store: self.store.clone(),
}) })
@ -709,8 +706,8 @@ impl<S: EncodedQuadsStore> Graph for StoreUnionGraph<S> {
let encoder = self.store.encoder(); let encoder = self.store.encoder();
Ok(PredicatesIterator { Ok(PredicatesIterator {
iter: self.store.quads_for_subject_object( iter: self.store.quads_for_subject_object(
&encoder.encode_named_or_blank_node(subject)?, encoder.encode_named_or_blank_node(subject)?,
&encoder.encode_term(object)?, encoder.encode_term(object)?,
)?, )?,
store: self.store.clone(), store: self.store.clone(),
}) })
@ -723,7 +720,7 @@ impl<S: EncodedQuadsStore> Graph for StoreUnionGraph<S> {
Ok(TriplesIterator { Ok(TriplesIterator {
iter: self iter: self
.store .store
.quads_for_predicate(&encoder.encode_named_node(predicate)?)?, .quads_for_predicate(encoder.encode_named_node(predicate)?)?,
store: self.store.clone(), store: self.store.clone(),
}) })
} }
@ -735,8 +732,8 @@ impl<S: EncodedQuadsStore> Graph for StoreUnionGraph<S> {
let encoder = self.store.encoder(); let encoder = self.store.encoder();
Ok(SubjectsIterator { Ok(SubjectsIterator {
iter: self.store.quads_for_predicate_object( iter: self.store.quads_for_predicate_object(
&encoder.encode_named_node(predicate)?, encoder.encode_named_node(predicate)?,
&encoder.encode_term(object)?, encoder.encode_term(object)?,
)?, )?,
store: self.store.clone(), store: self.store.clone(),
}) })
@ -748,7 +745,7 @@ impl<S: EncodedQuadsStore> Graph for StoreUnionGraph<S> {
) -> Result<TriplesIterator<S::QuadsForObjectIterator, S>> { ) -> Result<TriplesIterator<S::QuadsForObjectIterator, S>> {
let encoder = self.store.encoder(); let encoder = self.store.encoder();
Ok(TriplesIterator { 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(), store: self.store.clone(),
}) })
} }
@ -758,9 +755,9 @@ impl<S: EncodedQuadsStore> Graph for StoreUnionGraph<S> {
Ok(self Ok(self
.store .store
.quads_for_subject_predicate_object( .quads_for_subject_predicate_object(
&encoder.encode_named_or_blank_node(triple.subject())?, encoder.encode_named_or_blank_node(triple.subject())?,
&encoder.encode_named_node(triple.predicate())?, encoder.encode_named_node(triple.predicate())?,
&encoder.encode_term(triple.object())?, encoder.encode_term(triple.object())?,
)?.any(|_| true)) )?.any(|_| true))
} }
@ -853,7 +850,7 @@ impl<I: Iterator<Item = Result<EncodedQuad>>, S: EncodedQuadsStore> Iterator
k.and_then(|quad| { k.and_then(|quad| {
self.store self.store
.encoder() .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>> { fn next(&mut self) -> Option<Result<NamedNode>> {
self.iter self.iter
.next() .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>> { fn next(&mut self) -> Option<Result<Term>> {
self.iter self.iter
.next() .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