Skip to content

Commit

Permalink
Fix graph indexing in IndexedBTreeMap.
Browse files Browse the repository at this point in the history
  • Loading branch information
timothee-haudebourg committed Mar 26, 2024
1 parent 1030f2b commit 85e14ff
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/dataset/impl/indexed_btree_dataset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ impl<R: Ord> IndexedBTreeDataset<R> {

let g_i = match g_i {
Some((_, Some(g_i))) => {
self.resources[g_i].as_object.insert(i);
self.resources[g_i].as_graph.insert(i);
Some(g_i)
}
Some((g, None)) => {
Expand Down Expand Up @@ -342,7 +342,7 @@ impl<R: Ord> IndexedBTreeDataset<R> {
.remove(quad_cmp(&self.resources, &self.quads), &quad)
{
Some(i) => {
self.remove_by_index(i);
self.remove_by_index(i, false);
true
}
None => false,
Expand All @@ -369,14 +369,19 @@ impl<R: Ord> IndexedBTreeDataset<R> {
let mut graph = BTreeGraph::new();
for i in indexes {
let quad = quad_with_resources(&self.resources, self.quads[i]).cloned();
self.remove_by_index(i);
self.remove_by_index(i, true);
graph.insert(quad.into_triple().0); // TODO: could be optimized
}

Some(graph)
}

fn remove_by_index(&mut self, i: usize) {
fn remove_by_index(&mut self, i: usize, remove_index: bool) {
if remove_index {
self.quads_indexes
.remove(quad_index_cmp(&self.resources, &self.quads), &i);
}

let Quad(s_i, p_i, o_i, g_i) = self.quads.remove(i);

self.subjects.remove(&s_i);
Expand Down Expand Up @@ -790,7 +795,7 @@ impl<'a, R: Clone + Ord> Iterator for ExtractPatternMatching<'a, R> {
Ok(()) => match self.graph.next(i, quad) {
Ok(()) => {
let value = quad_with_resources(&self.dataset.resources, quad).cloned();
self.dataset.remove_by_index(i);
self.dataset.remove_by_index(i, true);
self.i = i + 1;
return Some(value);
}
Expand Down

0 comments on commit 85e14ff

Please sign in to comment.