Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ rocksdb = "0.12.2"
lru = "0.1.15"
scoped_threadpool = "0.1.9"
walkdir = "2.0.0"
time = "0.1"

[dependencies.hdfs]
git="https://github.com/UNSW-database/hdfs-rs.git"
Expand Down
8 changes: 8 additions & 0 deletions src/generic/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,14 @@ pub trait GraphLabelTrait<Id: IdType, NL: Hash + Eq, EL: Hash + Eq, L: IdType>:
.filter_map(|(s, d)| self.get_edge_label(s, d))
.collect()
}

/// Trait for labelled graphs.
fn neighbors_of_node_iter(&self, id: Id, label: Option<NL>) -> Iter<Id>;
fn neighbors_of_edge_iter(&self, id: Id, label: Option<EL>) -> Iter<Id>;
fn neighbors_of_node(&self, id: Id, label: Option<NL>) -> Cow<[Id]>;
fn neighbors_of_edge(&self, id: Id, label: Option<EL>) -> Cow<[Id]>;
fn nodes_with_label(&self, label: Option<NL>) -> Iter<Id>;
fn edges_with_label(&self, label: Option<EL>) -> Iter<(Id, Id)>;
}

pub trait MutGraphLabelTrait<Id: IdType, NL: Hash + Eq, EL: Hash + Eq, L: IdType>:
Expand Down
6 changes: 6 additions & 0 deletions src/generic/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
*/
use generic::IdType;
pub use graph_impl::graph_map::NodeMap;
use graph_impl::multi_graph::node::MultiNode;
pub use graph_impl::static_graph::StaticNode;

pub trait NodeTrait<Id: IdType, L: IdType> {
Expand Down Expand Up @@ -55,6 +56,7 @@ pub enum OwnedNodeType<Id: IdType, L: IdType = Id> {
pub enum NodeType<'a, Id: 'a + IdType, L: 'a + IdType = Id> {
NodeMap(&'a NodeMap<Id, L>),
StaticNode(StaticNode<Id, L>),
MultiNode(MultiNode<Id, L>),
None,
}

Expand Down Expand Up @@ -133,6 +135,7 @@ impl<'a, Id: IdType, L: IdType> NodeType<'a, Id, L> {
match self {
NodeType::NodeMap(node) => node,
NodeType::StaticNode(_) => panic!("`unwrap_nodemap()` on `StaticNode`"),
NodeType::MultiNode(_) => panic!("`unwrap_nodemap()` on `MultiNode`"),
NodeType::None => panic!("`unwrap_nodemap()` on `None`"),
}
}
Expand All @@ -142,6 +145,7 @@ impl<'a, Id: IdType, L: IdType> NodeType<'a, Id, L> {
match self {
NodeType::NodeMap(_) => panic!("`unwrap_staticnode()` on `NodeMap`"),
NodeType::StaticNode(node) => node,
NodeType::MultiNode(node) => panic!("`unwrap_staticnode()` on `MultiNode`"),
NodeType::None => panic!("`unwrap_staticnode()` on `None`"),
}
}
Expand All @@ -161,6 +165,7 @@ impl<'a, Id: IdType, L: IdType> NodeTrait<Id, L> for NodeType<'a, Id, L> {
match self {
NodeType::NodeMap(node) => node.get_id(),
NodeType::StaticNode(ref node) => node.get_id(),
NodeType::MultiNode(ref node) => node.get_id(),
NodeType::None => panic!("`get_id()` on `None`"),
}
}
Expand All @@ -170,6 +175,7 @@ impl<'a, Id: IdType, L: IdType> NodeTrait<Id, L> for NodeType<'a, Id, L> {
match self {
NodeType::NodeMap(node) => node.get_label_id(),
NodeType::StaticNode(ref node) => node.get_label_id(),
NodeType::MultiNode(ref node) => node.get_label_id(),
NodeType::None => None,
}
}
Expand Down
24 changes: 24 additions & 0 deletions src/graph_impl/graph_map/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,30 @@ impl<Id: IdType, NL: Hash + Eq, EL: Hash + Eq, Ty: GraphType, L: IdType>
fn get_edge_label_map(&self) -> &SetMap<EL> {
&self.edge_label_map
}

fn neighbors_of_node_iter(&self, id: Id, label: Option<NL>) -> Iter<Id> {
unimplemented!()
}

fn neighbors_of_edge_iter(&self, id: Id, label: Option<EL>) -> Iter<Id> {
unimplemented!()
}

fn neighbors_of_node(&self, id: Id, label: Option<NL>) -> Cow<[Id]> {
unimplemented!()
}

fn neighbors_of_edge(&self, id: Id, label: Option<EL>) -> Cow<[Id]> {
unimplemented!()
}

fn nodes_with_label(&self, label: Option<NL>) -> Iter<Id> {
unimplemented!()
}

fn edges_with_label(&self, label: Option<EL>) -> Iter<(Id, Id)> {
unimplemented!()
}
}

impl<Id: IdType, NL: Hash + Eq, EL: Hash + Eq, Ty: GraphType, L: IdType>
Expand Down
11 changes: 6 additions & 5 deletions src/graph_impl/graph_vec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,6 @@ impl<Id: IdType, NL: Hash + Eq, EL: Hash + Eq, L: IdType> TypedGraphVec<Id, NL,
}

