use std::fmt;
use super::{GraphConstructionOptions, GraphEdgeColumnBindings};
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct EdgeNormalizeSpec {
pub edge_columns: GraphEdgeColumnBindings,
pub add_reverse: bool,
pub dedup: EdgeDedupStrategy,
pub weight_combiner: EdgeWeightCombiner,
}
impl EdgeNormalizeSpec {
pub fn python_cugraph(edge_columns: GraphEdgeColumnBindings, graph_options: &GraphConstructionOptions) -> Self {
let has_weight = edge_columns.weight.is_some();
let (dedup, weight_combiner) = match (graph_options.directed, has_weight) {
(_, false) => (EdgeDedupStrategy::KeepLast, EdgeWeightCombiner::None),
(true, true) => (EdgeDedupStrategy::KeepLast, EdgeWeightCombiner::KeepLastInputOrder),
(false, true) => (EdgeDedupStrategy::KeepFirst, EdgeWeightCombiner::MinWeight),
};
Self { edge_columns, add_reverse: !graph_options.directed, dedup, weight_combiner }
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum EdgeDedupStrategy {
None,
KeepFirst,
KeepLast,
}
impl EdgeDedupStrategy {
pub const fn as_str(self) -> &'static str {
match self {
Self::None => "none",
Self::KeepFirst => "keep_first",
Self::KeepLast => "keep_last",
}
}
}
impl fmt::Display for EdgeDedupStrategy {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(self.as_str())
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum EdgeWeightCombiner {
None,
MinWeight,
KeepLastInputOrder,
}
impl EdgeWeightCombiner {
pub const fn as_str(self) -> &'static str {
match self {
Self::None => "none",
Self::MinWeight => "min_weight",
Self::KeepLastInputOrder => "keep_last_input_order",
}
}
}
impl fmt::Display for EdgeWeightCombiner {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(self.as_str())
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
pub enum GraphKCoreDegreeType {
In,
Out,
#[default]
InOut,
}
impl GraphKCoreDegreeType {
pub const fn as_str(self) -> &'static str {
match self {
Self::In => "in",
Self::Out => "out",
Self::InOut => "in_out",
}
}
}
impl fmt::Display for GraphKCoreDegreeType {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(self.as_str())
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub struct GraphDegreesAllParams;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub struct GraphInDegreesAllParams;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub struct GraphOutDegreesAllParams;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub struct GraphTriangleCountAllParams;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct GraphCoreNumberParams {
pub degree_type: GraphKCoreDegreeType,
}
impl Default for GraphCoreNumberParams {
fn default() -> Self {
Self { degree_type: GraphKCoreDegreeType::InOut }
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct GraphKCoreParams {
pub k: u32,
pub degree_type: GraphKCoreDegreeType,
}
impl Default for GraphKCoreParams {
fn default() -> Self {
Self { k: 2, degree_type: GraphKCoreDegreeType::InOut }
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub struct GraphMstParams;