uni_algo/algo/cypher/
triangle_count.rs1use crate::algo::algorithms::{Algorithm, TriangleCount, TriangleCountConfig};
7use crate::algo::procedure_template::{GenericAlgoProcedure, GraphAlgoAdapter};
8use crate::algo::procedures::{AlgoResultRow, ValueType};
9use anyhow::Result;
10use serde_json::{Value, json};
11
12pub struct TriangleCountAdapter;
13
14impl GraphAlgoAdapter for TriangleCountAdapter {
15 const NAME: &'static str = "uni.algo.triangleCount";
16 type Algo = TriangleCount;
17
18 fn specific_args() -> Vec<(&'static str, ValueType, Option<Value>)> {
19 vec![]
20 }
21
22 fn yields() -> Vec<(&'static str, ValueType)> {
23 vec![
24 ("nodeId", ValueType::Int),
25 ("triangleCount", ValueType::Int),
26 ]
27 }
28
29 fn to_config(_args: Vec<Value>) -> TriangleCountConfig {
30 TriangleCountConfig
31 }
32
33 fn map_result(result: <Self::Algo as Algorithm>::Result) -> Result<Vec<AlgoResultRow>> {
34 Ok(result
35 .node_counts
36 .into_iter()
37 .map(|(vid, count)| AlgoResultRow {
38 values: vec![json!(vid.as_u64()), json!(count)],
39 })
40 .collect())
41 }
42
43 fn include_reverse() -> bool {
44 true
45 }
46}
47
48pub type TriangleCountProcedure = GenericAlgoProcedure<TriangleCountAdapter>;