Adds method to get the size of a Graph or a Dataset

pull/10/head
Tpt 6 years ago
parent 08f1a68c44
commit 439719732c
  1. 1
      Cargo.toml
  2. 8
      src/store/mod.rs
  3. 35
      src/store/store.rs

@ -20,6 +20,7 @@ lazy_static = "1"
rocksdb = "0.10" rocksdb = "0.10"
url = "1" url = "1"
uuid = { version = "0.6", features = ["v4"] } uuid = { version = "0.6", features = ["v4"] }
bzip2 = "0.3"
byteorder = "1" byteorder = "1"
[build-dependencies] [build-dependencies]

@ -57,6 +57,10 @@ pub trait Graph {
fn insert(&self, triple: &Triple) -> Result<()>; fn insert(&self, triple: &Triple) -> Result<()>;
fn remove(&self, triple: &Triple) -> Result<()>; fn remove(&self, triple: &Triple) -> Result<()>;
fn len(&self) -> Result<usize>;
fn is_empty(&self) -> Result<bool>;
} }
pub trait NamedGraph: Graph { pub trait NamedGraph: Graph {
@ -128,4 +132,8 @@ pub trait Dataset {
fn insert(&self, quad: &Quad) -> Result<()>; fn insert(&self, quad: &Quad) -> Result<()>;
fn remove(&self, quad: &Quad) -> Result<()>; fn remove(&self, quad: &Quad) -> Result<()>;
fn len(&self) -> Result<usize>;
fn is_empty(&self) -> Result<bool>;
} }

@ -266,6 +266,14 @@ impl<S: EncodedQuadsStore> Dataset for StoreDataset<S> {
fn remove(&self, quad: &Quad) -> Result<()> { fn remove(&self, quad: &Quad) -> Result<()> {
self.store.remove(&self.store.encoder().encode_quad(quad)?) self.store.remove(&self.store.encoder().encode_quad(quad)?)
} }
fn len(&self) -> Result<usize> {
Ok(self.store.quads()?.count())
}
fn is_empty(&self) -> Result<bool> {
Ok(self.store.quads()?.any(|_| true))
}
} }
pub struct StoreNamedGraph<S: EncodedQuadsStore> { pub struct StoreNamedGraph<S: EncodedQuadsStore> {
@ -403,6 +411,17 @@ impl<S: EncodedQuadsStore> Graph for StoreNamedGraph<S> {
.encode_triple_in_graph(triple, self.encoded_name.clone())?, .encode_triple_in_graph(triple, self.encoded_name.clone())?,
) )
} }
fn len(&self) -> Result<usize> {
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))
}
} }
impl<S: EncodedQuadsStore> NamedGraph for StoreNamedGraph<S> { impl<S: EncodedQuadsStore> NamedGraph for StoreNamedGraph<S> {
@ -530,6 +549,14 @@ impl<S: EncodedQuadsStore> Graph for StoreDefaultGraph<S> {
self.store self.store
.remove(&self.store.encoder().encode_triple_in_graph(triple, None)?) .remove(&self.store.encoder().encode_triple_in_graph(triple, None)?)
} }
fn len(&self) -> Result<usize> {
Ok(self.store.quads_for_graph(&None)?.count())
}
fn is_empty(&self) -> Result<bool> {
Ok(self.store.quads_for_graph(&None)?.any(|_| true))
}
} }
pub struct StoreUnionGraph<S: EncodedQuadsStore> { pub struct StoreUnionGraph<S: EncodedQuadsStore> {
@ -650,6 +677,14 @@ impl<S: EncodedQuadsStore> Graph for StoreUnionGraph<S> {
fn remove(&self, triple: &Triple) -> Result<()> { fn remove(&self, triple: &Triple) -> Result<()> {
unimplemented!() unimplemented!()
} }
fn len(&self) -> Result<usize> {
Ok(self.store.quads()?.count())
}
fn is_empty(&self) -> Result<bool> {
Ok(self.store.quads()?.any(|_| true))
}
} }
pub struct DelegatingBytesStore<'a, S: 'a + BytesStore + Sized>(&'a S); pub struct DelegatingBytesStore<'a, S: 'a + BytesStore + Sized>(&'a S);

Loading…
Cancel
Save