use crate::{
db::{
api::{
properties::{Metadata, Properties},
state::ops::{ArrowNodeOp, GraphView, NodeOp},
},
graph::node::NodeView,
},
prelude::{GraphViewOps, PropertiesOps},
};
use raphtory_api::core::{
entities::{properties::prop::Prop, VID},
storage::arc_str::ArcStr,
};
use raphtory_storage::graph::graph::GraphStorage;
use std::{collections::HashMap, fmt::Debug, marker::PhantomData};
#[derive(Debug, Clone)]
pub struct GetProperties<'graph, G> {
pub(crate) graph: G,
_marker: PhantomData<&'graph ()>,
}
impl<'graph, G> GetProperties<'graph, G> {
pub fn new(graph: G) -> Self {
Self {
graph,
_marker: PhantomData,
}
}
}
impl<'graph, G: GraphView + 'graph> From<Properties<NodeView<'graph, G>>>
for HashMap<ArcStr, Option<Prop>>
{
fn from(properties: Properties<NodeView<'graph, G>>) -> Self {
HashMap::from_iter(properties.iter())
}
}
impl<'graph, G: GraphViewOps<'graph>> NodeOp for GetProperties<'graph, G> {
type Output = Properties<NodeView<'graph, G>>;
fn apply(&self, _storage: &GraphStorage, node: VID) -> Self::Output {
Properties::new(NodeView::new_internal(self.graph.clone(), node))
}
}
impl<'graph, G: GraphViewOps<'graph>> ArrowNodeOp for GetProperties<'graph, G> {
type ArrowOutput = HashMap<ArcStr, Option<Prop>>;
}
#[derive(Debug, Clone)]
pub struct GetMetadata<'graph, G> {
pub(crate) graph: G,
_marker: PhantomData<&'graph ()>,
}
impl<'graph, G> GetMetadata<'graph, G> {
pub fn new(graph: G) -> Self {
Self {
graph,
_marker: PhantomData,
}
}
}
impl<'graph, G: GraphView + 'graph> From<Metadata<'graph, NodeView<'graph, G>>>
for HashMap<ArcStr, Option<Prop>>
{
fn from(metadata: Metadata<'graph, NodeView<'graph, G>>) -> Self {
HashMap::from_iter(metadata.iter())
}
}
impl<'graph, G: GraphViewOps<'graph>> NodeOp for GetMetadata<'graph, G> {
type Output = Metadata<'graph, NodeView<'graph, G>>;
fn apply(&self, _storage: &GraphStorage, node: VID) -> Self::Output {
Metadata::new(NodeView::new_internal(self.graph.clone(), node))
}
}
impl<'graph, G: GraphViewOps<'graph>> ArrowNodeOp for GetMetadata<'graph, G> {
type ArrowOutput = HashMap<ArcStr, Option<Prop>>;
}