Makes EncodedTerm implement Copy

pull/10/head
Tpt 6 years ago
parent 472a9292b3
commit da78cf5dff
  1. 27
      src/store/memory.rs
  2. 6
      src/store/numeric_encoder.rs
  3. 48
      src/store/rocksdb.rs

@ -347,29 +347,29 @@ impl EncodedQuadsStore for MemoryStore {
fn insert(&self, quad: &EncodedQuad) -> Result<()> { fn insert(&self, quad: &EncodedQuad) -> Result<()> {
let mut graph_indexes = self.graph_indexes.write()?; let mut graph_indexes = self.graph_indexes.write()?;
let graph = graph_indexes let graph = graph_indexes
.entry(quad.graph_name.clone()) .entry(quad.graph_name)
.or_insert_with(MemoryGraphIndexes::default); .or_insert_with(MemoryGraphIndexes::default);
graph graph
.spo .spo
.entry(quad.subject.clone()) .entry(quad.subject)
.or_default() .or_default()
.entry(quad.predicate.clone()) .entry(quad.predicate)
.or_default() .or_default()
.insert(quad.object.clone()); .insert(quad.object);
graph graph
.pos .pos
.entry(quad.predicate.clone()) .entry(quad.predicate)
.or_default() .or_default()
.entry(quad.object.clone()) .entry(quad.object)
.or_default() .or_default()
.insert(quad.subject.clone()); .insert(quad.subject);
graph graph
.osp .osp
.entry(quad.object.clone()) .entry(quad.object)
.or_default() .or_default()
.entry(quad.subject.clone()) .entry(quad.subject)
.or_default() .or_default()
.insert(quad.predicate.clone()); .insert(quad.predicate);
Ok(()) Ok(())
} }
@ -446,10 +446,5 @@ fn encoded_quad(
object: &EncodedTerm, object: &EncodedTerm,
graph_name: &EncodedTerm, graph_name: &EncodedTerm,
) -> EncodedQuad { ) -> EncodedQuad {
EncodedQuad::new( EncodedQuad::new(*subject, *predicate, *object, *graph_name)
subject.clone(),
predicate.clone(),
object.clone(),
graph_name.clone(),
)
} }

@ -24,7 +24,7 @@ const TYPE_TYPED_LITERAL_ID: u8 = 4;
pub static ENCODED_DEFAULT_GRAPH: EncodedTerm = EncodedTerm::DefaultGraph {}; pub static ENCODED_DEFAULT_GRAPH: EncodedTerm = EncodedTerm::DefaultGraph {};
#[derive(Eq, PartialEq, Ord, PartialOrd, Debug, Clone, Hash)] #[derive(Eq, PartialEq, Ord, PartialOrd, Debug, Clone, Copy, Hash)]
pub enum EncodedTerm { pub enum EncodedTerm {
DefaultGraph {}, DefaultGraph {},
NamedNode { iri_id: u64 }, NamedNode { iri_id: u64 },
@ -252,7 +252,7 @@ impl<S: BytesStore> Encoder<S> {
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) => self.encode_named_or_blank_node(&graph_name)?, Some(graph_name) => self.encode_named_or_blank_node(&graph_name)?,
None => ENCODED_DEFAULT_GRAPH.clone(), None => ENCODED_DEFAULT_GRAPH,
}, },
}) })
} }
@ -266,7 +266,7 @@ impl<S: BytesStore> Encoder<S> {
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.clone(), graph_name: *graph_name,
}) })
} }

@ -130,7 +130,7 @@ impl EncodedQuadsStore for RocksDbStore {
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.clone()), None, None, None), filter: EncodedQuadPattern::new(Some(*subject), None, None, None),
}) })
} }
@ -143,12 +143,7 @@ impl EncodedQuadsStore for RocksDbStore {
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( filter: EncodedQuadPattern::new(Some(*subject), Some(*predicate), None, None),
Some(subject.clone()),
Some(predicate.clone()),
None,
None,
),
}) })
} }
@ -162,12 +157,7 @@ impl EncodedQuadsStore for RocksDbStore {
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( filter: EncodedQuadPattern::new(Some(*subject), Some(*predicate), Some(*object), None),
Some(subject.clone()),
Some(predicate.clone()),
Some(object.clone()),
None,
),
}) })
} }
@ -180,12 +170,7 @@ impl EncodedQuadsStore for RocksDbStore {
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( filter: EncodedQuadPattern::new(Some(*subject), None, Some(*object), None),
Some(subject.clone()),
None,
Some(object.clone()),
None,
),
}) })
} }
@ -197,7 +182,7 @@ impl EncodedQuadsStore for RocksDbStore {
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.clone()), None, None), filter: EncodedQuadPattern::new(None, Some(*predicate), None, None),
}) })
} }
@ -210,12 +195,7 @@ impl EncodedQuadsStore for RocksDbStore {
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( filter: EncodedQuadPattern::new(None, Some(*predicate), Some(*object), None),
None,
Some(predicate.clone()),
Some(object.clone()),
None,
),
}) })
} }
@ -227,7 +207,7 @@ impl EncodedQuadsStore for RocksDbStore {
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.clone()), None), filter: EncodedQuadPattern::new(None, None, Some(*object), None),
}) })
} }
@ -237,7 +217,7 @@ impl EncodedQuadsStore for RocksDbStore {
) -> Result<InGraphQuadsIterator<SPOGIndexIterator>> { ) -> Result<InGraphQuadsIterator<SPOGIndexIterator>> {
Ok(InGraphQuadsIterator { Ok(InGraphQuadsIterator {
iter: self.quads()?, iter: self.quads()?,
graph_name: graph_name.clone(), graph_name: *graph_name,
}) })
} }
@ -248,7 +228,7 @@ impl EncodedQuadsStore for RocksDbStore {
) -> 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.clone(), graph_name: *graph_name,
}) })
} }
@ -260,7 +240,7 @@ impl EncodedQuadsStore for RocksDbStore {
) -> 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.clone(), graph_name: *graph_name,
}) })
} }
@ -272,7 +252,7 @@ impl EncodedQuadsStore for RocksDbStore {
) -> 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.clone(), graph_name: *graph_name,
}) })
} }
@ -283,7 +263,7 @@ impl EncodedQuadsStore for RocksDbStore {
) -> 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.clone(), graph_name: *graph_name,
}) })
} }
@ -295,7 +275,7 @@ impl EncodedQuadsStore for RocksDbStore {
) -> 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.clone(), graph_name: *graph_name,
}) })
} }
@ -306,7 +286,7 @@ impl EncodedQuadsStore for RocksDbStore {
) -> 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.clone(), graph_name: *graph_name,
}) })
} }

Loading…
Cancel
Save