let max_id = self.max_id.unwrap();

let node_labels = Self::get_node_labels(self.nodes, max_id, self.has_node_label);
let edge_vec = Self::get_edge_vec(self.edges, max_id, self.has_edge_label);
let in_edge_vec = if Ty::is_directed() {
Expand Down Expand Up @@ -339,17 +338,17 @@ mod tests {
let mut g = GraphVec::<&str>::new();
g.add_node(0, Some("node0"));
g.add_node(2, Some("node2"));
g.add_node(2, Some("node2"));
g.add_edge(0, 1, Some("(0,1)"));
g.add_edge(1, 0, Some("(0,1)"));
g.add_edge(0, 3, Some("(0,3)"));
g.add_edge(3, 0, Some("(0,3)"));

let un_graph = g.clone().into_static::<Undirected, u16>();

let un_graph_true = UnStaticGraph::<&str, &str, u16>::from_raw(
4,
1,
EdgeVec::with_labels(vec![0, 2, 3, 3, 3], vec![1, 3, 0], vec![0, 1, 0]),
2,
EdgeVec::with_labels(vec![0, 2, 3, 3, 4], vec![1, 3, 0, 0], vec![0, 1, 0, 1]),
None,
Some(vec![0, u16::max_value(), 1, u16::max_value()]),
vec!["node0", "node2"].into(),
Expand All @@ -366,17 +365,19 @@ mod tests {
g.add_edge(0, 1, Some("(0,1)"));
g.add_in_edge(1, 0);
g.add_edge(0, 3, Some("(0,3)"));
g.add_in_edge(3, 0);

assert_eq!(g.node_count(), 2);
assert_eq!(g.edge_count(), 2);

let di_graph = g.clone().into_static::<Directed, u32>();

println!("My turn...");
let di_graph_true = DiStaticGraph::<&str>::from_raw(
4,
2,
EdgeVec::with_labels(vec![0, 2, 2, 2, 2], vec![1, 3], vec![0, 1]),
Some(EdgeVec::new(vec![0, 0, 1, 1, 1], vec![0])),
Some(EdgeVec::new(vec![0, 0, 1, 1, 2], vec![0, 0])),
Some(vec![0, u32::max_value(), 1, u32::max_value()]),
vec!["node0", "node2"].into(),
vec!["(0,1)", "(0,3)"].into(),
Expand Down
3 changes: 3 additions & 0 deletions src/graph_impl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
*/
pub mod graph_map;
pub mod graph_vec;
pub mod multi_graph;
pub mod static_graph;

pub use graph_impl::graph_map::{
Expand All @@ -36,6 +37,7 @@ pub use graph_impl::static_graph::{
pub enum GraphImpl {
GraphMap,
StaticGraph,
MultiGraph,
}

impl ::std::str::FromStr for GraphImpl {
Expand All @@ -45,6 +47,7 @@ impl ::std::str::FromStr for GraphImpl {
match s.as_ref() {
"graphmap" => Ok(GraphImpl::GraphMap),
"staticgraph" => Ok(GraphImpl::StaticGraph),
"multigraph" => Ok(GraphImpl::MultiGraph),
_other => Err(format!("Unsupported implementation {:?}", _other)),
}
}
Expand Down
7 changes: 7 additions & 0 deletions src/graph_impl/multi_graph/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#[macro_use]
pub mod plan;
pub mod node;
pub mod planner;
pub mod query;
pub mod runner;
pub mod utils;
58 changes: 58 additions & 0 deletions src/graph_impl/multi_graph/node.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* Copyright (c) 2018 UNSW Sydney, Data and Knowledge Group.
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
use generic::{IdType, NodeTrait};

#[derive(Debug, Clone, PartialEq, Eq)]
pub struct MultiNode<Id: IdType, L: IdType = Id> {
id: Id,
label: Option<L>,
}

impl<Id: IdType, L: IdType> MultiNode<Id, L> {
#[inline(always)]
pub fn new(id: Id, label: Option<L>) -> Self {
MultiNode { id, label }
}

#[inline(always)]
pub fn new_static(id: Id, label: L) -> Self {
MultiNode {
id,
label: if label == L::max_value() {
None
} else {
Some(label)
},
}
}
}

impl<Id: IdType, L: IdType> NodeTrait<Id, L> for MultiNode<Id, L> {
#[inline(always)]
fn get_id(&self) -> Id {
self.id
}

#[inline(always)]
fn get_label_id(&self) -> Option<L> {
self.label
}
}
4 changes: 4 additions & 0 deletions src/graph_impl/multi_graph/plan/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#[macro_use]
pub mod operator;
pub mod query_plan;
pub mod query_plan_worker;
Loading