Skip to content

Commit

Permalink
impl at and fix in/out degree (#1399)
Browse files Browse the repository at this point in the history
  • Loading branch information
shivamka1 authored Nov 30, 2023
1 parent c9f9eba commit b657a70
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 12 deletions.
12 changes: 12 additions & 0 deletions raphtory-graphql/src/model/graph/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,18 @@ impl GqlGraph {
w.into_dynamic_indexed().into()
}

async fn at(&self, time: i64) -> GqlGraph {
self.graph.at(time).into_dynamic_indexed().into()
}

async fn before(&self, time: i64) -> GqlGraph {
self.graph.before(time).into_dynamic_indexed().into()
}

async fn after(&self, time: i64) -> GqlGraph {
self.graph.after(time).into_dynamic_indexed().into()
}

async fn layer_names(&self) -> Vec<String> {
self.graph.unique_layers().map_into().collect()
}
Expand Down
36 changes: 24 additions & 12 deletions raphtory-graphql/src/model/graph/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,24 +164,36 @@ impl Node {
}

/// Returns the number edges with this node as the source
async fn out_degree(&self, layer: Option<String>) -> usize {
match layer.as_deref() {
async fn out_degree(&self, layers: Option<Vec<String>>) -> usize {
match layers {
None => self.vv.out_degree(),
Some(layer) => match self.vv.layer(layer) {
None => 0,
Some(vvv) => vvv.out_degree(),
},
Some(layers) => layers
.iter()
.map(|layer| {
let degree = match self.vv.layer(layer) {
None => 0,
Some(vvv) => vvv.out_degree(),
};
degree
})
.sum(),
}
}

/// Returns the number edges with this node as the destination
async fn in_degree(&self, layer: Option<String>) -> usize {
match layer.as_deref() {
async fn in_degree(&self, layers: Option<Vec<String>>) -> usize {
match layers {
None => self.vv.in_degree(),
Some(layer) => match self.vv.layer(layer) {
None => 0,
Some(vvv) => vvv.in_degree(),
},
Some(layers) => layers
.iter()
.map(|layer| {
let degree = match self.vv.layer(layer) {
None => 0,
Some(vvv) => vvv.in_degree(),
};
degree
})
.sum(),
}
}

Expand Down

0 comments on commit b657a70

Please sign in to comment.