From 44354eae7a97c8ddf4c6041e9ee946ffce2748ec Mon Sep 17 00:00:00 2001 From: Ben Steer Date: Mon, 3 Jul 2023 20:21:10 +0100 Subject: [PATCH] Fixed all warnings and refactor module structure (#1081) * Fixed all warnings * first attempt at core refactor * Refactored db * Fixed all tests in benchmark graphql python and core * Added rustfmt file * fix neo tests * Renamed views * more tests * more tests * Fix JS * more tests * Fix all imports * Moved comparison benchmarks * Changed outer tgraph to entities * refactored python * Removed Perspectives as not being used * remove perspective ref * Final fmt --- .rustfmt.toml | 2 + .../benchmark_base.py | 0 .../benchmark_driver.py | 0 .../benchmark_imports.py | 0 .../cozo_bench.py | 0 .../graphtool_bench.py | 0 .../kuzu_bench.py | 0 .../memgraph_bench.py | 0 .../neo4j_bench.py | 0 .../networkx_bench.py | 0 .../profile_bench.py | 0 .../raphtory_bench.py | 0 {benchmark => comparison-benchmark}/readme.md | 0 examples/custom-algorithm/src/main.rs | 2 +- examples/rust/src/bin/bench/main.rs | 16 +-- examples/rust/src/bin/btc/main.rs | 34 +++--- examples/rust/src/bin/crypto/main.rs | 14 ++- examples/rust/src/bin/hulongbay/main.rs | 33 +++-- examples/rust/src/bin/lotr/main.rs | 20 ++-- examples/rust/src/bin/pokec/main.rs | 16 +-- js-raphtory/src/graph/edge.rs | 6 +- js-raphtory/src/graph/graph_view_impl.rs | 3 +- js-raphtory/src/graph/misc.rs | 6 +- js-raphtory/src/graph/mod.rs | 40 +++---- js-raphtory/src/graph/vertex.rs | 13 +- python/src/lib.rs | 16 +-- raphtory-benchmark/benches/algobench.rs | 10 +- raphtory-benchmark/benches/base.rs | 2 +- raphtory-benchmark/benches/common/mod.rs | 14 +-- raphtory-benchmark/benches/edge_add.rs | 12 +- raphtory-benchmark/benches/graph_ops.rs | 3 +- raphtory-benchmark/benches/parameterized.rs | 2 +- .../benches/tgraph_benchmarks.rs | 5 +- raphtory-graphql/src/data.rs | 10 +- raphtory-graphql/src/lib.rs | 11 +- raphtory-graphql/src/model/algorithm.rs | 23 ++-- .../src/model/filters/edgefilter.rs | 9 +- raphtory-graphql/src/model/filters/mod.rs | 2 +- .../src/model/filters/nodefilter.rs | 16 +-- .../src/model/filters/property.rs | 6 +- raphtory-graphql/src/model/graph/edge.rs | 14 ++- raphtory-graphql/src/model/graph/graph.rs | 17 +-- raphtory-graphql/src/model/graph/node.rs | 24 ++-- raphtory-graphql/src/model/mod.rs | 15 +-- raphtory-graphql/src/observability/tracing.rs | 8 +- raphtory-graphql/src/routes.rs | 9 +- raphtory-graphql/src/server.rs | 23 ++-- raphtory/Cargo.toml | 2 +- .../src/algorithms/clustering_coefficient.rs | 14 ++- .../src/algorithms/connected_components.rs | 12 +- raphtory/src/algorithms/degree.rs | 5 +- .../src/algorithms/directed_graph_density.rs | 5 +- raphtory/src/algorithms/hits.rs | 16 +-- .../local_clustering_coefficient.rs | 18 +-- .../src/algorithms/local_triangle_count.rs | 14 +-- .../algorithms/motifs/three_node_eval_wip.rs | 37 +++--- .../src/algorithms/motifs/three_node_local.rs | 11 +- raphtory/src/algorithms/pagerank.rs | 15 ++- raphtory/src/algorithms/reciprocity.rs | 33 +++-- .../src/algorithms/temporal_reachability.rs | 28 +++-- raphtory/src/algorithms/triangle_count.rs | 23 ++-- raphtory/src/algorithms/triplet_count.rs | 28 +++-- .../core/{tgraph => entities/edges}/edge.rs | 34 +++--- .../src/core/{ => entities/edges}/edge_ref.rs | 4 +- .../{tgraph => entities/edges}/edge_store.rs | 19 +-- raphtory/src/core/entities/edges/mod.rs | 3 + raphtory/src/core/entities/graph/mod.rs | 3 + .../core/{tgraph => entities/graph}/tgraph.rs | 59 ++++----- .../graph}/tgraph_storage.rs | 35 +++--- .../core/{tgraph => entities/graph}/timer.rs | 3 +- raphtory/src/core/{tgraph => entities}/mod.rs | 31 ++--- .../properties}/graph_props.rs | 12 +- raphtory/src/core/entities/properties/mod.rs | 4 + .../{tgraph => entities/properties}/props.rs | 66 +++++----- .../core/{ => entities/properties}/tcell.rs | 6 +- .../core/{ => entities/properties}/tprop.rs | 7 +- .../vertices/input_vertex.rs} | 4 +- raphtory/src/core/entities/vertices/mod.rs | 5 + .../vertices/structure}/adj.rs | 8 +- .../vertices/structure}/adjset.rs | 0 .../vertices/structure}/iter.rs | 11 +- .../core/entities/vertices/structure/mod.rs | 3 + .../{tgraph => entities/vertices}/vertex.rs | 41 ++++--- .../{ => entities/vertices}/vertex_ref.rs | 4 +- .../vertices/vertex_store.rs} | 35 +++--- raphtory/src/core/locked_view.rs | 30 ----- raphtory/src/core/mod.rs | 18 +-- raphtory/src/core/state/accumulator_id.rs | 6 +- raphtory/src/core/state/agg.rs | 8 +- raphtory/src/core/state/compute_state.rs | 7 +- raphtory/src/core/state/container.rs | 3 +- raphtory/src/core/state/mod.rs | 4 +- raphtory/src/core/state/morcel_state.rs | 3 +- raphtory/src/core/state/shuffle_state.rs | 15 +-- raphtory/src/core/storage/iter.rs | 3 +- raphtory/src/core/{ => storage}/lazy_vec.rs | 0 raphtory/src/core/storage/locked_view.rs | 18 +++ raphtory/src/core/storage/mod.rs | 17 +-- .../src/core/{ => storage}/sorted_vec_map.rs | 3 +- raphtory/src/core/{ => storage}/timeindex.rs | 8 +- raphtory/src/core/{ => utils}/errors.rs | 6 +- .../src/core/{utils.rs => utils/hashing.rs} | 3 +- raphtory/src/core/utils/mod.rs | 3 + raphtory/src/core/{ => utils}/time.rs | 7 +- raphtory/src/db/api/mod.rs | 2 + .../mutation}/addition_ops.rs | 15 ++- .../mutation}/deletion_ops.rs | 14 ++- .../internal/internal_addition_ops.rs | 7 +- .../internal/internal_deletion_ops.rs | 3 +- .../internal_property_additions_ops.rs | 7 +- .../mutation}/internal/mod.rs | 2 +- .../db/{mutation_api => api/mutation}/mod.rs | 0 .../mutation}/property_addition_ops.rs | 12 +- .../src/db/{view_api => api/view}/edge.rs | 12 +- .../src/db/{view_api => api/view}/graph.rs | 39 +++--- .../view}/internal/core_deletion_ops.rs | 11 +- .../view}/internal/core_ops.rs | 19 +-- .../view}/internal/exploded_edge_ops.rs | 16 ++- .../view}/internal/graph_ops.rs | 12 +- .../view}/internal/graph_properties_ops.rs | 12 +- .../view}/internal/graph_window_ops.rs | 13 +- .../view}/internal/inherit.rs | 0 .../src/db/api/view/internal/into_dynamic.rs | 34 ++++++ .../view}/internal/materialize.rs | 10 +- .../db/{view_api => api/view}/internal/mod.rs | 11 +- .../view}/internal/time_semantics.rs | 18 +-- .../view}/internal/wrapped_graph.rs | 2 +- .../src/db/{view_api => api/view}/layer.rs | 0 raphtory/src/db/{view_api => api/view}/mod.rs | 1 - .../src/db/{view_api => api/view}/time.rs | 18 +-- .../src/db/{view_api => api/view}/vertex.rs | 7 +- raphtory/src/db/{ => graph}/edge.rs | 26 ++-- raphtory/src/db/{ => graph}/graph.rs | 57 +++++---- raphtory/src/db/graph/mod.rs | 6 + raphtory/src/db/{ => graph}/path.rs | 36 +++--- raphtory/src/db/{ => graph}/vertex.rs | 32 ++--- raphtory/src/db/{ => graph}/vertices.rs | 22 ++-- .../views/deletion_graph.rs} | 52 ++++---- .../views/layer_graph.rs} | 16 +-- raphtory/src/db/graph/views/mod.rs | 4 + .../views/vertex_subgraph.rs} | 22 ++-- .../views/window_graph.rs} | 43 +++---- raphtory/src/db/internal/addition.rs | 4 +- raphtory/src/db/internal/core_ops.rs | 13 +- raphtory/src/db/internal/deletion.rs | 7 +- raphtory/src/db/internal/graph_ops.rs | 15 ++- raphtory/src/db/internal/materialize.rs | 7 +- raphtory/src/db/internal/prop_add.rs | 4 +- raphtory/src/db/internal/time_semantics.rs | 13 +- raphtory/src/db/mod.rs | 13 +- raphtory/src/db/task/context.rs | 17 +-- raphtory/src/db/task/{ => edge}/eval_edge.rs | 29 ++--- raphtory/src/db/task/edge/mod.rs | 2 + .../db/task/{ => edge}/window_eval_edge.rs | 22 ++-- raphtory/src/db/task/mod.rs | 14 +-- raphtory/src/db/task/task.rs | 11 +- raphtory/src/db/task/task_runner.rs | 52 ++++---- raphtory/src/db/task/task_state.rs | 9 +- .../src/db/task/{ => vertex}/eval_vertex.rs | 55 ++++----- .../db/task/{ => vertex}/eval_vertex_state.rs | 3 +- raphtory/src/db/task/vertex/mod.rs | 3 + .../task/{ => vertex}/window_eval_vertex.rs | 24 ++-- raphtory/src/db/{ => utils}/doc_strings.rs | 0 raphtory/src/db/utils/mod.rs | 1 + .../src/db/view_api/internal/into_dynamic.rs | 59 --------- .../src/graph_loader/example/company_house.rs | 11 +- .../src/graph_loader/example/lotr_graph.rs | 13 +- .../graph_loader/example/neo4j_examples.rs | 12 +- .../graph_loader/example/reddit_hyperlinks.rs | 23 ++-- .../src/graph_loader/example/stable_coins.rs | 14 +-- .../example/sx_superuser_graph.rs | 11 +- raphtory/src/graph_loader/mod.rs | 37 +++--- .../src/graph_loader/source/csv_loader.rs | 32 ++--- .../src/graph_loader/source/json_loader.rs | 9 +- .../src/graph_loader/source/neo4j_loader.rs | 18 ++- .../src/graphgen/preferential_attachment.rs | 11 +- raphtory/src/graphgen/random_attachment.rs | 11 +- raphtory/src/lib.rs | 17 ++- raphtory/src/python/{ => graph}/edge.rs | 45 ++++--- raphtory/src/python/{ => graph}/graph.rs | 24 ++-- .../{ => graph}/graph_with_deletions.rs | 28 +++-- raphtory/src/python/graph/mod.rs | 5 + raphtory/src/python/{ => graph}/vertex.rs | 44 ++++--- .../python/{ => graph/views}/graph_view.rs | 48 +++++--- raphtory/src/python/graph/views/mod.rs | 1 + raphtory/src/python/macros/mod.rs | 6 - raphtory/src/python/mod.rs | 14 +-- .../src/python/{ => packages}/algorithms.rs | 42 ++++--- .../src/python/{ => packages}/graph_gen.rs | 10 +- .../src/python/{ => packages}/graph_loader.rs | 7 +- raphtory/src/python/packages/mod.rs | 3 + raphtory/src/python/perspective.rs | 113 ------------------ raphtory/src/python/types/iterable.rs | 9 +- .../src/python/{ => types}/macros/iter.rs | 0 .../src/python/{ => types}/macros/iterable.rs | 2 +- raphtory/src/python/types/macros/mod.rs | 6 + .../{ => types}/macros/nested_iterable.rs | 0 raphtory/src/python/types/mod.rs | 4 + .../python/{ => types}/wrappers/iterators.rs | 17 +-- .../src/python/{ => types}/wrappers/mod.rs | 0 .../src/python/{ => types}/wrappers/prop.rs | 10 +- raphtory/src/python/{ => utils}/errors.rs | 10 +- .../src/python/{utils.rs => utils/mod.rs} | 19 +-- 203 files changed, 1466 insertions(+), 1486 deletions(-) create mode 100644 .rustfmt.toml rename {benchmark => comparison-benchmark}/benchmark_base.py (100%) rename {benchmark => comparison-benchmark}/benchmark_driver.py (100%) rename {benchmark => comparison-benchmark}/benchmark_imports.py (100%) rename {benchmark => comparison-benchmark}/cozo_bench.py (100%) rename {benchmark => comparison-benchmark}/graphtool_bench.py (100%) rename {benchmark => comparison-benchmark}/kuzu_bench.py (100%) rename {benchmark => comparison-benchmark}/memgraph_bench.py (100%) rename {benchmark => comparison-benchmark}/neo4j_bench.py (100%) rename {benchmark => comparison-benchmark}/networkx_bench.py (100%) rename {benchmark => comparison-benchmark}/profile_bench.py (100%) rename {benchmark => comparison-benchmark}/raphtory_bench.py (100%) rename {benchmark => comparison-benchmark}/readme.md (100%) rename raphtory/src/core/{tgraph => entities/edges}/edge.rs (93%) rename raphtory/src/core/{ => entities/edges}/edge_ref.rs (97%) rename raphtory/src/core/{tgraph => entities/edges}/edge_store.rs (96%) create mode 100644 raphtory/src/core/entities/edges/mod.rs create mode 100644 raphtory/src/core/entities/graph/mod.rs rename raphtory/src/core/{tgraph => entities/graph}/tgraph.rs (94%) rename raphtory/src/core/{tgraph => entities/graph}/tgraph_storage.rs (85%) rename raphtory/src/core/{tgraph => entities/graph}/timer.rs (99%) rename raphtory/src/core/{tgraph => entities}/mod.rs (80%) rename raphtory/src/core/{tgraph => entities/properties}/graph_props.rs (91%) create mode 100644 raphtory/src/core/entities/properties/mod.rs rename raphtory/src/core/{tgraph => entities/properties}/props.rs (80%) rename raphtory/src/core/{ => entities/properties}/tcell.rs (99%) rename raphtory/src/core/{ => entities/properties}/tprop.rs (99%) rename raphtory/src/core/{vertex.rs => entities/vertices/input_vertex.rs} (89%) create mode 100644 raphtory/src/core/entities/vertices/mod.rs rename raphtory/src/core/{tgraph => entities/vertices/structure}/adj.rs (96%) rename raphtory/src/core/{tgraph => entities/vertices/structure}/adjset.rs (100%) rename raphtory/src/core/{tgraph => entities/vertices/structure}/iter.rs (95%) create mode 100644 raphtory/src/core/entities/vertices/structure/mod.rs rename raphtory/src/core/{tgraph => entities/vertices}/vertex.rs (86%) rename raphtory/src/core/{ => entities/vertices}/vertex_ref.rs (93%) rename raphtory/src/core/{tgraph/node_store.rs => entities/vertices/vertex_store.rs} (94%) delete mode 100644 raphtory/src/core/locked_view.rs rename raphtory/src/core/{ => storage}/lazy_vec.rs (100%) create mode 100644 raphtory/src/core/storage/locked_view.rs rename raphtory/src/core/{ => storage}/sorted_vec_map.rs (99%) rename raphtory/src/core/{ => storage}/timeindex.rs (98%) rename raphtory/src/core/{ => utils}/errors.rs (95%) rename raphtory/src/core/{utils.rs => utils/hashing.rs} (94%) create mode 100644 raphtory/src/core/utils/mod.rs rename raphtory/src/core/{ => utils}/time.rs (98%) create mode 100644 raphtory/src/db/api/mod.rs rename raphtory/src/db/{mutation_api => api/mutation}/addition_ops.rs (92%) rename raphtory/src/db/{mutation_api => api/mutation}/deletion_ops.rs (76%) rename raphtory/src/db/{mutation_api => api/mutation}/internal/internal_addition_ops.rs (93%) rename raphtory/src/db/{mutation_api => api/mutation}/internal/internal_deletion_ops.rs (91%) rename raphtory/src/db/{mutation_api => api/mutation}/internal/internal_property_additions_ops.rs (95%) rename raphtory/src/db/{mutation_api => api/mutation}/internal/mod.rs (90%) rename raphtory/src/db/{mutation_api => api/mutation}/mod.rs (100%) rename raphtory/src/db/{mutation_api => api/mutation}/property_addition_ops.rs (93%) rename raphtory/src/db/{view_api => api/view}/edge.rs (97%) rename raphtory/src/db/{view_api => api/view}/graph.rs (94%) rename raphtory/src/db/{view_api => api/view}/internal/core_deletion_ops.rs (82%) rename raphtory/src/db/{view_api => api/view}/internal/core_ops.rs (96%) rename raphtory/src/db/{view_api => api/view}/internal/exploded_edge_ops.rs (92%) rename raphtory/src/db/{view_api => api/view}/internal/graph_ops.rs (97%) rename raphtory/src/db/{view_api => api/view}/internal/graph_properties_ops.rs (96%) rename raphtory/src/db/{view_api => api/view}/internal/graph_window_ops.rs (97%) rename raphtory/src/db/{view_api => api/view}/internal/inherit.rs (100%) create mode 100644 raphtory/src/db/api/view/internal/into_dynamic.rs rename raphtory/src/db/{view_api => api/view}/internal/materialize.rs (86%) rename raphtory/src/db/{view_api => api/view}/internal/mod.rs (92%) rename raphtory/src/db/{view_api => api/view}/internal/time_semantics.rs (98%) rename raphtory/src/db/{view_api => api/view}/internal/wrapped_graph.rs (74%) rename raphtory/src/db/{view_api => api/view}/layer.rs (100%) rename raphtory/src/db/{view_api => api/view}/mod.rs (94%) rename raphtory/src/db/{view_api => api/view}/time.rs (96%) rename raphtory/src/db/{view_api => api/view}/vertex.rs (98%) rename raphtory/src/db/{ => graph}/edge.rs (95%) rename raphtory/src/db/{ => graph}/graph.rs (97%) create mode 100644 raphtory/src/db/graph/mod.rs rename raphtory/src/db/{ => graph}/path.rs (95%) rename raphtory/src/db/{ => graph}/vertex.rs (95%) rename raphtory/src/db/{ => graph}/vertices.rs (92%) rename raphtory/src/db/{graph_deletions.rs => graph/views/deletion_graph.rs} (91%) rename raphtory/src/db/{graph_layer.rs => graph/views/layer_graph.rs} (92%) create mode 100644 raphtory/src/db/graph/views/mod.rs rename raphtory/src/db/{subgraph_vertex.rs => graph/views/vertex_subgraph.rs} (88%) rename raphtory/src/db/{graph_window.rs => graph/views/window_graph.rs} (96%) rename raphtory/src/db/task/{ => edge}/eval_edge.rs (92%) create mode 100644 raphtory/src/db/task/edge/mod.rs rename raphtory/src/db/task/{ => edge}/window_eval_edge.rs (94%) rename raphtory/src/db/task/{ => vertex}/eval_vertex.rs (95%) rename raphtory/src/db/task/{ => vertex}/eval_vertex_state.rs (99%) create mode 100644 raphtory/src/db/task/vertex/mod.rs rename raphtory/src/db/task/{ => vertex}/window_eval_vertex.rs (97%) rename raphtory/src/db/{ => utils}/doc_strings.rs (100%) create mode 100644 raphtory/src/db/utils/mod.rs delete mode 100644 raphtory/src/db/view_api/internal/into_dynamic.rs rename raphtory/src/python/{ => graph}/edge.rs (95%) rename raphtory/src/python/{ => graph}/graph.rs (94%) rename raphtory/src/python/{ => graph}/graph_with_deletions.rs (94%) create mode 100644 raphtory/src/python/graph/mod.rs rename raphtory/src/python/{ => graph}/vertex.rs (98%) rename raphtory/src/python/{ => graph/views}/graph_view.rs (94%) create mode 100644 raphtory/src/python/graph/views/mod.rs delete mode 100644 raphtory/src/python/macros/mod.rs rename raphtory/src/python/{ => packages}/algorithms.rs (88%) rename raphtory/src/python/{ => packages}/graph_gen.rs (91%) rename raphtory/src/python/{ => packages}/graph_loader.rs (96%) create mode 100644 raphtory/src/python/packages/mod.rs delete mode 100644 raphtory/src/python/perspective.rs rename raphtory/src/python/{ => types}/macros/iter.rs (100%) rename raphtory/src/python/{ => types}/macros/iterable.rs (98%) create mode 100644 raphtory/src/python/types/macros/mod.rs rename raphtory/src/python/{ => types}/macros/nested_iterable.rs (100%) rename raphtory/src/python/{ => types}/wrappers/iterators.rs (94%) rename raphtory/src/python/{ => types}/wrappers/mod.rs (100%) rename raphtory/src/python/{ => types}/wrappers/prop.rs (90%) rename raphtory/src/python/{ => utils}/errors.rs (75%) rename raphtory/src/python/{utils.rs => utils/mod.rs} (96%) diff --git a/.rustfmt.toml b/.rustfmt.toml new file mode 100644 index 0000000000..4c54ff0d8f --- /dev/null +++ b/.rustfmt.toml @@ -0,0 +1,2 @@ +#will enable when it is stable +imports_granularity = "Crate" \ No newline at end of file diff --git a/benchmark/benchmark_base.py b/comparison-benchmark/benchmark_base.py similarity index 100% rename from benchmark/benchmark_base.py rename to comparison-benchmark/benchmark_base.py diff --git a/benchmark/benchmark_driver.py b/comparison-benchmark/benchmark_driver.py similarity index 100% rename from benchmark/benchmark_driver.py rename to comparison-benchmark/benchmark_driver.py diff --git a/benchmark/benchmark_imports.py b/comparison-benchmark/benchmark_imports.py similarity index 100% rename from benchmark/benchmark_imports.py rename to comparison-benchmark/benchmark_imports.py diff --git a/benchmark/cozo_bench.py b/comparison-benchmark/cozo_bench.py similarity index 100% rename from benchmark/cozo_bench.py rename to comparison-benchmark/cozo_bench.py diff --git a/benchmark/graphtool_bench.py b/comparison-benchmark/graphtool_bench.py similarity index 100% rename from benchmark/graphtool_bench.py rename to comparison-benchmark/graphtool_bench.py diff --git a/benchmark/kuzu_bench.py b/comparison-benchmark/kuzu_bench.py similarity index 100% rename from benchmark/kuzu_bench.py rename to comparison-benchmark/kuzu_bench.py diff --git a/benchmark/memgraph_bench.py b/comparison-benchmark/memgraph_bench.py similarity index 100% rename from benchmark/memgraph_bench.py rename to comparison-benchmark/memgraph_bench.py diff --git a/benchmark/neo4j_bench.py b/comparison-benchmark/neo4j_bench.py similarity index 100% rename from benchmark/neo4j_bench.py rename to comparison-benchmark/neo4j_bench.py diff --git a/benchmark/networkx_bench.py b/comparison-benchmark/networkx_bench.py similarity index 100% rename from benchmark/networkx_bench.py rename to comparison-benchmark/networkx_bench.py diff --git a/benchmark/profile_bench.py b/comparison-benchmark/profile_bench.py similarity index 100% rename from benchmark/profile_bench.py rename to comparison-benchmark/profile_bench.py diff --git a/benchmark/raphtory_bench.py b/comparison-benchmark/raphtory_bench.py similarity index 100% rename from benchmark/raphtory_bench.py rename to comparison-benchmark/raphtory_bench.py diff --git a/benchmark/readme.md b/comparison-benchmark/readme.md similarity index 100% rename from benchmark/readme.md rename to comparison-benchmark/readme.md diff --git a/examples/custom-algorithm/src/main.rs b/examples/custom-algorithm/src/main.rs index 2d4590edf7..081cd72387 100644 --- a/examples/custom-algorithm/src/main.rs +++ b/examples/custom-algorithm/src/main.rs @@ -2,7 +2,7 @@ use async_graphql::dynamic::{FieldValue, ResolverContext, TypeRef}; use async_graphql::FieldResult; use dynamic_graphql::internal::TypeName; use dynamic_graphql::SimpleObject; -use raphtory::db::view_api::GraphViewOps; +use raphtory::db::view::GraphViewOps; use raphtory_graphql::{Algorithm, RaphtoryServer}; #[derive(SimpleObject)] diff --git a/examples/rust/src/bin/bench/main.rs b/examples/rust/src/bin/bench/main.rs index f8159e7c40..d35cdba1d9 100644 --- a/examples/rust/src/bin/bench/main.rs +++ b/examples/rust/src/bin/bench/main.rs @@ -1,11 +1,13 @@ -use raphtory::algorithms::pagerank::unweighted_page_rank; -use raphtory::db::graph::Graph; -use raphtory::db::mutation_api::AdditionOps; -use raphtory::db::view_api::*; -use raphtory::graph_loader::source::csv_loader::CsvLoader; +use raphtory::{ + algorithms::pagerank::unweighted_page_rank, graph_loader::source::csv_loader::CsvLoader, + prelude::*, +}; use serde::Deserialize; -use std::path::PathBuf; -use std::{env, path::Path, time::Instant}; +use std::{ + env, + path::{Path, PathBuf}, + time::Instant, +}; #[derive(Deserialize, std::fmt::Debug)] pub struct Benchr { diff --git a/examples/rust/src/bin/btc/main.rs b/examples/rust/src/bin/btc/main.rs index c6efd95128..9a6f684262 100644 --- a/examples/rust/src/bin/btc/main.rs +++ b/examples/rust/src/bin/btc/main.rs @@ -1,23 +1,21 @@ #![allow(unused_imports)] -use std::collections::HashMap; -use std::marker::PhantomData; -use std::path::{Path, PathBuf}; -use std::thread::JoinHandle; -use std::{env, thread}; +#![allow(dead_code)] use chrono::{DateTime, Utc}; -use raphtory::core::utils; -use raphtory::core::{Direction, Prop}; -use raphtory::graph_loader::source::csv_loader::CsvLoader; +use raphtory::{core::utils::hashing, graph_loader::source::csv_loader::CsvLoader, prelude::*}; use regex::Regex; use serde::Deserialize; -use std::fs::File; -use std::io::{prelude::*, BufReader, LineWriter}; -use std::time::Instant; - -use raphtory::db::graph::Graph; -use raphtory::db::mutation_api::AdditionOps; -use raphtory::db::view_api::*; +use std::{ + collections::HashMap, + env, + fs::File, + io::{prelude::*, BufReader, LineWriter}, + marker::PhantomData, + path::{Path, PathBuf}, + thread, + thread::JoinHandle, + time::Instant, +}; #[derive(Deserialize, std::fmt::Debug)] pub struct Sent { @@ -56,7 +54,7 @@ fn main() { panic!("Missing data dir = {}", data_dir.to_str().unwrap()) } - let test_v = utils::calculate_hash(&"139eeGkMGR6F9EuJQ3qYoXebfkBbNAsLtV:btc"); + let test_v = hashing::calculate_hash(&"139eeGkMGR6F9EuJQ3qYoXebfkBbNAsLtV:btc"); // If data_dir/graphdb.bincode exists, use bincode to load the graph from binary encoded data files // otherwise load the graph from csv data files @@ -84,8 +82,8 @@ fn main() { CsvLoader::new(data_dir) .with_filter(Regex::new(r".+(sent|received)").unwrap()) .load_into_graph(&g, |sent: Sent, g: &Graph| { - let src = utils::calculate_hash(&sent.addr); - let dst = utils::calculate_hash(&sent.txn); + let src = hashing::calculate_hash(&sent.addr); + let dst = hashing::calculate_hash(&sent.txn); let time = sent.time.timestamp(); if src == test_v || dst == test_v { diff --git a/examples/rust/src/bin/crypto/main.rs b/examples/rust/src/bin/crypto/main.rs index acf7d76fbe..9546e0c721 100644 --- a/examples/rust/src/bin/crypto/main.rs +++ b/examples/rust/src/bin/crypto/main.rs @@ -1,10 +1,12 @@ use itertools::Itertools; -use raphtory::algorithms::pagerank::unweighted_page_rank; -use raphtory::algorithms::temporal_reachability::temporally_reachable_nodes; -use raphtory::db::view_api::*; -use raphtory::graph_loader::example::stable_coins::stable_coin_graph; -use std::env; -use std::time::Instant; +use raphtory::{ + algorithms::{ + pagerank::unweighted_page_rank, temporal_reachability::temporally_reachable_nodes, + }, + db::api::view::*, + graph_loader::example::stable_coins::stable_coin_graph, +}; +use std::{env, time::Instant}; fn main() { let args: Vec = env::args().collect(); diff --git a/examples/rust/src/bin/hulongbay/main.rs b/examples/rust/src/bin/hulongbay/main.rs index 672d69b575..fecda9f4be 100644 --- a/examples/rust/src/bin/hulongbay/main.rs +++ b/examples/rust/src/bin/hulongbay/main.rs @@ -1,21 +1,22 @@ // #![allow(unused_imports)] -use std::env; -use std::error::Error; -use std::fmt::{Debug, Display, Formatter}; -use std::path::Path; - +#![allow(dead_code)] use itertools::Itertools; -use raphtory::algorithms::connected_components::weakly_connected_components; -use raphtory::algorithms::triangle_count::triangle_count; -use raphtory::core::Prop; -use raphtory::db::graph::Graph; -use raphtory::db::mutation_api::AdditionOps; -use raphtory::db::view_api::*; -use raphtory::db::view_api::{GraphViewOps, VertexViewOps}; -use raphtory::graph_loader::source::csv_loader::CsvLoader; +use raphtory::{ + algorithms::{ + connected_components::weakly_connected_components, triangle_count::triangle_count, + }, + graph_loader::source::csv_loader::CsvLoader, + prelude::*, +}; use regex::Regex; use serde::Deserialize; -use std::time::Instant; +use std::{ + env, + error::Error, + fmt::{Debug, Display, Formatter}, + path::Path, + time::Instant, +}; #[derive(Deserialize, Debug)] pub struct Edge { @@ -109,10 +110,6 @@ fn try_main() -> Result<(), Box> { let data_dir = Path::new(args.get(1).ok_or(MissingArgumentError)?); let graph = loader(data_dir)?; - - let min_time = graph.start().ok_or(GraphEmptyError)?; - let max_time = graph.end().ok_or(GraphEmptyError)?; - let mid_time = (min_time + max_time) / 2; let now = Instant::now(); let actual_tri_count = triangle_count(&graph, None); diff --git a/examples/rust/src/bin/lotr/main.rs b/examples/rust/src/bin/lotr/main.rs index cb2d98bb1f..5ff59cf029 100644 --- a/examples/rust/src/bin/lotr/main.rs +++ b/examples/rust/src/bin/lotr/main.rs @@ -1,14 +1,14 @@ use itertools::Itertools; -use raphtory::algorithms::temporal_reachability::temporally_reachable_nodes; -use raphtory::core::utils; -use raphtory::core::Prop; -use raphtory::db::graph::Graph; -use raphtory::db::mutation_api::AdditionOps; -use raphtory::db::view_api::*; -use raphtory::graph_loader::source::csv_loader::CsvLoader; +use raphtory::{ + algorithms::temporal_reachability::temporally_reachable_nodes, core::utils::hashing, + graph_loader::source::csv_loader::CsvLoader, prelude::*, +}; use serde::Deserialize; -use std::path::PathBuf; -use std::{env, path::Path, time::Instant}; +use std::{ + env, + path::{Path, PathBuf}, + time::Instant, +}; #[derive(Deserialize, std::fmt::Debug)] pub struct Lotr { @@ -101,7 +101,7 @@ fn main() { assert_eq!(graph.num_vertices(), 139); assert_eq!(graph.num_edges(), 701); - let gandalf = utils::calculate_hash(&"Gandalf"); + let gandalf = hashing::calculate_hash(&"Gandalf"); assert_eq!(gandalf, 2760374808085341115); assert!(graph.has_vertex(gandalf)); diff --git a/examples/rust/src/bin/pokec/main.rs b/examples/rust/src/bin/pokec/main.rs index b554965616..c6960b7636 100644 --- a/examples/rust/src/bin/pokec/main.rs +++ b/examples/rust/src/bin/pokec/main.rs @@ -1,13 +1,15 @@ -use std::{env, path::Path, time::Instant}; - -use raphtory::algorithms::connected_components::weakly_connected_components; -use raphtory::db::mutation_api::AdditionOps; -use raphtory::graph_loader::source::csv_loader::CsvLoader; use raphtory::{ - algorithms::pagerank::unweighted_page_rank, - db::{graph::Graph, view_api::GraphViewOps}, + algorithms::{ + connected_components::weakly_connected_components, pagerank::unweighted_page_rank, + }, + db::{ + api::{mutation::AdditionOps, view::GraphViewOps}, + graph::graph::Graph, + }, + graph_loader::source::csv_loader::CsvLoader, }; use serde::Deserialize; +use std::{env, path::Path, time::Instant}; #[derive(Deserialize, std::fmt::Debug)] struct Edge { diff --git a/js-raphtory/src/graph/edge.rs b/js-raphtory/src/graph/edge.rs index c1159ecc5c..4d3090e0a5 100644 --- a/js-raphtory/src/graph/edge.rs +++ b/js-raphtory/src/graph/edge.rs @@ -1,9 +1,7 @@ -use raphtory::db::edge::EdgeView; -use raphtory::db::view_api::*; -use wasm_bindgen::prelude::*; - use super::Graph; use crate::graph::{misc::JsProp, vertex::Vertex}; +use raphtory::db::{api::view::*, graph::edge::EdgeView}; +use wasm_bindgen::prelude::*; #[wasm_bindgen] pub struct Edge(pub(crate) EdgeView); diff --git a/js-raphtory/src/graph/graph_view_impl.rs b/js-raphtory/src/graph/graph_view_impl.rs index 038e7b082a..ca6e794334 100644 --- a/js-raphtory/src/graph/graph_view_impl.rs +++ b/js-raphtory/src/graph/graph_view_impl.rs @@ -1,6 +1,5 @@ -use raphtory::db::view_api::internal::{Base, BoxableGraphView, InheritViewOps}; - use super::{Graph, UnderGraph}; +use raphtory::db::api::view::internal::{Base, BoxableGraphView, InheritViewOps}; impl Base for Graph { type Base = dyn BoxableGraphView + Send + Sync + 'static; diff --git a/js-raphtory/src/graph/misc.rs b/js-raphtory/src/graph/misc.rs index 758feff889..9a73735a53 100644 --- a/js-raphtory/src/graph/misc.rs +++ b/js-raphtory/src/graph/misc.rs @@ -1,10 +1,8 @@ -use std::ops::Deref; -use std::sync::Arc; - use crate::graph::{Graph, UnderGraph}; use chrono::{Datelike, Timelike}; use js_sys::Array; -use raphtory::core::{errors::GraphError, Prop}; +use raphtory::core::{utils::errors::GraphError, Prop}; +use std::{ops::Deref, sync::Arc}; use wasm_bindgen::{prelude::wasm_bindgen, JsValue}; #[wasm_bindgen] diff --git a/js-raphtory/src/graph/mod.rs b/js-raphtory/src/graph/mod.rs index 5bda6181b1..b44bfd1aa3 100644 --- a/js-raphtory/src/graph/mod.rs +++ b/js-raphtory/src/graph/mod.rs @@ -1,28 +1,28 @@ +#![allow(dead_code)] #[cfg(feature = "console_error_panic_hook")] extern crate console_error_panic_hook; use core::panic; -use std::convert::TryFrom; -use std::sync::Arc; - use js_sys::Object; -use raphtory::core::errors::GraphError; -use raphtory::core::Prop; -use raphtory::db::graph::Graph as TGraph; -use raphtory::db::graph_window::WindowedGraph; -use raphtory::db::mutation_api::AdditionOps; -use raphtory::db::view_api::internal::BoxableGraphView; -use raphtory::db::view_api::GraphViewOps; -use raphtory::db::view_api::TimeOps; -use wasm_bindgen::prelude::*; -use wasm_bindgen::JsCast; - -use crate::graph::misc::JSError; -use crate::graph::misc::JsObjectEntry; -use crate::graph::vertex::JsVertex; -use crate::graph::vertex::Vertex; -use crate::log; -use crate::utils::set_panic_hook; +use raphtory::{ + core::utils::errors::GraphError, + db::{ + api::view::{internal::BoxableGraphView, GraphViewOps, TimeOps}, + graph::{graph::Graph as TGraph, views::window_graph::WindowedGraph}, + }, + prelude::*, +}; +use std::{convert::TryFrom, sync::Arc}; +use wasm_bindgen::{prelude::*, JsCast}; + +use crate::{ + graph::{ + misc::{JSError, JsObjectEntry}, + vertex::{JsVertex, Vertex}, + }, + log, + utils::set_panic_hook, +}; mod edge; mod graph_view_impl; diff --git a/js-raphtory/src/graph/vertex.rs b/js-raphtory/src/graph/vertex.rs index 876778e524..bf1a1e3b3b 100644 --- a/js-raphtory/src/graph/vertex.rs +++ b/js-raphtory/src/graph/vertex.rs @@ -1,15 +1,12 @@ -use std::convert::TryFrom; - +use super::{misc::JSError, Graph}; +use crate::graph::{edge::Edge, misc::JsProp}; use raphtory::{ - core::errors::GraphError, - db::{vertex::VertexView, view_api::VertexViewOps}, + core::utils::errors::GraphError, + db::{api::view::VertexViewOps, graph::vertex::VertexView}, }; +use std::convert::TryFrom; use wasm_bindgen::prelude::*; -use crate::graph::{edge::Edge, misc::JsProp}; - -use super::{misc::JSError, Graph}; - #[wasm_bindgen] pub struct Vertex(pub(crate) VertexView); diff --git a/python/src/lib.rs b/python/src/lib.rs index 0d9f95e4c8..ed29a59173 100644 --- a/python/src/lib.rs +++ b/python/src/lib.rs @@ -1,12 +1,14 @@ extern crate core; use pyo3::prelude::*; -use raphtory_core::python::algorithms::*; -use raphtory_core::python::edge::{PyEdge, PyEdges}; -use raphtory_core::python::graph::PyGraph; -use raphtory_core::python::graph_gen::*; -use raphtory_core::python::graph_loader::*; -use raphtory_core::python::graph_with_deletions::PyGraphWithDeletions; -use raphtory_core::python::vertex::{PyVertex, PyVertices}; +use raphtory_core::python::{ + graph::{ + edge::{PyEdge, PyEdges}, + graph::PyGraph, + graph_with_deletions::PyGraphWithDeletions, + vertex::{PyVertex, PyVertices}, + }, + packages::{algorithms::*, graph_gen::*, graph_loader::*}, +}; /// Raphtory graph analytics library #[pymodule] diff --git a/raphtory-benchmark/benches/algobench.rs b/raphtory-benchmark/benches/algobench.rs index 802153a83e..5e97a260ad 100644 --- a/raphtory-benchmark/benches/algobench.rs +++ b/raphtory-benchmark/benches/algobench.rs @@ -1,8 +1,12 @@ use crate::common::bench; use criterion::{criterion_group, criterion_main, Criterion}; -use raphtory::algorithms::local_clustering_coefficient::local_clustering_coefficient; -use raphtory::algorithms::local_triangle_count::local_triangle_count; -use raphtory::prelude::*; +use raphtory::{ + algorithms::{ + local_clustering_coefficient::local_clustering_coefficient, + local_triangle_count::local_triangle_count, + }, + prelude::*, +}; use rayon::prelude::*; mod common; diff --git a/raphtory-benchmark/benches/base.rs b/raphtory-benchmark/benches/base.rs index 8a984dc0e3..6db4e389d6 100644 --- a/raphtory-benchmark/benches/base.rs +++ b/raphtory-benchmark/benches/base.rs @@ -18,7 +18,7 @@ pub fn base(c: &mut Criterion) { large_group.throughput(Throughput::Elements(1_000)); large_group.measurement_time(std::time::Duration::from_secs(3)); // Make an option of None - run_large_ingestion_benchmarks(&mut large_group, || bootstrap_graph(4, 10000), None); + run_large_ingestion_benchmarks(&mut large_group, || bootstrap_graph(10000), None); large_group.finish(); } diff --git a/raphtory-benchmark/benches/common/mod.rs b/raphtory-benchmark/benches/common/mod.rs index bc7d5caf0e..f1f49b03d1 100644 --- a/raphtory-benchmark/benches/common/mod.rs +++ b/raphtory-benchmark/benches/common/mod.rs @@ -1,9 +1,8 @@ +#![allow(dead_code)] + use criterion::{measurement::WallTime, BatchSize, Bencher, BenchmarkGroup, BenchmarkId}; -use rand::seq::*; -use rand::{distributions::Uniform, Rng}; -use raphtory::db::graph::Graph; -use raphtory::db::mutation_api::AdditionOps; -use raphtory::db::view_api::*; +use rand::{distributions::Uniform, seq::*, Rng}; +use raphtory::prelude::*; use std::collections::HashSet; fn make_index_gen() -> Box> { @@ -18,7 +17,7 @@ fn make_time_gen() -> Box> { Box::new(rng.sample_iter(range)) } -pub fn bootstrap_graph(num_shards: usize, num_vertices: usize) -> Graph { +pub fn bootstrap_graph(num_vertices: usize) -> Graph { let graph = Graph::new(); let mut indexes = make_index_gen(); let mut times = make_time_gen(); @@ -123,9 +122,6 @@ pub fn run_large_ingestion_benchmarks( ) where F: FnMut() -> Graph, { - let mut times_gen = make_time_gen(); - let mut time_sample = || times_gen.next().unwrap(); - let updates = 1000; bench( diff --git a/raphtory-benchmark/benches/edge_add.rs b/raphtory-benchmark/benches/edge_add.rs index c6c42a35e6..ff8c8019a6 100644 --- a/raphtory-benchmark/benches/edge_add.rs +++ b/raphtory-benchmark/benches/edge_add.rs @@ -1,11 +1,11 @@ use criterion::{criterion_group, criterion_main, Criterion}; -use raphtory::core::vertex::InputVertex; -use raphtory::db::graph::Graph; +use raphtory::prelude::*; mod common; -use rand::distributions::{Alphanumeric, DistString}; -use rand::{thread_rng, Rng}; -use raphtory::db::mutation_api::AdditionOps; +use rand::{ + distributions::{Alphanumeric, DistString}, + thread_rng, Rng, +}; fn random_string(n: usize) -> String { Alphanumeric.sample_string(&mut rand::thread_rng(), n) @@ -31,7 +31,7 @@ pub fn graph(c: &mut Criterion) { id_group.finish(); let mut graph_group = c.benchmark_group("edge_add"); - let mut g = Graph::new(); + let g = Graph::new(); graph_group.bench_function("string input", |bencher| { let src: String = random_string(16); let dst: String = random_string(16); diff --git a/raphtory-benchmark/benches/graph_ops.rs b/raphtory-benchmark/benches/graph_ops.rs index 3c7b3a38be..962d009b42 100644 --- a/raphtory-benchmark/benches/graph_ops.rs +++ b/raphtory-benchmark/benches/graph_ops.rs @@ -1,7 +1,6 @@ use common::run_analysis_benchmarks; use criterion::{criterion_group, criterion_main, Criterion}; -use raphtory::db::view_api::*; -use raphtory::graph_loader::example::sx_superuser_graph::sx_superuser_graph; +use raphtory::{db::api::view::*, graph_loader::example::sx_superuser_graph::sx_superuser_graph}; mod common; diff --git a/raphtory-benchmark/benches/parameterized.rs b/raphtory-benchmark/benches/parameterized.rs index d23057f8db..843a04fe8f 100644 --- a/raphtory-benchmark/benches/parameterized.rs +++ b/raphtory-benchmark/benches/parameterized.rs @@ -12,7 +12,7 @@ pub fn parameterized(c: &mut Criterion) { let mut ingestion_group = c.benchmark_group("ingestion-num_vertices"); ingestion_group.plot_config(PlotConfiguration::default().summary_scale(AxisScale::Logarithmic)); for num_vertices in vertices { - let make_graph = || bootstrap_graph(4, num_vertices); + let make_graph = || bootstrap_graph(num_vertices); ingestion_group.throughput(Throughput::Elements(num_vertices as u64)); ingestion_group.sample_size(10); ingestion_group.warm_up_time(std::time::Duration::from_secs(1)); diff --git a/raphtory-benchmark/benches/tgraph_benchmarks.rs b/raphtory-benchmark/benches/tgraph_benchmarks.rs index 3fd0f7a800..93f0f54897 100644 --- a/raphtory-benchmark/benches/tgraph_benchmarks.rs +++ b/raphtory-benchmark/benches/tgraph_benchmarks.rs @@ -1,9 +1,8 @@ -use std::collections::BTreeSet; - use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion, Throughput}; use rand::{distributions::Uniform, Rng}; -use raphtory::core::tgraph::adjset::AdjSet; +use raphtory::core::entities::vertices::structure::adjset::AdjSet; use sorted_vector_map::SortedVectorSet; +use std::collections::BTreeSet; fn btree_set_u64(c: &mut Criterion) { let mut group = c.benchmark_group("btree_set_u64_range_insert"); diff --git a/raphtory-graphql/src/data.rs b/raphtory-graphql/src/data.rs index ffdb6b4074..bd9c34e7d2 100644 --- a/raphtory-graphql/src/data.rs +++ b/raphtory-graphql/src/data.rs @@ -1,8 +1,8 @@ -use raphtory::db::graph::Graph; -// use raphtory::db::view_api::internal::CoreGraphOps; -use raphtory::prelude::GraphViewOps; -use std::collections::{HashMap, HashSet}; -use std::path::Path; +use raphtory::prelude::{Graph, GraphViewOps}; +use std::{ + collections::{HashMap, HashSet}, + path::Path, +}; use walkdir::WalkDir; pub(crate) struct Data { diff --git a/raphtory-graphql/src/lib.rs b/raphtory-graphql/src/lib.rs index 8739ce59eb..7a2222eb32 100644 --- a/raphtory-graphql/src/lib.rs +++ b/raphtory-graphql/src/lib.rs @@ -1,5 +1,4 @@ -pub use crate::model::algorithm::Algorithm; -pub use crate::server::RaphtoryServer; +pub use crate::{model::algorithm::Algorithm, server::RaphtoryServer}; mod model; mod observability; @@ -11,13 +10,9 @@ mod data; #[cfg(test)] mod graphql_test { use super::*; - use dynamic_graphql::dynamic::DynamicRequestExt; - use dynamic_graphql::{App, FieldValue}; - use raphtory::core::Prop; - use raphtory::db::graph::Graph; - use raphtory::db::mutation_api::AdditionOps; + use dynamic_graphql::{dynamic::DynamicRequestExt, App, FieldValue}; + use raphtory::prelude::*; use std::collections::HashMap; - use std::env; #[tokio::test] async fn basic_query() { diff --git a/raphtory-graphql/src/model/algorithm.rs b/raphtory-graphql/src/model/algorithm.rs index a1fb8fba45..966b9e0389 100644 --- a/raphtory-graphql/src/model/algorithm.rs +++ b/raphtory-graphql/src/model/algorithm.rs @@ -1,16 +1,17 @@ -use async_graphql::dynamic::{ - Field, FieldFuture, FieldValue, InputValue, Object, ResolverContext, TypeRef, +use async_graphql::{ + dynamic::{Field, FieldFuture, FieldValue, InputValue, Object, ResolverContext, TypeRef}, + Context, FieldResult, +}; +use dynamic_graphql::{ + internal::{OutputTypeName, Register, Registry, ResolveOwned, TypeName}, + SimpleObject, }; -use async_graphql::{Context, FieldResult}; -use dynamic_graphql::internal::{OutputTypeName, Register, Registry, ResolveOwned, TypeName}; -use dynamic_graphql::SimpleObject; use once_cell::sync::Lazy; -use raphtory::algorithms::pagerank::unweighted_page_rank; -use raphtory::db::view_api::internal::DynamicGraph; -use raphtory::db::view_api::GraphViewOps; -use std::borrow::Cow; -use std::collections::HashMap; -use std::sync::Mutex; +use raphtory::{ + algorithms::pagerank::unweighted_page_rank, + db::api::view::{internal::DynamicGraph, GraphViewOps}, +}; +use std::{borrow::Cow, collections::HashMap, sync::Mutex}; type RegisterFunction = fn(&str, Registry, Object) -> (Registry, Object); diff --git a/raphtory-graphql/src/model/filters/edgefilter.rs b/raphtory-graphql/src/model/filters/edgefilter.rs index 5564b6c940..e06cad891c 100644 --- a/raphtory-graphql/src/model/filters/edgefilter.rs +++ b/raphtory-graphql/src/model/filters/edgefilter.rs @@ -1,8 +1,9 @@ -use crate::model::filters::primitives::{StringFilter, StringVecFilter}; -use crate::model::graph::edge::Edge; -use crate::model::graph::node::Node; +use crate::model::{ + filters::primitives::{StringFilter, StringVecFilter}, + graph::edge::Edge, +}; use dynamic_graphql::InputObject; -use raphtory::db::view_api::{EdgeViewOps, VertexViewOps}; +use raphtory::db::api::view::{EdgeViewOps, VertexViewOps}; #[derive(InputObject)] pub struct EdgeFilter { diff --git a/raphtory-graphql/src/model/filters/mod.rs b/raphtory-graphql/src/model/filters/mod.rs index e8a3fb1f8e..26cb55e0be 100644 --- a/raphtory-graphql/src/model/filters/mod.rs +++ b/raphtory-graphql/src/model/filters/mod.rs @@ -1,4 +1,4 @@ +pub(crate) mod edgefilter; pub(crate) mod nodefilter; pub(crate) mod primitives; pub(crate) mod property; -pub(crate) mod edgefilter; diff --git a/raphtory-graphql/src/model/filters/nodefilter.rs b/raphtory-graphql/src/model/filters/nodefilter.rs index c6ea75125b..9421e4f92e 100644 --- a/raphtory-graphql/src/model/filters/nodefilter.rs +++ b/raphtory-graphql/src/model/filters/nodefilter.rs @@ -1,12 +1,12 @@ -use crate::model::filters::primitives::{NumberFilter, StringFilter, StringVecFilter}; -use crate::model::filters::property::PropertyHasFilter; -use crate::model::graph::node::Node; -use dynamic_graphql::internal::{FromValue, InputTypeName, InputValueResult, Register, TypeName}; +use crate::model::{ + filters::{ + primitives::{NumberFilter, StringFilter, StringVecFilter}, + property::PropertyHasFilter, + }, + graph::node::Node, +}; use dynamic_graphql::InputObject; -use raphtory::core::Prop; -use raphtory::db::vertex::VertexView; -use raphtory::db::view_api::VertexViewOps; -use std::borrow::Cow; +use raphtory::{core::Prop, db::api::view::VertexViewOps}; #[derive(InputObject)] pub struct NodeFilter { diff --git a/raphtory-graphql/src/model/filters/property.rs b/raphtory-graphql/src/model/filters/property.rs index 734a6cb9e5..cdfdec1fcb 100644 --- a/raphtory-graphql/src/model/filters/property.rs +++ b/raphtory-graphql/src/model/filters/property.rs @@ -1,8 +1,6 @@ -use crate::model::filters::primitives::{NumberFilter, StringFilter}; -use crate::model::graph::node::Node; +use crate::model::{filters::primitives::NumberFilter, graph::node::Node}; use dynamic_graphql::InputObject; -use raphtory::core::Prop; -use raphtory::db::view_api::VertexViewOps; +use raphtory::{core::Prop, db::api::view::VertexViewOps}; #[derive(InputObject)] pub(crate) struct PropertyHasFilter { diff --git a/raphtory-graphql/src/model/graph/edge.rs b/raphtory-graphql/src/model/graph/edge.rs index a413c95ae8..26c939bcfe 100644 --- a/raphtory-graphql/src/model/graph/edge.rs +++ b/raphtory-graphql/src/model/graph/edge.rs @@ -1,10 +1,12 @@ -use crate::model::graph::node::Node; -use crate::model::graph::property::Property; +use crate::model::graph::{node::Node, property::Property}; use dynamic_graphql::{ResolvedObject, ResolvedObjectFields}; -use raphtory::db::edge::EdgeView; -use raphtory::db::view_api::internal::{DynamicGraph, IntoDynamic}; -use raphtory::db::view_api::EdgeViewOps; -use raphtory::db::view_api::GraphViewOps; +use raphtory::db::{ + api::view::{ + internal::{DynamicGraph, IntoDynamic}, + EdgeViewOps, GraphViewOps, + }, + graph::edge::EdgeView, +}; #[derive(ResolvedObject)] pub(crate) struct Edge { diff --git a/raphtory-graphql/src/model/graph/graph.rs b/raphtory-graphql/src/model/graph/graph.rs index 605118682a..8767409656 100644 --- a/raphtory-graphql/src/model/graph/graph.rs +++ b/raphtory-graphql/src/model/graph/graph.rs @@ -1,13 +1,14 @@ -use crate::model::algorithm::Algorithms; -use crate::model::filters::edgefilter::EdgeFilter; -use crate::model::filters::nodefilter::NodeFilter; -use crate::model::graph::edge::Edge; -use crate::model::graph::node::Node; -use crate::model::graph::property::Property; +use crate::model::{ + algorithm::Algorithms, + filters::{edgefilter::EdgeFilter, nodefilter::NodeFilter}, + graph::{edge::Edge, node::Node, property::Property}, +}; use dynamic_graphql::{ResolvedObject, ResolvedObjectFields}; use itertools::Itertools; -use raphtory::db::view_api::internal::{DynamicGraph, IntoDynamic}; -use raphtory::db::view_api::{EdgeViewOps, GraphViewOps, TimeOps, VertexViewOps}; +use raphtory::db::api::view::{ + internal::{DynamicGraph, IntoDynamic}, + GraphViewOps, TimeOps, VertexViewOps, +}; #[derive(ResolvedObject)] pub(crate) struct GraphMeta { diff --git a/raphtory-graphql/src/model/graph/node.rs b/raphtory-graphql/src/model/graph/node.rs index dfafce8aa3..5747d9b971 100644 --- a/raphtory-graphql/src/model/graph/node.rs +++ b/raphtory-graphql/src/model/graph/node.rs @@ -1,14 +1,20 @@ -use crate::model::filters::edgefilter::EdgeFilter; -use crate::model::graph::edge::Edge; -use crate::model::graph::property::Property; -use crate::model::graph::property_update::PropertyUpdate; +use crate::model::{ + filters::edgefilter::EdgeFilter, + graph::{edge::Edge, property::Property, property_update::PropertyUpdate}, +}; use async_graphql::Context; use dynamic_graphql::{ResolvedObject, ResolvedObjectFields}; use itertools::Itertools; -use raphtory::core::Prop; -use raphtory::db::vertex::VertexView; -use raphtory::db::view_api::internal::{DynamicGraph, IntoDynamic}; -use raphtory::db::view_api::*; +use raphtory::{ + core::Prop, + db::{ + api::view::{ + internal::{DynamicGraph, IntoDynamic}, + *, + }, + graph::vertex::VertexView, + }, +}; #[derive(ResolvedObject)] pub(crate) struct Node { @@ -184,7 +190,7 @@ impl Node { } } - async fn exploded_edges(&self, layer: Option) -> Vec { + async fn exploded_edges(&self) -> Vec { self.vv.out_edges().explode().map(|ee| ee.into()).collect() } diff --git a/raphtory-graphql/src/model/mod.rs b/raphtory-graphql/src/model/mod.rs index 679434dbd8..3100b4f159 100644 --- a/raphtory-graphql/src/model/mod.rs +++ b/raphtory-graphql/src/model/mod.rs @@ -1,10 +1,11 @@ -use crate::data::Data; -use crate::model::graph::graph::{GqlGraph, GraphMeta}; +use crate::{ + data::Data, + model::graph::graph::{GqlGraph, GraphMeta}, +}; use async_graphql::Context; use dynamic_graphql::{ResolvedObject, ResolvedObjectFields}; use itertools::Itertools; -use raphtory::db::view_api::internal::IntoDynamic; -use raphtory::db::view_api::GraphViewOps; +use raphtory::db::api::view::internal::IntoDynamic; pub(crate) mod algorithm; pub(crate) mod filters; @@ -21,11 +22,7 @@ impl QueryRoot { } /// Returns a view including all events between `t_start` (inclusive) and `t_end` (exclusive) - async fn graph<'a>( - ctx: &Context<'a>, - name: &str, - node_ids: &Option>, - ) -> Option { + async fn graph<'a>(ctx: &Context<'a>, name: &str) -> Option { let data = ctx.data_unchecked::(); let g = data.graphs.get(name)?; Some(g.clone().into()) diff --git a/raphtory-graphql/src/observability/tracing.rs b/raphtory-graphql/src/observability/tracing.rs index 7b4f1fb8c7..2e3986ede5 100644 --- a/raphtory-graphql/src/observability/tracing.rs +++ b/raphtory-graphql/src/observability/tracing.rs @@ -1,6 +1,10 @@ -use opentelemetry::sdk::trace::{self, Sampler}; use opentelemetry::{ - global, runtime::Tokio, sdk::propagation::TraceContextPropagator, sdk::trace::Tracer, + global, + runtime::Tokio, + sdk::{ + propagation::TraceContextPropagator, + trace::{self, Sampler, Tracer}, + }, }; use std::env; diff --git a/raphtory-graphql/src/routes.rs b/raphtory-graphql/src/routes.rs index 5d426bb8a7..22865da9c4 100644 --- a/raphtory-graphql/src/routes.rs +++ b/raphtory-graphql/src/routes.rs @@ -1,7 +1,10 @@ use async_graphql::http::{playground_source, GraphQLPlaygroundConfig}; -use poem::http::StatusCode; -use poem::web::{Html, Json}; -use poem::{handler, IntoResponse}; +use poem::{ + handler, + http::StatusCode, + web::{Html, Json}, + IntoResponse, +}; use serde::Serialize; #[derive(Serialize)] diff --git a/raphtory-graphql/src/server.rs b/raphtory-graphql/src/server.rs index 12c2fabee0..bbb99272fa 100644 --- a/raphtory-graphql/src/server.rs +++ b/raphtory-graphql/src/server.rs @@ -1,18 +1,15 @@ -use crate::data::Data; -use crate::model::algorithm::Algorithm; -use crate::model::QueryRoot; -use crate::observability::tracing::create_tracer_from_env; -use crate::routes::{graphql_playground, health}; +#![allow(dead_code)] +use crate::{ + data::Data, + model::{algorithm::Algorithm, QueryRoot}, + observability::tracing::create_tracer_from_env, + routes::{graphql_playground, health}, +}; use async_graphql_poem::GraphQL; use dynamic_graphql::App; -use poem::listener::TcpListener; -use poem::middleware::Cors; -use poem::{get, EndpointExt, Route, Server}; -use tokio::io::Result as IoResult; -use tokio::signal; -use tracing_subscriber::layer::SubscriberExt; -use tracing_subscriber::util::SubscriberInitExt; -use tracing_subscriber::Registry; +use poem::{get, listener::TcpListener, middleware::Cors, EndpointExt, Route, Server}; +use tokio::{io::Result as IoResult, signal}; +use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt, Registry}; pub struct RaphtoryServer { data: Data, diff --git a/raphtory/Cargo.toml b/raphtory/Cargo.toml index 957110bd43..7831c248dd 100644 --- a/raphtory/Cargo.toml +++ b/raphtory/Cargo.toml @@ -12,7 +12,6 @@ license.workspace = true readme.workspace = true homepage.workspace = true - # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] @@ -74,3 +73,4 @@ quickcheck_macros = "1" io = ["dep:zip","dep:neo4rs", "dep:bzip2", "dep:flate2", "dep:csv", "dep:serde_json", "dep:reqwest", "dep:tokio"] # Enables generating the pyo3 python bindings python = ["io", "dep:pyo3", "dep:num", "dep:display-error-chain"] + diff --git a/raphtory/src/algorithms/clustering_coefficient.rs b/raphtory/src/algorithms/clustering_coefficient.rs index d6a7b5789c..9de9386d9a 100644 --- a/raphtory/src/algorithms/clustering_coefficient.rs +++ b/raphtory/src/algorithms/clustering_coefficient.rs @@ -1,6 +1,7 @@ -use crate::algorithms::triangle_count::triangle_count; -use crate::algorithms::triplet_count::triplet_count; -use crate::db::view_api::GraphViewOps; +use crate::{ + algorithms::{triangle_count::triangle_count, triplet_count::triplet_count}, + db::api::view::GraphViewOps, +}; /// Computes the global clustering coefficient of a graph. The global clustering coefficient is /// defined as the number of triangles in the graph divided by the number of triplets in the graph. @@ -48,9 +49,10 @@ pub fn clustering_coefficient(g: &G) -> f64 { #[cfg(test)] mod cc_test { use super::*; - use crate::db::graph::Graph; - use crate::db::mutation_api::AdditionOps; - use crate::db::view_api::*; + use crate::db::{ + api::{mutation::AdditionOps, view::*}, + graph::graph::Graph, + }; use pretty_assertions::assert_eq; /// Test the global clustering coefficient diff --git a/raphtory/src/algorithms/connected_components.rs b/raphtory/src/algorithms/connected_components.rs index f49ee5c0a9..49b1e076ce 100644 --- a/raphtory/src/algorithms/connected_components.rs +++ b/raphtory/src/algorithms/connected_components.rs @@ -1,18 +1,16 @@ -use crate::db::task::eval_vertex::EvalVertexView; -use crate::db::view_api::VertexViewOps; use crate::{ core::state::compute_state::ComputeStateVec, db::{ + api::view::{GraphViewOps, VertexViewOps}, task::{ context::Context, task::{ATask, Job, Step}, task_runner::TaskRunner, + vertex::eval_vertex::EvalVertexView, }, - view_api::GraphViewOps, }, }; -use std::cmp; -use std::collections::HashMap; +use std::{cmp, collections::HashMap}; #[derive(Clone, Debug)] struct WccState { @@ -100,10 +98,10 @@ where #[cfg(test)] mod cc_test { - use crate::{db::graph::Graph, prelude::TimeOps}; + use crate::prelude::*; use super::*; - use crate::db::mutation_api::AdditionOps; + use crate::db::api::mutation::AdditionOps; use itertools::*; use std::{cmp::Reverse, iter::once}; diff --git a/raphtory/src/algorithms/degree.rs b/raphtory/src/algorithms/degree.rs index a2dbf20c6f..09eba2bcc4 100644 --- a/raphtory/src/algorithms/degree.rs +++ b/raphtory/src/algorithms/degree.rs @@ -41,7 +41,7 @@ //! print!("Average degree: {:?}", average_degree(&windowed_graph)); //! ``` //! -use crate::db::view_api::*; +use crate::db::api::view::*; /// The maximum out degree of any vertex in the graph. pub fn max_out_degree(graph: &G) -> usize { @@ -101,10 +101,9 @@ pub fn average_degree(graph: &G) -> f64 { #[cfg(test)] mod degree_test { - use crate::db::mutation_api::AdditionOps; use crate::{ algorithms::degree::{average_degree, max_in_degree, min_in_degree, min_out_degree}, - db::graph::Graph, + db::{api::mutation::AdditionOps, graph::graph::Graph}, }; use super::max_out_degree; diff --git a/raphtory/src/algorithms/directed_graph_density.rs b/raphtory/src/algorithms/directed_graph_density.rs index ecde9c9e75..0dc25555c3 100644 --- a/raphtory/src/algorithms/directed_graph_density.rs +++ b/raphtory/src/algorithms/directed_graph_density.rs @@ -31,7 +31,7 @@ //! println!("graph density: {:?}", directed_graph_density(&windowed_graph)); //! ``` //! -use crate::db::view_api::*; +use crate::db::api::view::*; /// Measures how dense or sparse a graph is pub fn directed_graph_density(graph: &G) -> f32 { @@ -41,8 +41,7 @@ pub fn directed_graph_density(graph: &G) -> f32 { #[cfg(test)] mod directed_graph_density_tests { use super::*; - use crate::db::graph::Graph; - use crate::db::mutation_api::AdditionOps; + use crate::db::{api::mutation::AdditionOps, graph::graph::Graph}; #[test] fn low_graph_density() { diff --git a/raphtory/src/algorithms/hits.rs b/raphtory/src/algorithms/hits.rs index b7311dab28..b8935796e0 100644 --- a/raphtory/src/algorithms/hits.rs +++ b/raphtory/src/algorithms/hits.rs @@ -1,20 +1,21 @@ -use crate::core::state::accumulator_id::accumulators::{max, sum}; -use crate::db::task::eval_vertex::EvalVertexView; use crate::{ - core::state::compute_state::ComputeStateVec, + core::state::{ + accumulator_id::accumulators::{max, sum}, + compute_state::ComputeStateVec, + }, db::{ + api::view::{GraphViewOps, VertexViewOps}, task::{ context::Context, task::{ATask, Job, Step}, task_runner::TaskRunner, + vertex::eval_vertex::EvalVertexView, }, - view_api::{GraphViewOps, VertexViewOps}, }, }; use num_traits::abs; use rustc_hash::FxHashMap; -use std::collections::HashMap; -use std::ops::Range; +use std::{collections::HashMap, ops::Range}; #[derive(Debug, Clone)] struct Hits { @@ -159,8 +160,7 @@ pub fn hits( #[cfg(test)] mod hits_tests { use super::*; - use crate::db::graph::Graph; - use crate::db::mutation_api::AdditionOps; + use crate::db::{api::mutation::AdditionOps, graph::graph::Graph}; use itertools::Itertools; fn load_graph(edges: Vec<(u64, u64)>) -> Graph { diff --git a/raphtory/src/algorithms/local_clustering_coefficient.rs b/raphtory/src/algorithms/local_clustering_coefficient.rs index 2a57926c28..39eded798a 100644 --- a/raphtory/src/algorithms/local_clustering_coefficient.rs +++ b/raphtory/src/algorithms/local_clustering_coefficient.rs @@ -24,9 +24,7 @@ //! //! ```rust //! use raphtory::algorithms::local_clustering_coefficient::{local_clustering_coefficient}; -//! use raphtory::db::graph::Graph; -//! use raphtory::db::mutation_api::AdditionOps; -//! use raphtory::db::view_api::*; +//! use raphtory::prelude::*; //! //! let g = Graph::new(); //! let windowed_graph = g.window(0, 7); @@ -50,9 +48,10 @@ //! println!("local clustering coefficient of all nodes: {:?}", actual); //! ``` -use crate::algorithms::local_triangle_count::local_triangle_count; -use crate::core::vertex_ref::VertexRef; -use crate::db::view_api::*; +use crate::{ + algorithms::local_triangle_count::local_triangle_count, + core::entities::vertices::vertex_ref::VertexRef, db::api::view::*, +}; /// measures the degree to which nodes in a graph tend to cluster together pub fn local_clustering_coefficient>( @@ -80,9 +79,10 @@ pub fn local_clustering_coefficient>( #[cfg(test)] mod clustering_coefficient_tests { use super::local_clustering_coefficient; - use crate::db::graph::Graph; - use crate::db::mutation_api::AdditionOps; - use crate::db::view_api::*; + use crate::db::{ + api::{mutation::AdditionOps, view::*}, + graph::graph::Graph, + }; #[test] fn clusters_of_triangles() { diff --git a/raphtory/src/algorithms/local_triangle_count.rs b/raphtory/src/algorithms/local_triangle_count.rs index 206aea93a2..27d70318b3 100644 --- a/raphtory/src/algorithms/local_triangle_count.rs +++ b/raphtory/src/algorithms/local_triangle_count.rs @@ -18,9 +18,7 @@ //! //! ```rust //! use raphtory::algorithms::local_triangle_count::{local_triangle_count}; -//! use raphtory::db::graph::Graph; -//! use raphtory::db::mutation_api::AdditionOps; -//! use raphtory::db::view_api::*; +//! use raphtory::prelude::*; //! //! let g = Graph::new(); //! let vs = vec![(1, 1, 2), (2, 1, 3), (3, 2, 1), (4, 3, 2)]; @@ -39,8 +37,7 @@ //! println!("local_triangle_count: {:?}", result); //! ``` //! -use crate::core::vertex_ref::VertexRef; -use crate::db::view_api::*; +use crate::{core::entities::vertices::vertex_ref::VertexRef, db::api::view::*}; use itertools::Itertools; /// calculates the number of triangles (a cycle of length 3) for a node. @@ -73,9 +70,10 @@ pub fn local_triangle_count>(graph: &G, v: V mod triangle_count_tests { use super::local_triangle_count; - use crate::db::graph::Graph; - use crate::db::mutation_api::AdditionOps; - use crate::db::view_api::*; + use crate::db::{ + api::{mutation::AdditionOps, view::*}, + graph::graph::Graph, + }; #[test] fn counts_triangles() { diff --git a/raphtory/src/algorithms/motifs/three_node_eval_wip.rs b/raphtory/src/algorithms/motifs/three_node_eval_wip.rs index 65a76fbe80..7813ce4a92 100644 --- a/raphtory/src/algorithms/motifs/three_node_eval_wip.rs +++ b/raphtory/src/algorithms/motifs/three_node_eval_wip.rs @@ -1,20 +1,22 @@ -use std::collections::HashMap; -use std::slice::Iter; - -use crate::core::state::accumulator_id::AccId; -use crate::core::state::agg::ValDef; -use crate::db::view_api::*; - -use crate::algorithms::motifs::three_node_motifs::*; -use crate::core::state::accumulator_id::accumulators::val; -use crate::core::state::compute_state::ComputeStateVec; -use crate::db::task::context::Context; -use crate::db::task::eval_vertex::EvalVertexView; -use crate::db::task::task::{ATask, Job, Step}; -use crate::db::task::task_runner::TaskRunner; -use crate::db::view_api::{GraphViewOps, VertexViewOps}; +use crate::{ + algorithms::motifs::three_node_motifs::*, + core::state::{ + accumulator_id::{accumulators::val, AccId}, + agg::ValDef, + compute_state::ComputeStateVec, + }, + db::{ + api::view::{GraphViewOps, VertexViewOps, *}, + task::{ + context::Context, + task::{ATask, Job, Step}, + task_runner::TaskRunner, + vertex::eval_vertex::EvalVertexView, + }, + }, +}; use num_traits::Zero; -use std::ops::Add; +use std::{collections::HashMap, ops::Add, slice::Iter}; pub fn star_motif_count( evv: &EvalVertexView, @@ -384,8 +386,7 @@ pub fn temporal_three_node_motif( #[cfg(test)] mod motifs_test { use super::*; - use crate::db::graph::Graph; - use crate::db::mutation_api::AdditionOps; + use crate::db::{api::mutation::AdditionOps, graph::graph::Graph}; fn load_graph(edges: Vec<(i64, u64, u64)>) -> Graph { let graph = Graph::new(); diff --git a/raphtory/src/algorithms/motifs/three_node_local.rs b/raphtory/src/algorithms/motifs/three_node_local.rs index 161d9ddc25..f657b5b94f 100644 --- a/raphtory/src/algorithms/motifs/three_node_local.rs +++ b/raphtory/src/algorithms/motifs/three_node_local.rs @@ -1,8 +1,6 @@ +use crate::{algorithms::motifs::three_node_motifs::*, db::api::view::*}; use std::collections::HashMap; -use crate::algorithms::motifs::three_node_motifs::*; -use crate::db::view_api::*; - pub fn star_motif_count(graph: &G, v: u64, delta: i64) -> [usize; 24] { if let Some(vertex) = graph.vertex(v) { let neigh_map: HashMap = vertex @@ -238,9 +236,10 @@ pub fn global_temporal_three_node_motifs(graph: &G, delta: i64) #[cfg(test)] mod local_motif_test { - use crate::algorithms::motifs::three_node_local::*; - use crate::db::graph::Graph; - use crate::db::mutation_api::AdditionOps; + use crate::{ + algorithms::motifs::three_node_local::*, + db::{api::mutation::AdditionOps, graph::graph::Graph}, + }; #[test] fn test_init() { diff --git a/raphtory/src/algorithms/pagerank.rs b/raphtory/src/algorithms/pagerank.rs index 8da8f59b25..25194fa87f 100644 --- a/raphtory/src/algorithms/pagerank.rs +++ b/raphtory/src/algorithms/pagerank.rs @@ -1,18 +1,18 @@ -use num_traits::abs; - -use crate::core::tgraph::VID; -use crate::db::view_api::VertexViewOps; use crate::{ - core::state::{accumulator_id::accumulators, compute_state::ComputeStateVec}, + core::{ + entities::VID, + state::{accumulator_id::accumulators, compute_state::ComputeStateVec}, + }, db::{ + api::view::{GraphViewOps, VertexViewOps}, task::{ context::Context, task::{ATask, Job, Step}, task_runner::TaskRunner, }, - view_api::GraphViewOps, }, }; +use num_traits::abs; use std::collections::HashMap; #[derive(Clone, Debug)] @@ -170,8 +170,7 @@ mod page_rank_tests { use itertools::Itertools; use pretty_assertions::assert_eq; - use crate::db::graph::Graph; - use crate::db::mutation_api::AdditionOps; + use crate::db::{api::mutation::AdditionOps, graph::graph::Graph}; use super::*; diff --git a/raphtory/src/algorithms/reciprocity.rs b/raphtory/src/algorithms/reciprocity.rs index 1fe3e56353..a4f604988a 100644 --- a/raphtory/src/algorithms/reciprocity.rs +++ b/raphtory/src/algorithms/reciprocity.rs @@ -23,9 +23,7 @@ //! //! ```rust //! use raphtory::algorithms::reciprocity::{all_local_reciprocity, global_reciprocity}; -//! use raphtory::db::graph::Graph; -//! use raphtory::db::mutation_api::AdditionOps; -//! use raphtory::db::view_api::*; +//! use raphtory::prelude::*; //! let g = Graph::new(); //! let vs = vec![ //! (1, 1, 2), @@ -45,13 +43,21 @@ //! println!("all_local_reciprocity: {:?}", all_local_reciprocity(&g, None)); //! println!("global_reciprocity: {:?}", global_reciprocity(&g, None)); //! ``` -use crate::core::state::accumulator_id::accumulators::sum; -use crate::core::state::compute_state::{ComputeState, ComputeStateVec}; -use crate::db::task::context::Context; -use crate::db::task::eval_vertex::EvalVertexView; -use crate::db::task::task::{ATask, Job, Step}; -use crate::db::task::task_runner::TaskRunner; -use crate::db::view_api::{GraphViewOps, VertexViewOps}; +use crate::{ + core::state::{ + accumulator_id::accumulators::sum, + compute_state::{ComputeState, ComputeStateVec}, + }, + db::{ + api::view::{GraphViewOps, VertexViewOps}, + task::{ + context::Context, + task::{ATask, Job, Step}, + task_runner::TaskRunner, + vertex::eval_vertex::EvalVertexView, + }, + }, +}; use std::collections::{HashMap, HashSet}; /// Gets the unique edge counts excluding cycles for a vertex. Returns a tuple of usize @@ -140,9 +146,10 @@ pub fn all_local_reciprocity( #[cfg(test)] mod reciprocity_test { - use crate::algorithms::reciprocity::{all_local_reciprocity, global_reciprocity}; - use crate::db::graph::Graph; - use crate::db::mutation_api::AdditionOps; + use crate::{ + algorithms::reciprocity::{all_local_reciprocity, global_reciprocity}, + db::{api::mutation::AdditionOps, graph::graph::Graph}, + }; use pretty_assertions::assert_eq; use std::collections::HashMap; diff --git a/raphtory/src/algorithms/temporal_reachability.rs b/raphtory/src/algorithms/temporal_reachability.rs index 85b1adc344..f88b17d9e0 100644 --- a/raphtory/src/algorithms/temporal_reachability.rs +++ b/raphtory/src/algorithms/temporal_reachability.rs @@ -1,14 +1,21 @@ -use crate::core::state::accumulator_id::accumulators::{hash_set, min, or}; -use crate::core::state::compute_state::ComputeStateVec; -use crate::core::vertex::InputVertex; -use crate::db::task::context::Context; -use crate::db::task::task::{ATask, Job, Step}; -use crate::db::task::task_runner::TaskRunner; -use crate::db::view_api::*; +use crate::{ + core::{ + entities::vertices::input_vertex::InputVertex, + state::{ + accumulator_id::accumulators::{hash_set, min, or}, + compute_state::ComputeStateVec, + }, + }, + db::task::{ + context::Context, + task::{ATask, Job, Step}, + task_runner::TaskRunner, + }, + prelude::*, +}; use itertools::Itertools; use num_traits::Zero; -use std::collections::HashMap; -use std::ops::Add; +use std::{collections::HashMap, ops::Add}; #[derive(Eq, Hash, PartialEq, Clone, Debug, Default)] pub struct TaintMessage { @@ -183,8 +190,7 @@ pub fn temporally_reachable_nodes( #[cfg(test)] mod generic_taint_tests { use super::*; - use crate::db::graph::Graph; - use crate::db::mutation_api::AdditionOps; + use crate::db::{api::mutation::AdditionOps, graph::graph::Graph}; fn load_graph(edges: Vec<(i64, u64, u64)>) -> Graph { let graph = Graph::new(); diff --git a/raphtory/src/algorithms/triangle_count.rs b/raphtory/src/algorithms/triangle_count.rs index 2e538afdad..40804c5231 100644 --- a/raphtory/src/algorithms/triangle_count.rs +++ b/raphtory/src/algorithms/triangle_count.rs @@ -1,9 +1,14 @@ -use crate::core::state::accumulator_id::accumulators; -use crate::core::state::compute_state::ComputeStateVec; -use crate::db::task::context::Context; -use crate::db::task::task::{ATask, Job, Step}; -use crate::db::task::task_runner::TaskRunner; -use crate::db::view_api::*; +use crate::{ + core::state::{accumulator_id::accumulators, compute_state::ComputeStateVec}, + db::{ + api::view::*, + task::{ + context::Context, + task::{ATask, Job, Step}, + task_runner::TaskRunner, + }, + }, +}; use rustc_hash::FxHashSet; /// Computes the number of triangles in a graph using a fast algorithm @@ -21,9 +26,8 @@ use rustc_hash::FxHashSet; /// # Example /// ```rust /// use std::{cmp::Reverse, iter::once}; -/// use raphtory::db::graph::Graph; /// use raphtory::algorithms::triangle_count::triangle_count; -/// use raphtory::db::mutation_api::AdditionOps; +/// use raphtory::prelude::*; /// /// let graph = Graph::new(); /// @@ -116,8 +120,7 @@ pub fn triangle_count(g: &G, threads: Option) -> usize { #[cfg(test)] mod triangle_count_tests { use super::*; - use crate::db::graph::Graph; - use crate::db::mutation_api::AdditionOps; + use crate::db::{api::mutation::AdditionOps, graph::graph::Graph}; #[test] fn triangle_count_1() { diff --git a/raphtory/src/algorithms/triplet_count.rs b/raphtory/src/algorithms/triplet_count.rs index dcc116e8cf..9bb25656d0 100644 --- a/raphtory/src/algorithms/triplet_count.rs +++ b/raphtory/src/algorithms/triplet_count.rs @@ -32,12 +32,17 @@ //! println!("triplet count: {}", results); //! ``` //! -use crate::core::state::accumulator_id::accumulators::sum; -use crate::core::state::compute_state::ComputeStateVec; -use crate::db::task::context::Context; -use crate::db::task::task::{ATask, Job, Step}; -use crate::db::task::task_runner::TaskRunner; -use crate::db::view_api::{GraphViewOps, VertexViewOps}; +use crate::{ + core::state::{accumulator_id::accumulators::sum, compute_state::ComputeStateVec}, + db::{ + api::view::{GraphViewOps, VertexViewOps}, + task::{ + context::Context, + task::{ATask, Job, Step}, + task_runner::TaskRunner, + }, + }, +}; /// Computes the number of both open and closed triplets within a graph /// @@ -55,10 +60,8 @@ use crate::db::view_api::{GraphViewOps, VertexViewOps}; /// # Example /// /// ```rust -/// use raphtory::db::graph::Graph; /// use raphtory::algorithms::triplet_count::triplet_count; -/// use raphtory::db::mutation_api::AdditionOps; -/// use raphtory::db::view_api::*; +/// use raphtory::prelude::*; /// let graph = Graph::new(); /// let edges = vec![ /// (1, 2), @@ -111,9 +114,10 @@ pub fn triplet_count(g: &G, threads: Option) -> usize { #[cfg(test)] mod triplet_test { use super::*; - use crate::db::graph::Graph; - use crate::db::mutation_api::AdditionOps; - use crate::db::view_api::*; + use crate::db::{ + api::{mutation::AdditionOps, view::*}, + graph::graph::Graph, + }; use pretty_assertions::assert_eq; /// Test the global clustering coefficient diff --git a/raphtory/src/core/tgraph/edge.rs b/raphtory/src/core/entities/edges/edge.rs similarity index 93% rename from raphtory/src/core/tgraph/edge.rs rename to raphtory/src/core/entities/edges/edge.rs index 5cece3e54c..08713cb156 100644 --- a/raphtory/src/core/tgraph/edge.rs +++ b/raphtory/src/core/entities/edges/edge.rs @@ -1,22 +1,24 @@ -use std::{ - ops::{Deref, Range}, - sync::Arc, -}; - use crate::core::{ - locked_view::LockedView, - storage::Entry, - timeindex::{TimeIndex, TimeIndexOps}, - tprop::TProp, + entities::{ + edges::edge_store::EdgeStore, + graph::{ + tgraph::TGraph, + tgraph_storage::{GraphEntry, LockedGraphStorage}, + }, + properties::tprop::TProp, + vertices::vertex::Vertex, + GraphItem, VRef, EID, VID, + }, + storage::{ + locked_view::LockedView, + timeindex::{TimeIndex, TimeIndexOps}, + Entry, + }, Direction, Prop, }; - -use super::{ - edge_store::EdgeStore, - tgraph::TGraph, - tgraph_storage::{GraphEntry, LockedGraphStorage}, - vertex::Vertex, - GraphItem, VRef, EID, VID, +use std::{ + ops::{Deref, Range}, + sync::Arc, }; #[derive(Debug)] diff --git a/raphtory/src/core/edge_ref.rs b/raphtory/src/core/entities/edges/edge_ref.rs similarity index 97% rename from raphtory/src/core/edge_ref.rs rename to raphtory/src/core/entities/edges/edge_ref.rs index d994167a2f..69bc5e06a6 100644 --- a/raphtory/src/core/edge_ref.rs +++ b/raphtory/src/core/entities/edges/edge_ref.rs @@ -1,6 +1,4 @@ -use crate::core::vertex_ref::VertexRef; - -use super::tgraph::{EID, VID}; +use crate::core::entities::{vertices::vertex_ref::VertexRef, EID, VID}; #[derive(Debug, Copy, Clone, PartialEq)] pub enum EdgeRef { diff --git a/raphtory/src/core/tgraph/edge_store.rs b/raphtory/src/core/entities/edges/edge_store.rs similarity index 96% rename from raphtory/src/core/tgraph/edge_store.rs rename to raphtory/src/core/entities/edges/edge_store.rs index 433a0b7c79..0be9d63947 100644 --- a/raphtory/src/core/tgraph/edge_store.rs +++ b/raphtory/src/core/entities/edges/edge_store.rs @@ -1,13 +1,16 @@ -use std::ops::{Deref, DerefMut, Range}; - -use itertools::Itertools; -use serde::{Deserialize, Serialize}; - use crate::core::{ - edge_ref::EdgeRef, errors::MutateGraphError, timeindex::TimeIndex, tprop::TProp, Prop, + entities::{ + edges::edge_ref::EdgeRef, + properties::{props::Props, tprop::TProp}, + EID, VID, + }, + storage::timeindex::TimeIndex, + utils::errors::MutateGraphError, + Prop, }; - -use super::{props::Props, EID, VID}; +use itertools::Itertools; +use serde::{Deserialize, Serialize}; +use std::ops::{Deref, DerefMut, Range}; #[derive(Serialize, Deserialize, Debug, Default, PartialEq)] pub(crate) struct EdgeStore { diff --git a/raphtory/src/core/entities/edges/mod.rs b/raphtory/src/core/entities/edges/mod.rs new file mode 100644 index 0000000000..28c344e2dd --- /dev/null +++ b/raphtory/src/core/entities/edges/mod.rs @@ -0,0 +1,3 @@ +pub(crate) mod edge; +pub mod edge_ref; +pub mod edge_store; diff --git a/raphtory/src/core/entities/graph/mod.rs b/raphtory/src/core/entities/graph/mod.rs new file mode 100644 index 0000000000..4616119204 --- /dev/null +++ b/raphtory/src/core/entities/graph/mod.rs @@ -0,0 +1,3 @@ +pub mod tgraph; +pub mod tgraph_storage; +pub(crate) mod timer; diff --git a/raphtory/src/core/tgraph/tgraph.rs b/raphtory/src/core/entities/graph/tgraph.rs similarity index 94% rename from raphtory/src/core/tgraph/tgraph.rs rename to raphtory/src/core/entities/graph/tgraph.rs index 6d817c4bfe..8a50323e7b 100644 --- a/raphtory/src/core/tgraph/tgraph.rs +++ b/raphtory/src/core/entities/graph/tgraph.rs @@ -1,32 +1,33 @@ -use std::{fmt::Debug, hash::BuildHasherDefault, ops::Deref, path::Path, sync::Arc}; - -use dashmap::DashMap; -use rustc_hash::FxHasher; -use serde::{Deserialize, Serialize}; - use crate::core::{ - errors::{GraphError, MutateGraphError}, - locked_view::LockedView, - storage::Entry, - time::TryIntoTime, - timeindex::TimeIndexOps, - tprop::TProp, - vertex::InputVertex, - vertex_ref::VertexRef, + entities::{ + edges::{ + edge::EdgeView, + edge_store::{EdgeLayer, EdgeStore}, + }, + graph::{ + tgraph_storage::{GraphStorage, LockedIter}, + timer::{MaxCounter, MinCounter, TimeCounterTrait}, + }, + properties::{graph_props::GraphProps, props::Meta, tprop::TProp}, + vertices::{ + input_vertex::InputVertex, + vertex::{ArcEdge, ArcVertex, Vertex}, + vertex_ref::VertexRef, + vertex_store::VertexStore, + }, + EID, VID, + }, + storage::{locked_view::LockedView, timeindex::TimeIndexOps, Entry}, + utils::{ + errors::{GraphError, MutateGraphError}, + time::TryIntoTime, + }, Direction, Prop, PropUnwrap, }; - -use super::{ - edge::EdgeView, - edge_store::{EdgeLayer, EdgeStore}, - graph_props::GraphProps, - node_store::NodeStore, - props::Meta, - tgraph_storage::{GraphStorage, LockedIter}, - timer::{MaxCounter, MinCounter, TimeCounterTrait}, - vertex::{ArcEdge, ArcVertex, Vertex}, - EID, VID, -}; +use dashmap::DashMap; +use rustc_hash::FxHasher; +use serde::{Deserialize, Serialize}; +use std::{fmt::Debug, hash::BuildHasherDefault, ops::Deref, path::Path, sync::Arc}; pub(crate) type FxDashMap = DashMap>; @@ -149,7 +150,7 @@ impl InnerTemporalGraph { .unwrap_or_else(|| node.global_id().to_string()) } - pub(crate) fn node_entry(&self, v: VID) -> Entry<'_, NodeStore, N> { + pub(crate) fn node_entry(&self, v: VID) -> Entry<'_, VertexStore, N> { self.storage.get_node(v.into()) } @@ -236,7 +237,7 @@ impl InnerTemporalGraph { // update the logical to physical mapping if needed let v_id = *(self.logical_to_physical.entry(v.id()).or_insert_with(|| { - let node_store = NodeStore::new(v.id(), t); + let node_store = VertexStore::new(v.id(), t); self.storage.push_node(node_store) })); @@ -262,7 +263,7 @@ impl InnerTemporalGraph { // update the logical to physical mapping if needed let v_id = *(self.logical_to_physical.entry(v.id()).or_insert_with(|| { - let node_store = NodeStore::new(v.id(), t); + let node_store = VertexStore::new(v.id(), t); self.storage.push_node(node_store) })); diff --git a/raphtory/src/core/tgraph/tgraph_storage.rs b/raphtory/src/core/entities/graph/tgraph_storage.rs similarity index 85% rename from raphtory/src/core/tgraph/tgraph_storage.rs rename to raphtory/src/core/entities/graph/tgraph_storage.rs index 67a4a0fad8..3d0e141119 100644 --- a/raphtory/src/core/tgraph/tgraph_storage.rs +++ b/raphtory/src/core/entities/graph/tgraph_storage.rs @@ -1,18 +1,15 @@ -use std::{ops::Deref, sync::Arc}; - -use serde::{Deserialize, Serialize}; - use crate::core::{ + entities::{edges::edge_store::EdgeStore, vertices::vertex_store::VertexStore}, storage::{self, ArcEntry, Entry, EntryMut, PairEntryMut}, Direction, }; - -use super::{edge_store::EdgeStore, node_store::NodeStore}; +use serde::{Deserialize, Serialize}; +use std::{ops::Deref, sync::Arc}; #[derive(Debug, Deserialize, Serialize, PartialEq)] pub(crate) struct GraphStorage { // node storage with having (id, time_index, properties, adj list for each layer) - nodes: storage::RawStorage, N>, + nodes: storage::RawStorage, N>, // edge storage with having (src, dst, time_index, properties) for each layer edges: storage::RawStorage, N>, @@ -26,7 +23,7 @@ impl GraphStorage { } } - pub(crate) fn push_node(&self, node: NodeStore) -> usize { + pub(crate) fn push_node(&self, node: VertexStore) -> usize { self.nodes.push(node, |vid, node| node.vid = vid.into()) } @@ -34,7 +31,7 @@ impl GraphStorage { self.edges.push(edge, |eid, edge| edge.eid = eid.into()) } - pub(crate) fn get_node_mut(&self, id: usize) -> EntryMut<'_, NodeStore> { + pub(crate) fn get_node_mut(&self, id: usize) -> EntryMut<'_, VertexStore> { self.nodes.entry_mut(id) } @@ -42,11 +39,11 @@ impl GraphStorage { self.edges.entry_mut(id) } - pub(crate) fn get_node(&self, id: usize) -> Entry<'_, NodeStore, N> { + pub(crate) fn get_node(&self, id: usize) -> Entry<'_, VertexStore, N> { self.nodes.entry(id) } - pub(crate) fn get_node_arc(&self, id: usize) -> ArcEntry, N> { + pub(crate) fn get_node_arc(&self, id: usize) -> ArcEntry, N> { self.nodes.entry_arc(id) } @@ -58,7 +55,7 @@ impl GraphStorage { self.edges.entry(id) } - pub(crate) fn pair_node_mut(&self, i: usize, j: usize) -> PairEntryMut<'_, NodeStore> { + pub(crate) fn pair_node_mut(&self, i: usize, j: usize) -> PairEntryMut<'_, VertexStore> { self.nodes.pair_entry_mut(i, j) } @@ -79,7 +76,7 @@ impl GraphStorage { LockedGraphStorage::new(self) } - pub(crate) fn locked_nodes(&self) -> LockedIter> { + pub(crate) fn locked_nodes(&self) -> LockedIter> { LockedIter { from: 0, to: self.nodes.len(), @@ -105,8 +102,8 @@ pub(crate) struct LockedIter { phantom: std::marker::PhantomData, } -impl Iterator for LockedIter> { - type Item = GraphEntry, N>; +impl Iterator for LockedIter> { + type Item = GraphEntry, N>; fn next(&mut self) -> Option { if self.from < self.to { @@ -166,8 +163,8 @@ impl<'a, const N: usize, T> GraphEntry { } } -impl<'a, const N: usize> Deref for GraphEntry, N> { - type Target = NodeStore; +impl<'a, const N: usize> Deref for GraphEntry, N> { + type Target = VertexStore; fn deref(&self) -> &Self::Target { self.locked_gs.get_node(self.i) @@ -184,7 +181,7 @@ impl<'a, const N: usize> Deref for GraphEntry, N> { #[derive(Debug)] pub(crate) struct LockedGraphStorage { - nodes: storage::ReadLockedStorage, N>, + nodes: storage::ReadLockedStorage, N>, edges: storage::ReadLockedStorage, N>, } @@ -196,7 +193,7 @@ impl LockedGraphStorage { } } - pub(crate) fn get_node(&self, id: usize) -> &NodeStore { + pub(crate) fn get_node(&self, id: usize) -> &VertexStore { self.nodes.get(id) } diff --git a/raphtory/src/core/tgraph/timer.rs b/raphtory/src/core/entities/graph/timer.rs similarity index 99% rename from raphtory/src/core/tgraph/timer.rs rename to raphtory/src/core/entities/graph/timer.rs index 59d8a58215..9728b2011e 100644 --- a/raphtory/src/core/tgraph/timer.rs +++ b/raphtory/src/core/entities/graph/timer.rs @@ -1,6 +1,5 @@ -use std::sync::atomic::{AtomicI64, Ordering}; - use serde::{Deserialize, Serialize}; +use std::sync::atomic::{AtomicI64, Ordering}; pub(crate) trait TimeCounterTrait { fn cmp(a: i64, b: i64) -> bool; diff --git a/raphtory/src/core/tgraph/mod.rs b/raphtory/src/core/entities/mod.rs similarity index 80% rename from raphtory/src/core/tgraph/mod.rs rename to raphtory/src/core/entities/mod.rs index eb909e91d2..ba3472506e 100644 --- a/raphtory/src/core/tgraph/mod.rs +++ b/raphtory/src/core/entities/mod.rs @@ -1,23 +1,18 @@ +#![allow(unused)] + use std::ops::Deref; +use edges::edge::ERef; +use graph::{tgraph::TGraph, tgraph_storage::GraphEntry}; use serde::{Deserialize, Serialize}; +use vertices::{vertex_ref::VertexRef, vertex_store::VertexStore}; -use self::{edge::ERef, node_store::NodeStore, tgraph::TGraph, tgraph_storage::GraphEntry}; - -use super::{storage::Entry, vertex_ref::VertexRef, Direction}; +use super::{storage::Entry, Direction}; -mod adj; -pub mod adjset; -pub(crate) mod edge; -mod edge_store; -mod graph_props; -mod iter; -mod node_store; -pub mod props; -pub mod tgraph; -mod tgraph_storage; -pub(crate) mod timer; -mod vertex; +pub mod edges; +pub mod graph; +pub mod properties; +pub mod vertices; // the only reason this is public is because the phisical ids of the vertices don't move #[repr(transparent)] @@ -72,8 +67,8 @@ impl From for EID { } pub(crate) enum VRef<'a, const N: usize> { - Entry(Entry<'a, NodeStore, N>), // returned from graph.vertex - LockedEntry(GraphEntry, N>), // returned from locked_vertices + Entry(Entry<'a, VertexStore, N>), // returned from graph.vertex + LockedEntry(GraphEntry, N>), // returned from locked_vertices } // return index -> usize for VRef @@ -97,7 +92,7 @@ impl<'a, const N: usize> VRef<'a, N> { } impl<'a, const N: usize> Deref for VRef<'a, N> { - type Target = NodeStore; + type Target = VertexStore; fn deref(&self) -> &Self::Target { match self { diff --git a/raphtory/src/core/tgraph/graph_props.rs b/raphtory/src/core/entities/properties/graph_props.rs similarity index 91% rename from raphtory/src/core/tgraph/graph_props.rs rename to raphtory/src/core/entities/properties/graph_props.rs index b09ae89a8c..31435c22c1 100644 --- a/raphtory/src/core/tgraph/graph_props.rs +++ b/raphtory/src/core/entities/properties/graph_props.rs @@ -1,9 +1,13 @@ +use crate::core::{ + entities::{ + graph::tgraph::FxDashMap, + properties::{props::DictMapper, tprop::TProp}, + }, + storage::locked_view::LockedView, + Prop, +}; use serde::{Deserialize, Serialize}; -use crate::core::{locked_view::LockedView, tprop::TProp, Prop}; - -use super::{props::DictMapper, tgraph::FxDashMap}; - #[derive(Serialize, Deserialize, Debug)] pub(crate) struct GraphProps { static_mapper: DictMapper, diff --git a/raphtory/src/core/entities/properties/mod.rs b/raphtory/src/core/entities/properties/mod.rs new file mode 100644 index 0000000000..c5875f71b6 --- /dev/null +++ b/raphtory/src/core/entities/properties/mod.rs @@ -0,0 +1,4 @@ +pub mod graph_props; +pub mod props; +pub mod tcell; +pub mod tprop; diff --git a/raphtory/src/core/tgraph/props.rs b/raphtory/src/core/entities/properties/props.rs similarity index 80% rename from raphtory/src/core/tgraph/props.rs rename to raphtory/src/core/entities/properties/props.rs index 94225ebb96..cfdb2e1c48 100644 --- a/raphtory/src/core/tgraph/props.rs +++ b/raphtory/src/core/entities/properties/props.rs @@ -1,21 +1,17 @@ +use crate::core::{ + entities::{graph::tgraph::FxDashMap, properties::tprop::TProp}, + storage::lazy_vec::LazyVec, + utils::errors::{IllegalMutate, MutateGraphError}, + Prop, +}; +use serde::{Deserialize, Serialize}; use std::{ hash::Hash, sync::atomic::{AtomicUsize, Ordering}, }; -use serde::{Deserialize, Serialize}; - -use crate::core::{ - errors::{IllegalMutate, MutateGraphError}, - lazy_vec::LazyVec, - tprop::TProp, - Prop, -}; - -use super::tgraph::FxDashMap; - #[derive(Serialize, Deserialize, Default, Debug, PartialEq)] -pub(crate) struct Props { +pub struct Props { // properties static_props: LazyVec>, temporal_props: LazyVec, @@ -35,12 +31,12 @@ impl Props { } } - pub(crate) fn add_prop(&mut self, t: i64, prop_id: usize, prop: Prop) { + pub fn add_prop(&mut self, t: i64, prop_id: usize, prop: Prop) { self.temporal_props .update_or_set(prop_id, |p| p.set(t, &prop), TProp::from(t, &prop)) } - pub(crate) fn add_static_prop( + pub fn add_static_prop( &mut self, prop_id: usize, prop_name: &str, @@ -53,10 +49,7 @@ impl Props { }) } - pub(crate) fn temporal_props( - &self, - prop_id: usize, - ) -> Box + '_> { + pub fn temporal_props(&self, prop_id: usize) -> Box + '_> { let o = self.temporal_props.get(prop_id); if let Some(t_prop) = o { Box::new(t_prop.iter().map(|(t, p)| (t, p.clone()))) @@ -65,7 +58,7 @@ impl Props { } } - pub(crate) fn temporal_props_window( + pub fn temporal_props_window( &self, prop_id: usize, t_start: i64, @@ -83,33 +76,33 @@ impl Props { } } - pub(crate) fn static_prop(&self, prop_id: usize) -> Option<&Prop> { + pub fn static_prop(&self, prop_id: usize) -> Option<&Prop> { let prop = self.static_props.get(prop_id)?; prop.as_ref() } - pub(crate) fn temporal_prop(&self, prop_id: usize) -> Option<&TProp> { + pub fn temporal_prop(&self, prop_id: usize) -> Option<&TProp> { self.temporal_props.get(prop_id) } - pub(crate) fn static_prop_ids(&self) -> Vec { + pub fn static_prop_ids(&self) -> Vec { self.static_props.filled_ids() } - pub(crate) fn temporal_prop_ids(&self) -> Vec { + pub fn temporal_prop_ids(&self) -> Vec { self.temporal_props.filled_ids() } } #[derive(Serialize, Deserialize, Debug)] -pub(crate) struct Meta { +pub struct Meta { meta_prop_temporal: DictMapper, meta_prop_static: DictMapper, meta_layer: DictMapper, } impl Meta { - pub(crate) fn new() -> Self { + pub fn new() -> Self { let meta_layer = DictMapper::default(); meta_layer.get_or_create_id("_default".to_owned()); Self { @@ -119,7 +112,7 @@ impl Meta { } } - pub(crate) fn resolve_prop_ids( + pub fn resolve_prop_ids( &self, props: Vec<(String, Prop)>, is_static: bool, @@ -134,7 +127,7 @@ impl Meta { }) } - pub(crate) fn resolve_prop_id(&self, name: &str, is_static: bool) -> usize { + pub fn resolve_prop_id(&self, name: &str, is_static: bool) -> usize { if is_static { self.meta_prop_static.get_or_create_id(name.to_string()) } else { @@ -142,7 +135,7 @@ impl Meta { } } - pub(crate) fn find_prop_id(&self, name: &str, is_static: bool) -> Option { + pub fn find_prop_id(&self, name: &str, is_static: bool) -> Option { if is_static { self.meta_prop_static.get(&name.to_owned()) } else { @@ -150,15 +143,15 @@ impl Meta { } } - pub(crate) fn get_or_create_layer_id(&self, name: String) -> usize { + pub fn get_or_create_layer_id(&self, name: String) -> usize { self.meta_layer.get_or_create_id(name) } - pub(crate) fn get_layer_id(&self, name: &str) -> Option { + pub fn get_layer_id(&self, name: &str) -> Option { self.meta_layer.map.get(name).as_deref().copied() } - pub(crate) fn get_layer_name_by_id(&self, id: usize) -> Option { + pub fn get_layer_name_by_id(&self, id: usize) -> Option { self.meta_layer .map .iter() @@ -166,7 +159,7 @@ impl Meta { .map(|entry| entry.key().clone()) } - pub(crate) fn get_all_layers(&self) -> Vec { + pub fn get_all_layers(&self) -> Vec { self.meta_layer .map .iter() @@ -174,7 +167,7 @@ impl Meta { .collect() } - pub(crate) fn reverse_prop_id(&self, prop_id: usize, is_static: bool) -> Option { + pub fn reverse_prop_id(&self, prop_id: usize, is_static: bool) -> Option { if is_static { self.meta_prop_static.reverse_lookup(&prop_id) } else { @@ -204,7 +197,7 @@ impl DictMapper { *new_id } - pub(crate) fn get(&self, name: &T) -> Option { + pub fn get(&self, name: &T) -> Option { self.map.get(name).map(|id| *id) } @@ -212,7 +205,7 @@ impl DictMapper { self.reverse_map.get(id).map(|name| name.clone()) } - pub(crate) fn get_keys(&self) -> Vec { + pub fn get_keys(&self) -> Vec { self.map.iter().map(|entry| entry.key().clone()).collect() } } @@ -234,8 +227,7 @@ mod test { // map 5 strings to 5 ids from 4 threads concurrently 1000 times #[test] fn test_dict_mapper_concurrent() { - use std::sync::Arc; - use std::thread; + use std::{sync::Arc, thread}; let mapper = Arc::new(DictMapper::default()); let mut threads = Vec::new(); diff --git a/raphtory/src/core/tcell.rs b/raphtory/src/core/entities/properties/tcell.rs similarity index 99% rename from raphtory/src/core/tcell.rs rename to raphtory/src/core/entities/properties/tcell.rs index 4de1566767..7355b47f3d 100644 --- a/raphtory/src/core/tcell.rs +++ b/raphtory/src/core/entities/properties/tcell.rs @@ -1,8 +1,6 @@ -use std::{collections::BTreeMap, fmt::Debug, ops::Range}; - +use crate::core::storage::sorted_vec_map::SVM; use serde::{Deserialize, Serialize}; - -use crate::core::sorted_vec_map::SVM; +use std::{collections::BTreeMap, fmt::Debug, ops::Range}; #[derive(Debug, PartialEq, Default, Clone, Serialize, Deserialize)] diff --git a/raphtory/src/core/tprop.rs b/raphtory/src/core/entities/properties/tprop.rs similarity index 99% rename from raphtory/src/core/tprop.rs rename to raphtory/src/core/entities/properties/tprop.rs index acc0a61fce..50eba7cfca 100644 --- a/raphtory/src/core/tprop.rs +++ b/raphtory/src/core/entities/properties/tprop.rs @@ -1,6 +1,7 @@ -use crate::core::tcell::TCell; -use crate::core::Prop; -use crate::db::graph::Graph; +use crate::{ + core::{entities::properties::tcell::TCell, Prop}, + db::graph::graph::Graph, +}; use chrono::NaiveDateTime; use serde::{Deserialize, Serialize}; use std::ops::Range; diff --git a/raphtory/src/core/vertex.rs b/raphtory/src/core/entities/vertices/input_vertex.rs similarity index 89% rename from raphtory/src/core/vertex.rs rename to raphtory/src/core/entities/vertices/input_vertex.rs index d96ebd248a..ceb6f0511b 100644 --- a/raphtory/src/core/vertex.rs +++ b/raphtory/src/core/entities/vertices/input_vertex.rs @@ -4,7 +4,7 @@ //! This trait allows you to use a variety of types as input vertices, including //! `u64`, `&str`, and `String`. -use crate::core::utils; +use crate::core::utils::hashing; pub trait InputVertex: Clone { fn id(&self) -> u64; @@ -23,7 +23,7 @@ impl InputVertex for u64 { impl<'a> InputVertex for &'a str { fn id(&self) -> u64 { - self.parse().unwrap_or(utils::calculate_hash(self)) + self.parse().unwrap_or(hashing::calculate_hash(self)) } fn id_str(&self) -> Option<&str> { diff --git a/raphtory/src/core/entities/vertices/mod.rs b/raphtory/src/core/entities/vertices/mod.rs new file mode 100644 index 0000000000..3ad56d82de --- /dev/null +++ b/raphtory/src/core/entities/vertices/mod.rs @@ -0,0 +1,5 @@ +pub mod input_vertex; +pub mod structure; +pub mod vertex; +pub mod vertex_ref; +pub mod vertex_store; diff --git a/raphtory/src/core/tgraph/adj.rs b/raphtory/src/core/entities/vertices/structure/adj.rs similarity index 96% rename from raphtory/src/core/tgraph/adj.rs rename to raphtory/src/core/entities/vertices/structure/adj.rs index 8edbd602b6..049ebb49d0 100644 --- a/raphtory/src/core/tgraph/adj.rs +++ b/raphtory/src/core/entities/vertices/structure/adj.rs @@ -1,11 +1,11 @@ +use crate::core::{ + entities::{vertices::structure::adjset::AdjSet, EID, VID}, + Direction, +}; use core::panic; - -use crate::core::Direction; use itertools::Itertools; use serde::{Deserialize, Serialize}; -use super::{adjset::AdjSet, EID, VID}; - #[derive(Debug, Serialize, Deserialize, PartialEq, Default)] pub(crate) enum Adj { #[default] diff --git a/raphtory/src/core/tgraph/adjset.rs b/raphtory/src/core/entities/vertices/structure/adjset.rs similarity index 100% rename from raphtory/src/core/tgraph/adjset.rs rename to raphtory/src/core/entities/vertices/structure/adjset.rs diff --git a/raphtory/src/core/tgraph/iter.rs b/raphtory/src/core/entities/vertices/structure/iter.rs similarity index 95% rename from raphtory/src/core/tgraph/iter.rs rename to raphtory/src/core/entities/vertices/structure/iter.rs index 5b90ee449b..a54e0afa4b 100644 --- a/raphtory/src/core/tgraph/iter.rs +++ b/raphtory/src/core/entities/vertices/structure/iter.rs @@ -1,10 +1,9 @@ -use std::sync::Arc; - +use crate::core::{ + entities::{edges::edge::EdgeView, graph::tgraph::TGraph, VRef, EID, VID}, + Direction, +}; use itertools::Merge; - -use crate::core::Direction; - -use super::{edge::EdgeView, tgraph::TGraph, VRef, EID, VID}; +use std::sync::Arc; pub struct Paged<'a, const N: usize> { guard: Arc>, diff --git a/raphtory/src/core/entities/vertices/structure/mod.rs b/raphtory/src/core/entities/vertices/structure/mod.rs new file mode 100644 index 0000000000..9eaadd3beb --- /dev/null +++ b/raphtory/src/core/entities/vertices/structure/mod.rs @@ -0,0 +1,3 @@ +pub mod adj; +pub mod adjset; +pub mod iter; diff --git a/raphtory/src/core/tgraph/vertex.rs b/raphtory/src/core/entities/vertices/vertex.rs similarity index 86% rename from raphtory/src/core/tgraph/vertex.rs rename to raphtory/src/core/entities/vertices/vertex.rs index fe630ba441..b8adcda2af 100644 --- a/raphtory/src/core/tgraph/vertex.rs +++ b/raphtory/src/core/entities/vertices/vertex.rs @@ -1,24 +1,23 @@ -use std::{ops::Range, sync::Arc}; - -use itertools::Itertools; - use crate::core::{ - edge_ref::EdgeRef, - locked_view::LockedView, - storage::{ArcEntry, Entry}, - timeindex::{TimeIndex, TimeIndexOps}, - tprop::TProp, + entities::{ + edges::{edge::EdgeView, edge_ref::EdgeRef, edge_store::EdgeStore}, + graph::tgraph::TGraph, + properties::tprop::TProp, + vertices::{ + structure::iter::{Paged, PagedIter}, + vertex_store::VertexStore, + }, + VRef, VID, + }, + storage::{ + locked_view::LockedView, + timeindex::{TimeIndex, TimeIndexOps}, + ArcEntry, Entry, + }, Direction, Prop, }; - -use super::{ - edge::EdgeView, - edge_store::EdgeStore, - iter::{Paged, PagedIter}, - node_store::NodeStore, - tgraph::TGraph, - VRef, VID, -}; +use itertools::Itertools; +use std::{ops::Range, sync::Arc}; pub struct Vertex<'a, const N: usize> { node: VRef<'a, N>, @@ -34,7 +33,7 @@ impl<'a, const N: usize> Vertex<'a, N> { Vertex { node, graph } } - pub(crate) fn from_entry(node: Entry<'a, NodeStore, N>, graph: &'a TGraph) -> Self { + pub(crate) fn from_entry(node: Entry<'a, VertexStore, N>, graph: &'a TGraph) -> Self { Self::new(VRef::Entry(node), graph) } @@ -125,11 +124,11 @@ impl<'a, const N: usize> IntoIterator for Vertex<'a, N> { } pub struct ArcVertex { - e: ArcEntry, N>, + e: ArcEntry, N>, } impl ArcVertex { - pub(crate) fn from_entry(e: ArcEntry, N>) -> Self { + pub(crate) fn from_entry(e: ArcEntry, N>) -> Self { ArcVertex { e } } diff --git a/raphtory/src/core/vertex_ref.rs b/raphtory/src/core/entities/vertices/vertex_ref.rs similarity index 93% rename from raphtory/src/core/vertex_ref.rs rename to raphtory/src/core/entities/vertices/vertex_ref.rs index 97961101ef..4fe34144d2 100644 --- a/raphtory/src/core/vertex_ref.rs +++ b/raphtory/src/core/entities/vertices/vertex_ref.rs @@ -1,6 +1,4 @@ -use crate::core::vertex::InputVertex; - -use super::tgraph::VID; +use crate::core::entities::{vertices::input_vertex::InputVertex, VID}; #[derive(Copy, Clone, PartialOrd, PartialEq, Debug)] pub enum VertexRef { diff --git a/raphtory/src/core/tgraph/node_store.rs b/raphtory/src/core/entities/vertices/vertex_store.rs similarity index 94% rename from raphtory/src/core/tgraph/node_store.rs rename to raphtory/src/core/entities/vertices/vertex_store.rs index 6df6225235..ebfaa20ac8 100644 --- a/raphtory/src/core/tgraph/node_store.rs +++ b/raphtory/src/core/entities/vertices/vertex_store.rs @@ -1,17 +1,20 @@ -use std::ops::Range; - -use itertools::Itertools; -use serde::{Deserialize, Serialize}; - use crate::core::{ - edge_ref::EdgeRef, errors::MutateGraphError, timeindex::TimeIndex, tprop::TProp, Direction, - Prop, + entities::{ + edges::edge_ref::EdgeRef, + properties::{props::Props, tprop::TProp}, + vertices::structure::{adj, adj::Adj}, + EID, VID, + }, + storage::timeindex::TimeIndex, + utils::errors::MutateGraphError, + Direction, Prop, }; - -use super::{adj::Adj, props::Props, EID, VID}; +use itertools::Itertools; +use serde::{Deserialize, Serialize}; +use std::ops::Range; #[derive(Serialize, Deserialize, Debug, Default, PartialEq)] -pub(crate) struct NodeStore { +pub(crate) struct VertexStore { global_id: u64, pub(crate) vid: VID, // all the timestamps that have been seen by this vertex @@ -22,7 +25,7 @@ pub(crate) struct NodeStore { props: Option, } -impl NodeStore { +impl VertexStore { pub fn new(global_id: u64, t: i64) -> Self { let mut layers = Vec::with_capacity(1); layers.push(Adj::Solo); @@ -63,7 +66,7 @@ impl NodeStore { Ok(()) } - pub(crate) fn find_edge(&self, dst: VID, layer_id: Option) -> Option { + pub(crate) fn find_edge(&self, dst: VID, layer_id: Option) -> Option { match layer_id { Some(layer_id) => { let layer_adj = self.layers.get(layer_id)?; @@ -80,13 +83,7 @@ impl NodeStore { None } - pub(crate) fn add_edge( - &mut self, - v_id: VID, - dir: Direction, - layer: usize, - edge_id: super::EID, - ) { + pub(crate) fn add_edge(&mut self, v_id: VID, dir: Direction, layer: usize, edge_id: EID) { if layer >= self.layers.len() { self.layers.resize_with(layer + 1, || Adj::Solo); } diff --git a/raphtory/src/core/locked_view.rs b/raphtory/src/core/locked_view.rs deleted file mode 100644 index 3d850a1257..0000000000 --- a/raphtory/src/core/locked_view.rs +++ /dev/null @@ -1,30 +0,0 @@ -//! A data structure for sharding a temporal graph. -//! -//! When a raphtory graph is created, the code will automatically shard the graph depending -//! on how many shards you set the graph to originally have when initializing it. -//! -//! For example, Graph::new(4) will create a graph with 4 shards. -//! -//! Each of these shards will be stored in a separate file, and will be loaded into memory when needed. -//! -//! Each shard will have its own set of vertex and edge data, and will be able to be queried independently. - -use std::{hash::BuildHasherDefault, ops::Deref}; - -use dashmap::mapref::one::Ref; - -pub enum LockedView<'a, T> { - Locked(parking_lot::MappedRwLockReadGuard<'a, T>), - DashMap(Ref<'a, usize, T, BuildHasherDefault>), -} - -impl<'a, T> Deref for LockedView<'a, T> { - type Target = T; - - fn deref(&self) -> &Self::Target { - match self { - LockedView::Locked(guard) => guard.deref(), - LockedView::DashMap(r) => (*r).deref(), - } - } -} diff --git a/raphtory/src/core/mod.rs b/raphtory/src/core/mod.rs index a2cc17b0d5..087a5d7a17 100644 --- a/raphtory/src/core/mod.rs +++ b/raphtory/src/core/mod.rs @@ -24,8 +24,7 @@ //! * `macOS` //! -use crate::db::graph::Graph; -use crate::db::view_api::GraphViewOps; +use crate::db::{api::view::GraphViewOps, graph::graph::Graph}; use chrono::NaiveDateTime; use serde::{Deserialize, Serialize}; use std::fmt; @@ -33,21 +32,10 @@ use std::fmt; #[cfg(test)] extern crate core; -pub mod edge_ref; -pub mod errors; -mod lazy_vec; -pub mod locked_view; -mod sorted_vec_map; +pub mod entities; pub mod state; -mod storage; -mod tcell; -pub mod tgraph; -pub mod time; -pub mod timeindex; -pub mod tprop; +pub(crate) mod storage; pub mod utils; -pub mod vertex; -pub mod vertex_ref; /// Denotes the direction of an edge. Can be incoming, outgoing or both. #[derive(Clone, Copy, PartialEq, PartialOrd, Debug)] diff --git a/raphtory/src/core/state/accumulator_id.rs b/raphtory/src/core/state/accumulator_id.rs index 21a2e9dd80..96ad01e743 100644 --- a/raphtory/src/core/state/accumulator_id.rs +++ b/raphtory/src/core/state/accumulator_id.rs @@ -39,13 +39,13 @@ unsafe impl> Sync for AccId: Send + Sync + 'static { @@ -404,7 +403,10 @@ mod agg_test { #[test] fn avg_def() { - use super::{topk::TopK, topk::TopKHeap, Accumulator, AvgDef, MaxDef, MinDef, SumDef}; + use super::{ + topk::{TopK, TopKHeap}, + Accumulator, AvgDef, MaxDef, MinDef, SumDef, + }; let mut avg = AvgDef::::zero(); let mut sum = SumDef::::zero(); diff --git a/raphtory/src/core/state/compute_state.rs b/raphtory/src/core/state/compute_state.rs index ef9574cd56..5052bd8d6b 100644 --- a/raphtory/src/core/state/compute_state.rs +++ b/raphtory/src/core/state/compute_state.rs @@ -1,12 +1,9 @@ -use std::collections::HashMap; - -use crate::core::state::agg::Accumulator; -use crate::db::view_api::GraphViewOps; - use super::{ container::{merge_2_vecs, DynArray, VecArray}, StateType, }; +use crate::{core::state::agg::Accumulator, db::api::view::GraphViewOps}; +use std::collections::HashMap; pub trait ComputeState: std::fmt::Debug + Clone + Send + Sync { fn clone_current_into_other(&mut self, ss: usize); diff --git a/raphtory/src/core/state/container.rs b/raphtory/src/core/state/container.rs index f1fb8b431f..6edc446d8e 100644 --- a/raphtory/src/core/state/container.rs +++ b/raphtory/src/core/state/container.rs @@ -1,6 +1,5 @@ -use std::any::Any; - use super::StateType; +use std::any::Any; pub trait DynArray: std::fmt::Debug + Send + Sync { fn as_any(&self) -> &dyn Any; diff --git a/raphtory/src/core/state/mod.rs b/raphtory/src/core/state/mod.rs index 8bad036b86..415a199d22 100644 --- a/raphtory/src/core/state/mod.rs +++ b/raphtory/src/core/state/mod.rs @@ -14,13 +14,12 @@ mod state_test { use itertools::Itertools; use rand::Rng; - use crate::db::mutation_api::AdditionOps; use crate::{ core::state::{ accumulator_id::accumulators, compute_state::ComputeStateVec, container::merge_2_vecs, morcel_state::MorcelComputeState, shuffle_state::ShuffleComputeState, }, - db::graph::Graph, + db::{api::mutation::AdditionOps, graph::graph::Graph}, }; #[quickcheck] @@ -191,7 +190,6 @@ mod state_test { #[test] fn sum_aggregates_for_3_keys_2_parts() { - let sum = accumulators::sum(0); let mut part1_state: ShuffleComputeState = diff --git a/raphtory/src/core/state/morcel_state.rs b/raphtory/src/core/state/morcel_state.rs index f670740351..bbb919b3ff 100644 --- a/raphtory/src/core/state/morcel_state.rs +++ b/raphtory/src/core/state/morcel_state.rs @@ -1,6 +1,5 @@ use super::{accumulator_id::AccId, compute_state::ComputeState, StateType}; -use crate::core::state::agg::Accumulator; -use crate::db::view_api::GraphViewOps; +use crate::{core::state::agg::Accumulator, db::api::view::GraphViewOps}; use rustc_hash::FxHashMap; use std::collections::HashMap; diff --git a/raphtory/src/core/state/shuffle_state.rs b/raphtory/src/core/state/shuffle_state.rs index c4bdaa3579..f4e87238a9 100644 --- a/raphtory/src/core/state/shuffle_state.rs +++ b/raphtory/src/core/state/shuffle_state.rs @@ -1,16 +1,17 @@ -use crate::core::state::agg::Accumulator; -use crate::db::task::task_state::{Global, Shard}; -use crate::db::view_api::GraphViewOps; -use std::borrow::Borrow; -use std::collections::HashMap; -use std::sync::Arc; - use super::{ accumulator_id::AccId, compute_state::ComputeState, morcel_state::{MorcelComputeState, GLOBAL_STATE_KEY}, StateType, }; +use crate::{ + core::state::agg::Accumulator, + db::{ + api::view::GraphViewOps, + task::task_state::{Global, Shard}, + }, +}; +use std::{borrow::Borrow, collections::HashMap, sync::Arc}; #[derive(Debug, Clone)] pub struct ShuffleComputeState { diff --git a/raphtory/src/core/storage/iter.rs b/raphtory/src/core/storage/iter.rs index 0280ebccb2..b0b2c40f34 100644 --- a/raphtory/src/core/storage/iter.rs +++ b/raphtory/src/core/storage/iter.rs @@ -1,6 +1,5 @@ -use std::{ops::Deref, sync::Arc}; - use super::RawStorage; +use std::{ops::Deref, sync::Arc}; pub struct Iter<'a, T, const N: usize> { raw: &'a RawStorage, diff --git a/raphtory/src/core/lazy_vec.rs b/raphtory/src/core/storage/lazy_vec.rs similarity index 100% rename from raphtory/src/core/lazy_vec.rs rename to raphtory/src/core/storage/lazy_vec.rs diff --git a/raphtory/src/core/storage/locked_view.rs b/raphtory/src/core/storage/locked_view.rs new file mode 100644 index 0000000000..0e8107b97a --- /dev/null +++ b/raphtory/src/core/storage/locked_view.rs @@ -0,0 +1,18 @@ +use dashmap::mapref::one::Ref; +use std::{hash::BuildHasherDefault, ops::Deref}; + +pub enum LockedView<'a, T> { + Locked(parking_lot::MappedRwLockReadGuard<'a, T>), + DashMap(Ref<'a, usize, T, BuildHasherDefault>), +} + +impl<'a, T> Deref for LockedView<'a, T> { + type Target = T; + + fn deref(&self) -> &Self::Target { + match self { + LockedView::Locked(guard) => guard.deref(), + LockedView::DashMap(r) => (*r).deref(), + } + } +} diff --git a/raphtory/src/core/storage/mod.rs b/raphtory/src/core/storage/mod.rs index b78729a18f..e0d8c55db2 100644 --- a/raphtory/src/core/storage/mod.rs +++ b/raphtory/src/core/storage/mod.rs @@ -1,5 +1,15 @@ +#![allow(unused)] + pub(crate) mod iter; +pub mod lazy_vec; +pub mod locked_view; +pub mod sorted_vec_map; +pub mod timeindex; +use self::iter::Iter; +use locked_view::LockedView; +use parking_lot::{RwLock, RwLockReadGuard}; +use serde::{Deserialize, Serialize}; use std::{ fmt::Debug, ops::{Deref, DerefMut}, @@ -9,13 +19,6 @@ use std::{ }, }; -use parking_lot::{RwLock, RwLockReadGuard}; -use serde::{Deserialize, Serialize}; - -use crate::core::locked_view::LockedView; - -use self::iter::Iter; - fn resolve(index: usize) -> (usize, usize) { let bucket = index % N; let offset = index / N; diff --git a/raphtory/src/core/sorted_vec_map.rs b/raphtory/src/core/storage/sorted_vec_map.rs similarity index 99% rename from raphtory/src/core/sorted_vec_map.rs rename to raphtory/src/core/storage/sorted_vec_map.rs index 4a6a3c3059..a5036969c9 100644 --- a/raphtory/src/core/sorted_vec_map.rs +++ b/raphtory/src/core/storage/sorted_vec_map.rs @@ -1,7 +1,6 @@ -use std::ops::Range; - use serde::{ser::SerializeSeq, Deserialize, Serialize}; use sorted_vector_map::SortedVectorMap; +use std::ops::Range; // wrapper for SortedVectorMap #[derive(Debug, PartialEq, Default, Clone)] diff --git a/raphtory/src/core/timeindex.rs b/raphtory/src/core/storage/timeindex.rs similarity index 98% rename from raphtory/src/core/timeindex.rs rename to raphtory/src/core/storage/timeindex.rs index 4411dc2e9e..a8a9dea6a8 100644 --- a/raphtory/src/core/timeindex.rs +++ b/raphtory/src/core/storage/timeindex.rs @@ -1,7 +1,9 @@ use serde::{Deserialize, Serialize}; -use std::cmp::{max, min}; -use std::collections::BTreeSet; -use std::ops::Range; +use std::{ + cmp::{max, min}, + collections::BTreeSet, + ops::Range, +}; #[derive(Default, Debug, Clone, Serialize, Deserialize, PartialEq)] pub enum TimeIndex { diff --git a/raphtory/src/core/errors.rs b/raphtory/src/core/utils/errors.rs similarity index 95% rename from raphtory/src/core/errors.rs rename to raphtory/src/core/utils/errors.rs index 03c689a9ad..214707123d 100644 --- a/raphtory/src/core/errors.rs +++ b/raphtory/src/core/utils/errors.rs @@ -1,6 +1,4 @@ -use crate::core::time::error::ParseTimeError; - -use super::{lazy_vec::IllegalSet, Prop}; +use crate::core::{storage::lazy_vec::IllegalSet, utils::time::error::ParseTimeError, Prop}; #[derive(thiserror::Error, Debug)] pub enum GraphError { @@ -74,8 +72,6 @@ pub enum MutateGraphError { }, } -pub type MutateGraphResult = Result<(), MutateGraphError>; - #[derive(thiserror::Error, Debug, PartialEq)] #[error("cannot mutate static property '{name}'")] pub struct IllegalMutate { diff --git a/raphtory/src/core/utils.rs b/raphtory/src/core/utils/hashing.rs similarity index 94% rename from raphtory/src/core/utils.rs rename to raphtory/src/core/utils/hashing.rs index 10e5873c20..36166db0a1 100644 --- a/raphtory/src/core/utils.rs +++ b/raphtory/src/core/utils/hashing.rs @@ -1,7 +1,8 @@ +#![allow(dead_code)] + //! Utility functions used throughout the modules. use std::hash::{Hash, Hasher}; - use twox_hash::XxHash64; pub fn calculate_hash(t: &T) -> u64 { diff --git a/raphtory/src/core/utils/mod.rs b/raphtory/src/core/utils/mod.rs new file mode 100644 index 0000000000..7c640621d9 --- /dev/null +++ b/raphtory/src/core/utils/mod.rs @@ -0,0 +1,3 @@ +pub mod errors; +pub mod hashing; +pub mod time; diff --git a/raphtory/src/core/time.rs b/raphtory/src/core/utils/time.rs similarity index 98% rename from raphtory/src/core/time.rs rename to raphtory/src/core/utils/time.rs index 9e16ef7ea9..a16f1ea6fd 100644 --- a/raphtory/src/core/time.rs +++ b/raphtory/src/core/utils/time.rs @@ -1,6 +1,5 @@ -use crate::core::time::error::*; -use chrono::NaiveDate; -use chrono::{DateTime, Duration, Months, NaiveDateTime, TimeZone}; +use crate::core::utils::time::error::*; +use chrono::{DateTime, Duration, Months, NaiveDate, NaiveDateTime, TimeZone}; use itertools::{Either, Itertools}; use regex::Regex; use std::ops::{Add, Sub}; @@ -283,7 +282,7 @@ impl Add for i64 { #[cfg(test)] mod time_tests { - use crate::core::time::{Interval, ParseTimeError, TryIntoTime}; + use crate::core::utils::time::{Interval, ParseTimeError, TryIntoTime}; #[test] fn interval_parsing() { diff --git a/raphtory/src/db/api/mod.rs b/raphtory/src/db/api/mod.rs new file mode 100644 index 0000000000..08e724b2bd --- /dev/null +++ b/raphtory/src/db/api/mod.rs @@ -0,0 +1,2 @@ +pub mod mutation; +pub mod view; diff --git a/raphtory/src/db/mutation_api/addition_ops.rs b/raphtory/src/db/api/mutation/addition_ops.rs similarity index 92% rename from raphtory/src/db/mutation_api/addition_ops.rs rename to raphtory/src/db/api/mutation/addition_ops.rs index 0fb97b1404..114600dc5c 100644 --- a/raphtory/src/db/mutation_api/addition_ops.rs +++ b/raphtory/src/db/api/mutation/addition_ops.rs @@ -1,8 +1,13 @@ -use crate::core::errors::GraphError; -use crate::core::time::{IntoTimeWithFormat, TryIntoTime}; -use crate::core::vertex::InputVertex; -use crate::db::mutation_api::internal::InternalAdditionOps; -use crate::db::mutation_api::Properties; +use crate::{ + core::{ + entities::vertices::input_vertex::InputVertex, + utils::{ + errors::GraphError, + time::{IntoTimeWithFormat, TryIntoTime}, + }, + }, + db::api::mutation::{internal::InternalAdditionOps, Properties}, +}; pub trait AdditionOps { // TODO: Probably add vector reference here like add diff --git a/raphtory/src/db/mutation_api/deletion_ops.rs b/raphtory/src/db/api/mutation/deletion_ops.rs similarity index 76% rename from raphtory/src/db/mutation_api/deletion_ops.rs rename to raphtory/src/db/api/mutation/deletion_ops.rs index c9beecfd0a..7c591d5e27 100644 --- a/raphtory/src/db/mutation_api/deletion_ops.rs +++ b/raphtory/src/db/api/mutation/deletion_ops.rs @@ -1,7 +1,13 @@ -use crate::core::errors::GraphError; -use crate::core::time::{IntoTimeWithFormat, TryIntoTime}; -use crate::core::vertex::InputVertex; -use crate::db::mutation_api::internal::InternalDeletionOps; +use crate::{ + core::{ + entities::vertices::input_vertex::InputVertex, + utils::{ + errors::GraphError, + time::{IntoTimeWithFormat, TryIntoTime}, + }, + }, + db::api::mutation::internal::InternalDeletionOps, +}; pub trait DeletionOps { fn delete_edge( diff --git a/raphtory/src/db/mutation_api/internal/internal_addition_ops.rs b/raphtory/src/db/api/mutation/internal/internal_addition_ops.rs similarity index 93% rename from raphtory/src/db/mutation_api/internal/internal_addition_ops.rs rename to raphtory/src/db/api/mutation/internal/internal_addition_ops.rs index d3b977b208..573516374f 100644 --- a/raphtory/src/db/mutation_api/internal/internal_addition_ops.rs +++ b/raphtory/src/db/api/mutation/internal/internal_addition_ops.rs @@ -1,6 +1,7 @@ -use crate::core::errors::GraphError; -use crate::core::Prop; -use crate::db::view_api::internal::Base; +use crate::{ + core::{utils::errors::GraphError, Prop}, + db::api::view::internal::Base, +}; pub trait InternalAdditionOps { fn internal_add_vertex( diff --git a/raphtory/src/db/mutation_api/internal/internal_deletion_ops.rs b/raphtory/src/db/api/mutation/internal/internal_deletion_ops.rs similarity index 91% rename from raphtory/src/db/mutation_api/internal/internal_deletion_ops.rs rename to raphtory/src/db/api/mutation/internal/internal_deletion_ops.rs index 51b39f08e9..49eaff1d76 100644 --- a/raphtory/src/db/mutation_api/internal/internal_deletion_ops.rs +++ b/raphtory/src/db/api/mutation/internal/internal_deletion_ops.rs @@ -1,5 +1,4 @@ -use crate::core::errors::GraphError; -use crate::db::view_api::internal::Base; +use crate::{core::utils::errors::GraphError, db::api::view::internal::Base}; pub trait InternalDeletionOps { fn internal_delete_edge( diff --git a/raphtory/src/db/mutation_api/internal/internal_property_additions_ops.rs b/raphtory/src/db/api/mutation/internal/internal_property_additions_ops.rs similarity index 95% rename from raphtory/src/db/mutation_api/internal/internal_property_additions_ops.rs rename to raphtory/src/db/api/mutation/internal/internal_property_additions_ops.rs index 52557e6caf..64538bbeb7 100644 --- a/raphtory/src/db/mutation_api/internal/internal_property_additions_ops.rs +++ b/raphtory/src/db/api/mutation/internal/internal_property_additions_ops.rs @@ -1,6 +1,7 @@ -use crate::core::errors::GraphError; -use crate::core::Prop; -use crate::db::view_api::internal::Base; +use crate::{ + core::{utils::errors::GraphError, Prop}, + db::api::view::internal::Base, +}; /// internal (dyn friendly) methods for adding properties pub trait InternalPropertyAdditionOps { diff --git a/raphtory/src/db/mutation_api/internal/mod.rs b/raphtory/src/db/api/mutation/internal/mod.rs similarity index 90% rename from raphtory/src/db/mutation_api/internal/mod.rs rename to raphtory/src/db/api/mutation/internal/mod.rs index 1f8500ab5e..f98fc537dd 100644 --- a/raphtory/src/db/mutation_api/internal/mod.rs +++ b/raphtory/src/db/api/mutation/internal/mod.rs @@ -2,7 +2,7 @@ mod internal_addition_ops; mod internal_deletion_ops; mod internal_property_additions_ops; -use crate::db::view_api::internal::Base; +use crate::db::api::view::internal::Base; pub use internal_addition_ops::*; pub use internal_deletion_ops::*; pub use internal_property_additions_ops::*; diff --git a/raphtory/src/db/mutation_api/mod.rs b/raphtory/src/db/api/mutation/mod.rs similarity index 100% rename from raphtory/src/db/mutation_api/mod.rs rename to raphtory/src/db/api/mutation/mod.rs diff --git a/raphtory/src/db/mutation_api/property_addition_ops.rs b/raphtory/src/db/api/mutation/property_addition_ops.rs similarity index 93% rename from raphtory/src/db/mutation_api/property_addition_ops.rs rename to raphtory/src/db/api/mutation/property_addition_ops.rs index 2e7362a25d..9271a81340 100644 --- a/raphtory/src/db/mutation_api/property_addition_ops.rs +++ b/raphtory/src/db/api/mutation/property_addition_ops.rs @@ -1,8 +1,10 @@ -use crate::core::errors::GraphError; -use crate::core::time::TryIntoTime; -use crate::core::vertex::InputVertex; -use crate::db::mutation_api::internal::InternalPropertyAdditionOps; -use crate::db::mutation_api::Properties; +use crate::{ + core::{ + entities::vertices::input_vertex::InputVertex, + utils::{errors::GraphError, time::TryIntoTime}, + }, + db::api::mutation::{internal::InternalPropertyAdditionOps, Properties}, +}; pub trait PropertyAdditionOps { /// Adds properties to the given input vertex. diff --git a/raphtory/src/db/view_api/edge.rs b/raphtory/src/db/api/view/edge.rs similarity index 97% rename from raphtory/src/db/view_api/edge.rs rename to raphtory/src/db/api/view/edge.rs index f9b66e7302..a99aeba8e5 100644 --- a/raphtory/src/db/view_api/edge.rs +++ b/raphtory/src/db/api/view/edge.rs @@ -1,8 +1,10 @@ -use crate::core::edge_ref::EdgeRef; -use crate::core::vertex_ref::VertexRef; -use crate::core::Prop; -use crate::db::view_api::internal::*; -use crate::db::view_api::*; +use crate::{ + core::{ + entities::{edges::edge_ref::EdgeRef, vertices::vertex_ref::VertexRef}, + Prop, + }, + db::api::view::{internal::*, *}, +}; use std::collections::HashMap; pub trait EdgeViewInternalOps> { diff --git a/raphtory/src/db/view_api/graph.rs b/raphtory/src/db/api/view/graph.rs similarity index 94% rename from raphtory/src/db/view_api/graph.rs rename to raphtory/src/db/api/view/graph.rs index d7fcb8a95f..5584ff9f6d 100644 --- a/raphtory/src/db/view_api/graph.rs +++ b/raphtory/src/db/api/view/graph.rs @@ -1,24 +1,29 @@ -use crate::core::errors::GraphError; -use crate::core::tgraph::tgraph::InnerTemporalGraph; -use crate::core::tgraph::VID; -use crate::core::Prop; +use crate::{ + core::{ + entities::{graph::tgraph::InnerTemporalGraph, vertices::vertex_ref::VertexRef, VID}, + utils::{errors::GraphError, time::IntoTime}, + Prop, + }, + db::{ + api::{ + mutation::{AdditionOps, PropertyAdditionOps}, + view::{internal::*, layer::LayerOps, *}, + }, + graph::{ + edge::EdgeView, + vertex::VertexView, + vertices::Vertices, + views::{ + layer_graph::LayeredGraph, vertex_subgraph::VertexSubgraph, + window_graph::WindowedGraph, + }, + }, + }, +}; use itertools::Itertools; use rustc_hash::FxHashSet; use std::collections::HashMap; -use crate::core::time::IntoTime; -use crate::core::vertex_ref::VertexRef; -use crate::db::edge::EdgeView; -use crate::db::graph_layer::LayeredGraph; -use crate::db::graph_window::WindowedGraph; -use crate::db::mutation_api::{AdditionOps, PropertyAdditionOps}; -use crate::db::subgraph_vertex::VertexSubgraph; -use crate::db::vertex::VertexView; -use crate::db::vertices::Vertices; -use crate::db::view_api::internal::*; -use crate::db::view_api::layer::LayerOps; -use crate::db::view_api::*; - /// This trait GraphViewOps defines operations for accessing /// information about a graph. The trait has associated types /// that are used to define the type of the vertices, edges diff --git a/raphtory/src/db/view_api/internal/core_deletion_ops.rs b/raphtory/src/db/api/view/internal/core_deletion_ops.rs similarity index 82% rename from raphtory/src/db/view_api/internal/core_deletion_ops.rs rename to raphtory/src/db/api/view/internal/core_deletion_ops.rs index 998fce8bd2..977b0ef76d 100644 --- a/raphtory/src/db/view_api/internal/core_deletion_ops.rs +++ b/raphtory/src/db/api/view/internal/core_deletion_ops.rs @@ -1,7 +1,10 @@ -use crate::core::edge_ref::EdgeRef; -use crate::core::locked_view::LockedView; -use crate::core::timeindex::TimeIndex; -use crate::db::view_api::internal::Base; +use crate::{ + core::{ + entities::edges::edge_ref::EdgeRef, + storage::{locked_view::LockedView, timeindex::TimeIndex}, + }, + db::api::view::internal::Base, +}; pub trait CoreDeletionOps { /// Get all the deletion timestamps for an edge diff --git a/raphtory/src/db/view_api/internal/core_ops.rs b/raphtory/src/db/api/view/internal/core_ops.rs similarity index 96% rename from raphtory/src/db/view_api/internal/core_ops.rs rename to raphtory/src/db/api/view/internal/core_ops.rs index a573c40847..6151b100c9 100644 --- a/raphtory/src/db/view_api/internal/core_ops.rs +++ b/raphtory/src/db/api/view/internal/core_ops.rs @@ -1,11 +1,14 @@ -use crate::core::edge_ref::EdgeRef; -use crate::core::locked_view::LockedView; -use crate::core::tgraph::VID; -use crate::core::timeindex::TimeIndex; -use crate::core::tprop::TProp; -use crate::core::vertex_ref::VertexRef; -use crate::core::Prop; -use crate::db::view_api::internal::Base; +use crate::{ + core::{ + entities::{ + edges::edge_ref::EdgeRef, properties::tprop::TProp, vertices::vertex_ref::VertexRef, + VID, + }, + storage::{locked_view::LockedView, timeindex::TimeIndex}, + Prop, + }, + db::api::view::internal::Base, +}; /// Core functions that should (almost-)always be implemented by pointing at the underlying graph. pub trait CoreGraphOps { diff --git a/raphtory/src/db/view_api/internal/exploded_edge_ops.rs b/raphtory/src/db/api/view/internal/exploded_edge_ops.rs similarity index 92% rename from raphtory/src/db/view_api/internal/exploded_edge_ops.rs rename to raphtory/src/db/api/view/internal/exploded_edge_ops.rs index 25b92b93ef..bd2b4b002d 100644 --- a/raphtory/src/db/view_api/internal/exploded_edge_ops.rs +++ b/raphtory/src/db/api/view/internal/exploded_edge_ops.rs @@ -1,9 +1,13 @@ -use crate::core::edge_ref::EdgeRef; -use crate::core::tgraph::VID; -use crate::core::Direction; -use crate::db::view_api::internal::time_semantics::TimeSemantics; -use crate::db::view_api::internal::GraphOps; -use crate::db::view_api::BoxedIter; +use crate::{ + core::{ + entities::{edges::edge_ref::EdgeRef, VID}, + Direction, + }, + db::api::view::{ + internal::{time_semantics::TimeSemantics, GraphOps}, + BoxedIter, + }, +}; use std::ops::Range; /// Additional methods for returning exploded edge data that are automatically implemented diff --git a/raphtory/src/db/view_api/internal/graph_ops.rs b/raphtory/src/db/api/view/internal/graph_ops.rs similarity index 97% rename from raphtory/src/db/view_api/internal/graph_ops.rs rename to raphtory/src/db/api/view/internal/graph_ops.rs index 41d67dbe24..e2777a1ab5 100644 --- a/raphtory/src/db/view_api/internal/graph_ops.rs +++ b/raphtory/src/db/api/view/internal/graph_ops.rs @@ -1,8 +1,10 @@ -use crate::core::edge_ref::EdgeRef; -use crate::core::tgraph::VID; -use crate::core::vertex_ref::VertexRef; -use crate::core::Direction; -use crate::db::view_api::internal::Base; +use crate::{ + core::{ + entities::{edges::edge_ref::EdgeRef, vertices::vertex_ref::VertexRef, VID}, + Direction, + }, + db::api::view::internal::Base, +}; /// The GraphViewInternalOps trait provides a set of methods to query a directed graph /// represented by the raphtory_core::tgraph::TGraph struct. diff --git a/raphtory/src/db/view_api/internal/graph_properties_ops.rs b/raphtory/src/db/api/view/internal/graph_properties_ops.rs similarity index 96% rename from raphtory/src/db/view_api/internal/graph_properties_ops.rs rename to raphtory/src/db/api/view/internal/graph_properties_ops.rs index 7e574cde80..f4bd26ffec 100644 --- a/raphtory/src/db/view_api/internal/graph_properties_ops.rs +++ b/raphtory/src/db/api/view/internal/graph_properties_ops.rs @@ -1,8 +1,10 @@ -use crate::core::edge_ref::EdgeRef; -use crate::core::tgraph::VID; -use crate::core::Prop; -use crate::db::view_api::internal::time_semantics::TimeSemantics; -use crate::db::view_api::internal::CoreGraphOps; +use crate::{ + core::{ + entities::{edges::edge_ref::EdgeRef, VID}, + Prop, + }, + db::api::view::internal::{time_semantics::TimeSemantics, CoreGraphOps}, +}; use std::collections::HashMap; /// Additional methods for retrieving properties that are automatically implemented diff --git a/raphtory/src/db/view_api/internal/graph_window_ops.rs b/raphtory/src/db/api/view/internal/graph_window_ops.rs similarity index 97% rename from raphtory/src/db/view_api/internal/graph_window_ops.rs rename to raphtory/src/db/api/view/internal/graph_window_ops.rs index d55e4f3d9f..4c5bb01cb6 100644 --- a/raphtory/src/db/view_api/internal/graph_window_ops.rs +++ b/raphtory/src/db/api/view/internal/graph_window_ops.rs @@ -1,9 +1,10 @@ -use crate::core::edge_ref::EdgeRef; -use crate::core::tgraph::VID; -use crate::core::vertex_ref::VertexRef; -use crate::core::Direction; -use crate::db::view_api::internal::time_semantics::TimeSemantics; -use crate::db::view_api::internal::{CoreGraphOps, GraphOps}; +use crate::{ + core::{ + entities::{edges::edge_ref::EdgeRef, vertices::vertex_ref::VertexRef, VID}, + Direction, + }, + db::api::view::internal::{time_semantics::TimeSemantics, CoreGraphOps, GraphOps}, +}; use itertools::*; /// Methods for interacting with windowed data (automatically implemented based on `TimeSemantics` trait diff --git a/raphtory/src/db/view_api/internal/inherit.rs b/raphtory/src/db/api/view/internal/inherit.rs similarity index 100% rename from raphtory/src/db/view_api/internal/inherit.rs rename to raphtory/src/db/api/view/internal/inherit.rs diff --git a/raphtory/src/db/api/view/internal/into_dynamic.rs b/raphtory/src/db/api/view/internal/into_dynamic.rs new file mode 100644 index 0000000000..e4198b0fda --- /dev/null +++ b/raphtory/src/db/api/view/internal/into_dynamic.rs @@ -0,0 +1,34 @@ +use crate::db::{ + api::view::{internal::DynamicGraph, GraphViewOps}, + graph::views::{ + layer_graph::LayeredGraph, vertex_subgraph::VertexSubgraph, window_graph::WindowedGraph, + }, +}; + +pub trait IntoDynamic { + fn into_dynamic(self) -> DynamicGraph; +} + +impl IntoDynamic for WindowedGraph { + fn into_dynamic(self) -> DynamicGraph { + DynamicGraph::new(self) + } +} + +impl IntoDynamic for LayeredGraph { + fn into_dynamic(self) -> DynamicGraph { + DynamicGraph::new(self) + } +} + +impl IntoDynamic for DynamicGraph { + fn into_dynamic(self) -> DynamicGraph { + self + } +} + +impl IntoDynamic for VertexSubgraph { + fn into_dynamic(self) -> DynamicGraph { + DynamicGraph::new(self) + } +} diff --git a/raphtory/src/db/view_api/internal/materialize.rs b/raphtory/src/db/api/view/internal/materialize.rs similarity index 86% rename from raphtory/src/db/view_api/internal/materialize.rs rename to raphtory/src/db/api/view/internal/materialize.rs index c44bbdac59..a605b66724 100644 --- a/raphtory/src/db/view_api/internal/materialize.rs +++ b/raphtory/src/db/api/view/internal/materialize.rs @@ -1,6 +1,10 @@ -use crate::db::graph::{Graph, InternalGraph}; -use crate::db::graph_deletions::GraphWithDeletions; -use crate::db::view_api::internal::Base; +use crate::db::{ + api::view::internal::Base, + graph::{ + graph::{Graph, InternalGraph}, + views::deletion_graph::GraphWithDeletions, + }, +}; pub enum MaterializedGraph { EventGraph(Graph), diff --git a/raphtory/src/db/view_api/internal/mod.rs b/raphtory/src/db/api/view/internal/mod.rs similarity index 92% rename from raphtory/src/db/view_api/internal/mod.rs rename to raphtory/src/db/api/view/internal/mod.rs index 0b6205d4ad..e68ff29a95 100644 --- a/raphtory/src/db/view_api/internal/mod.rs +++ b/raphtory/src/db/api/view/internal/mod.rs @@ -75,10 +75,13 @@ impl InheritViewOps for DynamicGraph {} #[cfg(test)] mod test { - use crate::db::graph::Graph; - use crate::db::mutation_api::AdditionOps; - use crate::db::view_api::internal::BoxableGraphView; - use crate::db::view_api::*; + use crate::db::{ + api::{ + mutation::AdditionOps, + view::{internal::BoxableGraphView, *}, + }, + graph::graph::Graph, + }; use itertools::Itertools; use std::sync::Arc; diff --git a/raphtory/src/db/view_api/internal/time_semantics.rs b/raphtory/src/db/api/view/internal/time_semantics.rs similarity index 98% rename from raphtory/src/db/view_api/internal/time_semantics.rs rename to raphtory/src/db/api/view/internal/time_semantics.rs index 62d602381f..7f261a6912 100644 --- a/raphtory/src/db/view_api/internal/time_semantics.rs +++ b/raphtory/src/db/api/view/internal/time_semantics.rs @@ -1,10 +1,14 @@ -use crate::core::edge_ref::EdgeRef; -use crate::core::tgraph::VID; -use crate::core::timeindex::TimeIndexOps; -use crate::core::Prop; -use crate::db::view_api::internal::{Base, CoreGraphOps, GraphOps}; -use crate::db::view_api::BoxedIter; - +use crate::{ + core::{ + entities::{edges::edge_ref::EdgeRef, VID}, + storage::timeindex::TimeIndexOps, + Prop, + }, + db::api::view::{ + internal::{Base, CoreGraphOps, GraphOps}, + BoxedIter, + }, +}; use std::ops::Range; /// Methods for defining time windowing semantics for a graph diff --git a/raphtory/src/db/view_api/internal/wrapped_graph.rs b/raphtory/src/db/api/view/internal/wrapped_graph.rs similarity index 74% rename from raphtory/src/db/view_api/internal/wrapped_graph.rs rename to raphtory/src/db/api/view/internal/wrapped_graph.rs index 608e8ed6fd..0d9721eb0e 100644 --- a/raphtory/src/db/view_api/internal/wrapped_graph.rs +++ b/raphtory/src/db/api/view/internal/wrapped_graph.rs @@ -1,4 +1,4 @@ -use crate::db::view_api::internal::{Base, BoxableGraphView, InheritViewOps}; +use crate::db::api::view::internal::{Base, BoxableGraphView, InheritViewOps}; use std::sync::Arc; impl Base for Arc { diff --git a/raphtory/src/db/view_api/layer.rs b/raphtory/src/db/api/view/layer.rs similarity index 100% rename from raphtory/src/db/view_api/layer.rs rename to raphtory/src/db/api/view/layer.rs diff --git a/raphtory/src/db/view_api/mod.rs b/raphtory/src/db/api/view/mod.rs similarity index 94% rename from raphtory/src/db/view_api/mod.rs rename to raphtory/src/db/api/view/mod.rs index 3d43e35b5c..6be1d0f853 100644 --- a/raphtory/src/db/view_api/mod.rs +++ b/raphtory/src/db/api/view/mod.rs @@ -12,6 +12,5 @@ pub use graph::*; pub use layer::*; pub use time::*; pub use vertex::*; -pub use vertex::*; pub type BoxedIter = Box + Send>; diff --git a/raphtory/src/db/view_api/time.rs b/raphtory/src/db/api/view/time.rs similarity index 96% rename from raphtory/src/db/view_api/time.rs rename to raphtory/src/db/api/view/time.rs index 3ce26e4e84..bbd0b31040 100644 --- a/raphtory/src/db/view_api/time.rs +++ b/raphtory/src/db/api/view/time.rs @@ -1,5 +1,4 @@ -use crate::core::time::error::ParseTimeError; -use crate::core::time::{Interval, IntoTime}; +use crate::core::utils::time::{error::ParseTimeError, Interval, IntoTime}; /// Trait defining time query operations pub trait TimeOps { @@ -159,11 +158,16 @@ impl Iterator for WindowSet { #[cfg(test)] mod time_tests { - use crate::core::time::TryIntoTime; - use crate::db::graph::Graph; - use crate::db::mutation_api::AdditionOps; - use crate::db::view_api::time::WindowSet; - use crate::db::view_api::{GraphViewOps, TimeOps}; + use crate::{ + core::utils::time::TryIntoTime, + db::{ + api::{ + mutation::AdditionOps, + view::{time::WindowSet, GraphViewOps, TimeOps}, + }, + graph::graph::Graph, + }, + }; use itertools::Itertools; // start inclusive, end exclusive diff --git a/raphtory/src/db/view_api/vertex.rs b/raphtory/src/db/api/view/vertex.rs similarity index 98% rename from raphtory/src/db/view_api/vertex.rs rename to raphtory/src/db/api/view/vertex.rs index 734813ec7f..fa08469ab5 100644 --- a/raphtory/src/db/view_api/vertex.rs +++ b/raphtory/src/db/api/view/vertex.rs @@ -1,6 +1,7 @@ -use crate::core::Prop; -use crate::db::view_api::edge::EdgeListOps; -use crate::db::view_api::{GraphViewOps, TimeOps}; +use crate::{ + core::Prop, + db::api::view::{edge::EdgeListOps, GraphViewOps, TimeOps}, +}; use std::collections::HashMap; /// Operations defined for a vertex diff --git a/raphtory/src/db/edge.rs b/raphtory/src/db/graph/edge.rs similarity index 95% rename from raphtory/src/db/edge.rs rename to raphtory/src/db/graph/edge.rs index 82838d2aa0..d22ffdb935 100644 --- a/raphtory/src/db/edge.rs +++ b/raphtory/src/db/graph/edge.rs @@ -5,16 +5,22 @@ //! and can have properties associated with them. //! -use crate::core::edge_ref::EdgeRef; -use crate::core::time::IntoTime; -use crate::core::vertex_ref::VertexRef; -use crate::core::Prop; -use crate::db::graph_window::WindowedGraph; -use crate::db::vertex::VertexView; -use crate::db::view_api::*; -use std::collections::HashMap; -use std::fmt::{Debug, Formatter}; -use std::iter; +use crate::{ + core::{ + entities::{edges::edge_ref::EdgeRef, vertices::vertex_ref::VertexRef}, + utils::time::IntoTime, + }, + db::{ + api::view::{BoxedIter, EdgeViewInternalOps}, + graph::{vertex::VertexView, views::window_graph::WindowedGraph}, + }, + prelude::*, +}; +use std::{ + collections::HashMap, + fmt::{Debug, Formatter}, + iter, +}; /// A view of an edge in the graph. #[derive(Clone)] diff --git a/raphtory/src/db/graph.rs b/raphtory/src/db/graph/graph.rs similarity index 97% rename from raphtory/src/db/graph.rs rename to raphtory/src/db/graph/graph.rs index 726bd431c6..eef4bb36d5 100644 --- a/raphtory/src/db/graph.rs +++ b/raphtory/src/db/graph/graph.rs @@ -7,9 +7,7 @@ //! # Examples //! //! ```rust -//! use raphtory::db::view_api::*; -//! use raphtory::db::graph::Graph; -//! use raphtory::db::mutation_api::AdditionOps; +//! use raphtory::prelude::*; //! let graph = Graph::new(); //! graph.add_vertex(0, "Alice", vec![]).unwrap(); //! graph.add_vertex(1, "Bob", vec![]).unwrap(); @@ -18,16 +16,20 @@ //! ``` //! -use crate::core::errors::GraphError; -use crate::core::tgraph::tgraph::InnerTemporalGraph; -use crate::prelude::{EdgeListOps, EdgeViewOps, GraphViewOps, VertexViewOps}; - +use crate::{ + core::{entities::graph::tgraph::InnerTemporalGraph, utils::errors::GraphError}, + db::api::{ + mutation::internal::{InheritAdditionOps, InheritPropertyAdditionOps}, + view::internal::{Base, DynamicGraph, InheritViewOps, IntoDynamic}, + }, + prelude::*, +}; use serde::{Deserialize, Serialize}; -use std::fmt::{Display, Formatter}; -use std::{path::Path, sync::Arc}; - -use super::mutation_api::internal::{InheritAdditionOps, InheritPropertyAdditionOps}; -use super::view_api::internal::{Base, DynamicGraph, InheritViewOps, IntoDynamic}; +use std::{ + fmt::{Display, Formatter}, + path::Path, + sync::Arc, +}; const SEG: usize = 16; pub(crate) type InternalGraph = InnerTemporalGraph; @@ -95,7 +97,7 @@ impl Graph { /// # Example /// /// ``` - /// use raphtory::db::graph::Graph; + /// use raphtory::prelude::Graph; /// let g = Graph::new(); /// ``` pub fn new() -> Self { @@ -119,7 +121,7 @@ impl Graph { /// # Example /// /// ```no_run - /// use raphtory::db::graph::Graph; + /// use raphtory::prelude::Graph; /// let g = Graph::load_from_file("path/to/graph"); /// ``` pub fn load_from_file>(path: P) -> Result { @@ -146,19 +148,22 @@ impl IntoDynamic for Graph { #[cfg(test)] mod db_tests { use super::*; - use crate::core::edge_ref::EdgeRef; - use crate::core::errors::GraphError; - use crate::core::time::error::ParseTimeError; - use crate::core::time::TryIntoTime; - use crate::core::vertex_ref::VertexRef; - use crate::core::{Direction, Prop}; - use crate::db::edge::EdgeView; - use crate::db::path::PathFromVertex; - use crate::db::view_api::{ - internal::*, EdgeListOps, EdgeViewOps, GraphViewOps, LayerOps, TimeOps, VertexViewOps, + use crate::{ + core::{ + entities::{edges::edge_ref::EdgeRef, vertices::vertex_ref::VertexRef}, + utils::time::{error::ParseTimeError, TryIntoTime}, + Direction, Prop, + }, + db::{ + api::view::{ + internal::*, EdgeListOps, EdgeViewOps, GraphViewOps, LayerOps, TimeOps, + VertexViewOps, + }, + graph::{edge::EdgeView, path::PathFromVertex}, + }, + graphgen::random_attachment::random_attachment, + prelude::{AdditionOps, PropertyAdditionOps}, }; - use crate::graphgen::random_attachment::random_attachment; - use crate::prelude::{AdditionOps, PropertyAdditionOps}; use chrono::NaiveDateTime; use itertools::Itertools; use quickcheck::Arbitrary; diff --git a/raphtory/src/db/graph/mod.rs b/raphtory/src/db/graph/mod.rs new file mode 100644 index 0000000000..0c529d4c55 --- /dev/null +++ b/raphtory/src/db/graph/mod.rs @@ -0,0 +1,6 @@ +pub mod edge; +pub mod graph; +pub mod path; +pub mod vertex; +pub mod vertices; +pub mod views; diff --git a/raphtory/src/db/path.rs b/raphtory/src/db/graph/path.rs similarity index 95% rename from raphtory/src/db/path.rs rename to raphtory/src/db/graph/path.rs index d6c29469e1..cd6816987f 100644 --- a/raphtory/src/db/path.rs +++ b/raphtory/src/db/graph/path.rs @@ -1,16 +1,20 @@ -use crate::core::tgraph::VID; -use crate::core::time::IntoTime; -use crate::core::vertex_ref::VertexRef; -use crate::core::{Direction, Prop}; -use crate::db::edge::EdgeView; -use crate::db::graph_layer::LayeredGraph; -use crate::db::graph_window::WindowedGraph; -use crate::db::vertex::VertexView; -use crate::db::view_api::internal::GraphWindowOps; -use crate::db::view_api::*; -use std::collections::HashMap; -use std::iter; -use std::sync::Arc; +use crate::{ + core::{ + entities::{vertices::vertex_ref::VertexRef, VID}, + utils::time::IntoTime, + Direction, + }, + db::{ + api::view::{internal::GraphWindowOps, BoxedIter, LayerOps}, + graph::{ + edge::EdgeView, + vertex::VertexView, + views::{layer_graph::LayeredGraph, window_graph::WindowedGraph}, + }, + }, + prelude::*, +}; +use std::{collections::HashMap, iter, sync::Arc}; #[derive(Copy, Clone)] pub enum Operations { @@ -58,7 +62,7 @@ pub struct PathFromGraph { } impl PathFromGraph { - pub(crate) fn new(graph: G, operation: Operations) -> PathFromGraph { + pub fn new(graph: G, operation: Operations) -> PathFromGraph { PathFromGraph { graph, operations: Arc::new(vec![operation]), @@ -304,7 +308,7 @@ impl PathFromVertex { Box::new(iter) } - pub(crate) fn new>( + pub fn new>( graph: G, vertex: V, operation: Operations, @@ -317,7 +321,7 @@ impl PathFromVertex { } } - pub(crate) fn neighbours_window(&self, dir: Direction, t_start: i64, t_end: i64) -> Self { + pub fn neighbours_window(&self, dir: Direction, t_start: i64, t_end: i64) -> Self { let mut new_ops = (*self.operations).clone(); new_ops.push(Operations::NeighboursWindow { dir, diff --git a/raphtory/src/db/vertex.rs b/raphtory/src/db/graph/vertex.rs similarity index 95% rename from raphtory/src/db/vertex.rs rename to raphtory/src/db/graph/vertex.rs index b57c92ae86..d5352be13a 100644 --- a/raphtory/src/db/vertex.rs +++ b/raphtory/src/db/graph/vertex.rs @@ -1,15 +1,21 @@ //! Defines the `Vertex` struct, which represents a vertex in the graph. -use crate::core::tgraph::VID; -use crate::core::time::IntoTime; -use crate::core::vertex_ref::VertexRef; -use crate::core::{Direction, Prop}; -use crate::db::edge::{EdgeList, EdgeView}; -use crate::db::graph_layer::LayeredGraph; -use crate::db::graph_window::WindowedGraph; -use crate::db::path::{Operations, PathFromVertex}; -use crate::db::view_api::internal::GraphPropertiesOps; -use crate::db::view_api::*; +use crate::{ + core::{ + entities::{vertices::vertex_ref::VertexRef, VID}, + utils::time::IntoTime, + Direction, + }, + db::{ + api::view::{internal::GraphPropertiesOps, BoxedIter, LayerOps}, + graph::{ + edge::{EdgeList, EdgeView}, + path::{Operations, PathFromVertex}, + views::{layer_graph::LayeredGraph, window_graph::WindowedGraph}, + }, + }, + prelude::*, +}; use std::collections::HashMap; #[derive(Debug, Clone)] @@ -32,7 +38,7 @@ impl From<&VertexView> for VertexRef { impl VertexView { /// Creates a new `VertexView` wrapping a vertex reference and a graph, localising any remote vertices to the correct shard. - pub(crate) fn new(graph: G, vertex: VertexRef) -> VertexView { + pub fn new(graph: G, vertex: VertexRef) -> VertexView { match vertex { VertexRef::Local(local) => Self::new_local(graph, local), _ => { @@ -43,7 +49,7 @@ impl VertexView { } /// Creates a new `VertexView` wrapping a local vertex reference and a graph - pub(crate) fn new_local(graph: G, vertex: VID) -> VertexView { + pub fn new_local(graph: G, vertex: VID) -> VertexView { VertexView { graph, vertex } } } @@ -461,8 +467,6 @@ impl VertexListOps for BoxedIter>> { #[cfg(test)] mod vertex_test { - use crate::db::graph::Graph; - use crate::db::mutation_api::AdditionOps; use crate::prelude::*; use std::collections::HashMap; diff --git a/raphtory/src/db/vertices.rs b/raphtory/src/db/graph/vertices.rs similarity index 92% rename from raphtory/src/db/vertices.rs rename to raphtory/src/db/graph/vertices.rs index 2b7ec4c898..640cc23ad3 100644 --- a/raphtory/src/db/vertices.rs +++ b/raphtory/src/db/graph/vertices.rs @@ -1,12 +1,16 @@ -use crate::core::time::IntoTime; -use crate::core::vertex_ref::VertexRef; -use crate::core::{Direction, Prop}; -use crate::db::edge::EdgeView; -use crate::db::graph_layer::LayeredGraph; -use crate::db::graph_window::WindowedGraph; -use crate::db::path::{Operations, PathFromGraph}; -use crate::db::vertex::VertexView; -use crate::db::view_api::*; +use crate::{ + core::{entities::vertices::vertex_ref::VertexRef, utils::time::IntoTime, Direction}, + db::{ + api::view::{BoxedIter, LayerOps}, + graph::{ + edge::EdgeView, + path::{Operations, PathFromGraph}, + vertex::VertexView, + views::{layer_graph::LayeredGraph, window_graph::WindowedGraph}, + }, + }, + prelude::*, +}; use std::collections::HashMap; #[derive(Clone)] diff --git a/raphtory/src/db/graph_deletions.rs b/raphtory/src/db/graph/views/deletion_graph.rs similarity index 91% rename from raphtory/src/db/graph_deletions.rs rename to raphtory/src/db/graph/views/deletion_graph.rs index 4e6195b59d..1826607f97 100644 --- a/raphtory/src/db/graph_deletions.rs +++ b/raphtory/src/db/graph/views/deletion_graph.rs @@ -1,23 +1,27 @@ -use crate::core::edge_ref::EdgeRef; -use crate::core::errors::GraphError; -use crate::core::tgraph::VID; -use crate::core::timeindex::TimeIndexOps; -use crate::core::{Direction, Prop}; -use crate::db::mutation_api::internal::InheritMutationOps; -use crate::db::view_api::internal::{ - Base, CoreDeletionOps, CoreGraphOps, DynamicGraph, GraphOps, InheritCoreDeletionOps, - InheritCoreOps, InheritGraphOps, InternalMaterialize, IntoDynamic, MaterializedGraph, - TimeSemantics, +use crate::{ + core::{ + entities::{edges::edge_ref::EdgeRef, VID}, + storage::timeindex::TimeIndexOps, + utils::errors::GraphError, + Direction, Prop, + }, + db::{ + api::{ + mutation::internal::InheritMutationOps, + view::{internal::*, BoxedIter}, + }, + graph::graph::{graph_equal, InternalGraph}, + }, + prelude::*, +}; +use std::{ + cmp::min, + fmt::{Display, Formatter}, + iter, + ops::Range, + path::Path, + sync::Arc, }; -use crate::db::view_api::{BoxedIter, GraphViewOps}; -use std::cmp::min; -use std::fmt::{Display, Formatter}; -use std::iter; -use std::ops::Range; -use std::path::Path; -use std::sync::Arc; - -use super::graph::{graph_equal, InternalGraph}; #[derive(Clone, Debug)] pub struct GraphWithDeletions { @@ -79,9 +83,8 @@ impl GraphWithDeletions { /// # Example /// /// ```no_run - /// use raphtory::db::graph::Graph; /// use std::fs::File; - /// use raphtory::db::mutation_api::AdditionOps; + /// use raphtory::prelude::*; /// let g = Graph::new(); /// g.add_vertex(1, 1, []).unwrap(); /// g.save_to_file("path_str"); @@ -104,7 +107,7 @@ impl GraphWithDeletions { /// # Example /// /// ```no_run - /// use raphtory::db::graph::Graph; + /// use raphtory::prelude::*; /// let g = Graph::load_from_file("path/to/graph"); /// ``` pub fn load_from_file>(path: P) -> Result { @@ -333,10 +336,7 @@ impl TimeSemantics for GraphWithDeletions { #[cfg(test)] mod test_deletions { - use crate::core::{Prop, PropUnwrap}; - use crate::db::graph_deletions::GraphWithDeletions; - use crate::db::mutation_api::{AdditionOps, DeletionOps}; - use crate::db::view_api::*; + use crate::{db::graph::views::deletion_graph::GraphWithDeletions, prelude::*}; use itertools::Itertools; #[test] diff --git a/raphtory/src/db/graph_layer.rs b/raphtory/src/db/graph/views/layer_graph.rs similarity index 92% rename from raphtory/src/db/graph_layer.rs rename to raphtory/src/db/graph/views/layer_graph.rs index 3a496336a3..b80826145e 100644 --- a/raphtory/src/db/graph_layer.rs +++ b/raphtory/src/db/graph/views/layer_graph.rs @@ -1,11 +1,13 @@ -use crate::core::edge_ref::EdgeRef; -use crate::core::tgraph::VID; -use crate::core::vertex_ref::VertexRef; -use crate::core::Direction; -use crate::db::view_api::internal::{ - Base, GraphOps, InheritCoreOps, InheritMaterialize, InheritTimeSemantics, +use crate::{ + core::{ + entities::{edges::edge_ref::EdgeRef, vertices::vertex_ref::VertexRef, VID}, + Direction, + }, + db::api::view::internal::{ + Base, GraphOps, InheritCoreOps, InheritMaterialize, InheritTimeSemantics, + }, + prelude::GraphViewOps, }; -use crate::db::view_api::GraphViewOps; use itertools::Itertools; #[derive(Debug, Clone)] diff --git a/raphtory/src/db/graph/views/mod.rs b/raphtory/src/db/graph/views/mod.rs new file mode 100644 index 0000000000..099efc6951 --- /dev/null +++ b/raphtory/src/db/graph/views/mod.rs @@ -0,0 +1,4 @@ +pub mod deletion_graph; +pub mod layer_graph; +pub mod vertex_subgraph; +pub mod window_graph; diff --git a/raphtory/src/db/subgraph_vertex.rs b/raphtory/src/db/graph/views/vertex_subgraph.rs similarity index 88% rename from raphtory/src/db/subgraph_vertex.rs rename to raphtory/src/db/graph/views/vertex_subgraph.rs index aa18ac5b6d..7c0fea4ff7 100644 --- a/raphtory/src/db/subgraph_vertex.rs +++ b/raphtory/src/db/graph/views/vertex_subgraph.rs @@ -1,11 +1,13 @@ -use crate::core::edge_ref::EdgeRef; -use crate::core::tgraph::VID; -use crate::core::vertex_ref::VertexRef; -use crate::core::Direction; -use crate::db::view_api::internal::{ - Base, GraphOps, InheritCoreOps, InheritMaterialize, InheritTimeSemantics, +use crate::{ + core::{ + entities::{edges::edge_ref::EdgeRef, vertices::vertex_ref::VertexRef, VID}, + Direction, + }, + db::api::view::internal::{ + Base, GraphOps, InheritCoreOps, InheritMaterialize, InheritTimeSemantics, + }, + prelude::GraphViewOps, }; -use crate::db::view_api::GraphViewOps; use rustc_hash::FxHashSet; use std::sync::Arc; @@ -30,7 +32,7 @@ impl InheritTimeSemantics for VertexSubgraph {} impl InheritMaterialize for VertexSubgraph {} impl VertexSubgraph { - pub(crate) fn new(graph: G, vertices: FxHashSet) -> Self { + pub fn new(graph: G, vertices: FxHashSet) -> Self { Self { graph, vertices: Arc::new(vertices), @@ -130,9 +132,7 @@ impl GraphOps for VertexSubgraph { #[cfg(test)] mod subgraph_tests { - use crate::db::graph::Graph; - use crate::db::mutation_api::AdditionOps; - use crate::db::view_api::*; + use crate::prelude::*; #[test] fn test_materialize_no_edges() { diff --git a/raphtory/src/db/graph_window.rs b/raphtory/src/db/graph/views/window_graph.rs similarity index 96% rename from raphtory/src/db/graph_window.rs rename to raphtory/src/db/graph/views/window_graph.rs index f8958a17b4..780a6f9b31 100644 --- a/raphtory/src/db/graph_window.rs +++ b/raphtory/src/db/graph/views/window_graph.rs @@ -25,9 +25,8 @@ //! //! ```rust //! -//! use raphtory::db::graph::Graph; -//! use raphtory::db::mutation_api::AdditionOps; -//! use raphtory::db::view_api::*; +//! use raphtory::prelude::*; +//! use raphtory::db::api::view::*; //! //! let graph = Graph::new(); //! graph.add_edge(0, 1, 2, [], None).unwrap(); @@ -38,18 +37,24 @@ //! assert_eq!(wg.edge(1, 2, None).unwrap().src().id(), 1); //! ``` -use crate::core::edge_ref::EdgeRef; -use crate::core::tgraph::VID; -use crate::core::time::IntoTime; -use crate::core::vertex_ref::VertexRef; -use crate::core::{Direction, Prop}; -use crate::db::view_api::internal::time_semantics::TimeSemantics; -use crate::db::view_api::internal::{ - Base, GraphOps, GraphWindowOps, InheritCoreOps, InheritMaterialize, +use crate::{ + core::{ + entities::{edges::edge_ref::EdgeRef, vertices::vertex_ref::VertexRef, VID}, + utils::time::IntoTime, + Direction, Prop, + }, + db::api::view::{ + internal::{ + Base, GraphOps, GraphWindowOps, InheritCoreOps, InheritMaterialize, TimeSemantics, + }, + BoxedIter, + }, + prelude::GraphViewOps, +}; +use std::{ + cmp::{max, min}, + ops::Range, }; -use crate::db::view_api::{BoxedIter, GraphViewOps}; -use std::cmp::{max, min}; -use std::ops::Range; /// A struct that represents a windowed view of a `Graph`. #[derive(Debug, Clone)] @@ -413,9 +418,8 @@ impl GraphOps for WindowedGraph { /// # Examples /// /// ```rust -/// use raphtory::db::graph::Graph; -/// use raphtory::db::mutation_api::AdditionOps; -/// use raphtory::db::view_api::*; +/// use raphtory::db::api::view::*; +/// use raphtory::prelude::*; /// /// let graph = Graph::new(); /// graph.add_edge(0, 1, 2, [], None).unwrap(); @@ -457,10 +461,7 @@ impl WindowedGraph { mod views_test { use super::*; - use crate::core::Prop; - use crate::db::graph::Graph; - use crate::db::mutation_api::AdditionOps; - use crate::db::view_api::*; + use crate::prelude::*; use itertools::Itertools; use quickcheck::TestResult; use rand::prelude::*; diff --git a/raphtory/src/db/internal/addition.rs b/raphtory/src/db/internal/addition.rs index 7924c9aced..4060bcc4a3 100644 --- a/raphtory/src/db/internal/addition.rs +++ b/raphtory/src/db/internal/addition.rs @@ -1,6 +1,6 @@ use crate::{ - core::{errors::GraphError, tgraph::tgraph::InnerTemporalGraph}, - db::mutation_api::internal::InternalAdditionOps, + core::{entities::graph::tgraph::InnerTemporalGraph, utils::errors::GraphError}, + db::api::mutation::internal::InternalAdditionOps, prelude::Prop, }; diff --git a/raphtory/src/db/internal/core_ops.rs b/raphtory/src/db/internal/core_ops.rs index f866ee62a5..9f8831041e 100644 --- a/raphtory/src/db/internal/core_ops.rs +++ b/raphtory/src/db/internal/core_ops.rs @@ -1,13 +1,12 @@ use crate::{ core::{ - edge_ref::EdgeRef, - locked_view::LockedView, - tgraph::{tgraph::InnerTemporalGraph, VID}, - timeindex::TimeIndex, - tprop::TProp, - vertex_ref::VertexRef, + entities::{ + edges::edge_ref::EdgeRef, graph::tgraph::InnerTemporalGraph, properties::tprop::TProp, + vertices::vertex_ref::VertexRef, VID, + }, + storage::{locked_view::LockedView, timeindex::TimeIndex}, }, - db::view_api::internal::CoreGraphOps, + db::api::view::internal::CoreGraphOps, prelude::Prop, }; diff --git a/raphtory/src/db/internal/deletion.rs b/raphtory/src/db/internal/deletion.rs index a3ac6f0f41..44f9f06187 100644 --- a/raphtory/src/db/internal/deletion.rs +++ b/raphtory/src/db/internal/deletion.rs @@ -1,9 +1,10 @@ use crate::{ core::{ - edge_ref::EdgeRef, errors::GraphError, locked_view::LockedView, - tgraph::tgraph::InnerTemporalGraph, timeindex::TimeIndex, + entities::{edges::edge_ref::EdgeRef, graph::tgraph::InnerTemporalGraph}, + storage::{locked_view::LockedView, timeindex::TimeIndex}, + utils::errors::GraphError, }, - db::{mutation_api::internal::InternalDeletionOps, view_api::internal::CoreDeletionOps}, + db::api::{mutation::internal::InternalDeletionOps, view::internal::CoreDeletionOps}, }; impl InternalDeletionOps for InnerTemporalGraph { diff --git a/raphtory/src/db/internal/graph_ops.rs b/raphtory/src/db/internal/graph_ops.rs index 5b3a54a53e..160f3f689f 100644 --- a/raphtory/src/db/internal/graph_ops.rs +++ b/raphtory/src/db/internal/graph_ops.rs @@ -1,16 +1,15 @@ -use std::ops::Deref; - -use genawaiter::sync::GenBoxed; - use crate::{ core::{ - edge_ref::EdgeRef, - tgraph::{tgraph::InnerTemporalGraph, VID}, - vertex_ref::VertexRef, + entities::{ + edges::edge_ref::EdgeRef, graph::tgraph::InnerTemporalGraph, + vertices::vertex_ref::VertexRef, VID, + }, Direction, }, - db::view_api::internal::GraphOps, + db::api::view::internal::GraphOps, }; +use genawaiter::sync::GenBoxed; +use std::ops::Deref; impl GraphOps for InnerTemporalGraph { fn local_vertex_ref(&self, v: VertexRef) -> Option { diff --git a/raphtory/src/db/internal/materialize.rs b/raphtory/src/db/internal/materialize.rs index 4ac52ab560..3a1daa780c 100644 --- a/raphtory/src/db/internal/materialize.rs +++ b/raphtory/src/db/internal/materialize.rs @@ -1,9 +1,8 @@ use crate::{ - core::tgraph::tgraph::InnerTemporalGraph, - db::graph::Graph, + core::entities::graph::tgraph::InnerTemporalGraph, db::{ - graph::InternalGraph, - view_api::internal::{InternalMaterialize, MaterializedGraph}, + api::view::internal::{InternalMaterialize, MaterializedGraph}, + graph::graph::{Graph, InternalGraph}, }, }; use std::sync::Arc; diff --git a/raphtory/src/db/internal/prop_add.rs b/raphtory/src/db/internal/prop_add.rs index 7a8840faba..9fe3a05494 100644 --- a/raphtory/src/db/internal/prop_add.rs +++ b/raphtory/src/db/internal/prop_add.rs @@ -1,6 +1,6 @@ use crate::{ - core::{errors::GraphError, tgraph::tgraph::InnerTemporalGraph}, - db::mutation_api::internal::InternalPropertyAdditionOps, + core::{entities::graph::tgraph::InnerTemporalGraph, utils::errors::GraphError}, + db::api::mutation::internal::InternalPropertyAdditionOps, prelude::Prop, }; diff --git a/raphtory/src/db/internal/time_semantics.rs b/raphtory/src/db/internal/time_semantics.rs index 0f72ebbfa8..2b1f88e9c9 100644 --- a/raphtory/src/db/internal/time_semantics.rs +++ b/raphtory/src/db/internal/time_semantics.rs @@ -1,19 +1,16 @@ -use std::ops::Range; - -use genawaiter::sync::GenBoxed; - use crate::{ core::{ - edge_ref::EdgeRef, - tgraph::{tgraph::InnerTemporalGraph, VID}, - timeindex::TimeIndexOps, + entities::{edges::edge_ref::EdgeRef, graph::tgraph::InnerTemporalGraph, VID}, + storage::timeindex::TimeIndexOps, }, - db::view_api::{ + db::api::view::{ internal::{CoreDeletionOps, CoreGraphOps, TimeSemantics}, BoxedIter, }, prelude::Prop, }; +use genawaiter::sync::GenBoxed; +use std::ops::Range; impl TimeSemantics for InnerTemporalGraph { fn vertex_earliest_time(&self, v: VID) -> Option { diff --git a/raphtory/src/db/mod.rs b/raphtory/src/db/mod.rs index bae0b3c204..80ea7d70d2 100644 --- a/raphtory/src/db/mod.rs +++ b/raphtory/src/db/mod.rs @@ -1,14 +1,5 @@ -pub mod doc_strings; -pub mod edge; +pub mod api; pub mod graph; -pub mod graph_deletions; -pub mod graph_layer; -pub mod graph_window; pub(crate) mod internal; -pub mod mutation_api; -pub mod path; -pub mod subgraph_vertex; pub mod task; -pub mod vertex; -pub mod vertices; -pub mod view_api; +pub mod utils; diff --git a/raphtory/src/db/task/context.rs b/raphtory/src/db/task/context.rs index c45f5d1df3..cb7eac9b56 100644 --- a/raphtory/src/db/task/context.rs +++ b/raphtory/src/db/task/context.rs @@ -1,17 +1,12 @@ -use std::sync::Arc; - +use super::task_state::{Global, Shard}; use crate::{ - core::{ - state::agg::Accumulator, - state::{ - accumulator_id::AccId, compute_state::ComputeState, shuffle_state::ShuffleComputeState, - StateType, - }, + core::state::{ + accumulator_id::AccId, agg::Accumulator, compute_state::ComputeState, + shuffle_state::ShuffleComputeState, StateType, }, - db::view_api::GraphViewOps, + db::api::view::GraphViewOps, }; - -use super::task_state::{Global, Shard}; +use std::sync::Arc; type MergeFn = Arc, &ShuffleComputeState, usize) + Send + Sync>; diff --git a/raphtory/src/db/task/eval_edge.rs b/raphtory/src/db/task/edge/eval_edge.rs similarity index 92% rename from raphtory/src/db/task/eval_edge.rs rename to raphtory/src/db/task/edge/eval_edge.rs index 377393ce64..9151914f50 100644 --- a/raphtory/src/db/task/eval_edge.rs +++ b/raphtory/src/db/task/edge/eval_edge.rs @@ -1,17 +1,18 @@ -use crate::core::edge_ref::EdgeRef; -use crate::core::state::compute_state::ComputeState; -use crate::core::vertex_ref::VertexRef; -use crate::core::Prop; -use crate::db::task::eval_vertex::EvalVertexView; -use crate::db::view_api::*; -use std::cell::RefCell; -use std::collections::HashMap; -use std::iter; -use std::marker::PhantomData; -use std::rc::Rc; - -use super::eval_vertex_state::EVState; -use super::task_state::Local2; +use crate::{ + core::{ + entities::{edges::edge_ref::EdgeRef, vertices::vertex_ref::VertexRef}, + state::compute_state::ComputeState, + Prop, + }, + db::{ + api::view::*, + task::{ + task_state::Local2, + vertex::{eval_vertex::EvalVertexView, eval_vertex_state::EVState}, + }, + }, +}; +use std::{cell::RefCell, collections::HashMap, iter, marker::PhantomData, rc::Rc}; pub struct EvalEdgeView<'a, G: GraphViewOps, CS: ComputeState, S> { ss: usize, diff --git a/raphtory/src/db/task/edge/mod.rs b/raphtory/src/db/task/edge/mod.rs new file mode 100644 index 0000000000..4bb00ca1e8 --- /dev/null +++ b/raphtory/src/db/task/edge/mod.rs @@ -0,0 +1,2 @@ +pub mod eval_edge; +pub mod window_eval_edge; diff --git a/raphtory/src/db/task/window_eval_edge.rs b/raphtory/src/db/task/edge/window_eval_edge.rs similarity index 94% rename from raphtory/src/db/task/window_eval_edge.rs rename to raphtory/src/db/task/edge/window_eval_edge.rs index b0ed5b968a..9502eb5397 100644 --- a/raphtory/src/db/task/window_eval_edge.rs +++ b/raphtory/src/db/task/edge/window_eval_edge.rs @@ -1,12 +1,18 @@ -use std::{cell::RefCell, collections::HashMap, iter, marker::PhantomData, rc::Rc}; - -use crate::db::view_api::internal::*; use crate::{ - core::{edge_ref::EdgeRef, state::compute_state::ComputeState, Prop}, - db::view_api::*, + core::{ + entities::{edges::edge_ref::EdgeRef, vertices::vertex_ref::VertexRef}, + state::compute_state::ComputeState, + Prop, + }, + db::{ + api::view::{internal::*, *}, + task::{ + task_state::Local2, + vertex::{eval_vertex_state::EVState, window_eval_vertex::WindowEvalVertex}, + }, + }, }; - -use super::{eval_vertex_state::EVState, task_state::Local2, window_eval_vertex::WindowEvalVertex}; +use std::{cell::RefCell, collections::HashMap, iter, marker::PhantomData, rc::Rc}; pub struct WindowEvalEdgeView<'a, G: GraphViewOps, CS: ComputeState, S: 'static> { ss: usize, @@ -59,7 +65,7 @@ impl<'a, G: GraphViewOps, CS: ComputeState, S: 'static> self.ev.clone() } - fn new_vertex(&self, v: crate::core::vertex_ref::VertexRef) -> WindowEvalVertex<'a, G, CS, S> { + fn new_vertex(&self, v: VertexRef) -> WindowEvalVertex<'a, G, CS, S> { WindowEvalVertex::new( self.ss, self.g.localise_vertex_unchecked(v), diff --git a/raphtory/src/db/task/mod.rs b/raphtory/src/db/task/mod.rs index 8941e02e77..d0846ecc91 100644 --- a/raphtory/src/db/task/mod.rs +++ b/raphtory/src/db/task/mod.rs @@ -1,17 +1,13 @@ -use std::sync::Arc; - use once_cell::sync::Lazy; use rayon::{ThreadPool, ThreadPoolBuilder}; +use std::sync::Arc; pub mod context; -pub mod eval_edge; -pub mod eval_vertex; -pub mod eval_vertex_state; +mod edge; pub mod task; pub mod task_runner; pub(crate) mod task_state; -pub mod window_eval_edge; -pub mod window_eval_vertex; +pub(crate) mod vertex; pub static POOL: Lazy> = Lazy::new(|| { let num_threads = std::env::var("DOCBROWN_MAX_THREADS") @@ -44,10 +40,10 @@ pub fn custom_pool(n_threads: usize) -> Arc { #[cfg(test)] mod task_tests { - use crate::db::mutation_api::AdditionOps; use crate::{ core::state::{self, compute_state::ComputeStateVec}, - db::graph::Graph, + db::api::mutation::AdditionOps, + prelude::*, }; use super::{ diff --git a/raphtory/src/db/task/task.rs b/raphtory/src/db/task/task.rs index cf77538443..6d90944e07 100644 --- a/raphtory/src/db/task/task.rs +++ b/raphtory/src/db/task/task.rs @@ -1,10 +1,9 @@ -use std::marker::PhantomData; - -use crate::core::state::compute_state::ComputeState; -use crate::db::view_api::GraphViewOps; - use super::context::GlobalState; -use super::eval_vertex::EvalVertexView; +use crate::{ + core::state::compute_state::ComputeState, + db::{api::view::GraphViewOps, task::vertex::eval_vertex::EvalVertexView}, +}; +use std::marker::PhantomData; pub trait Task where diff --git a/raphtory/src/db/task/task_runner.rs b/raphtory/src/db/task/task_runner.rs index f5964dbb7f..0f7b0beb35 100644 --- a/raphtory/src/db/task/task_runner.rs +++ b/raphtory/src/db/task/task_runner.rs @@ -1,23 +1,26 @@ -use std::{ - borrow::Cow, - rc::Rc, - sync::atomic::{AtomicBool, Ordering}, -}; - -use rayon::{prelude::*, ThreadPool}; - -use crate::core:: state::shuffle_state::{EvalLocalState, EvalShardState}; -use crate::{core::state::compute_state::ComputeState, db::view_api::GraphViewOps}; - use super::{ context::{Context, GlobalState}, custom_pool, - eval_vertex::EvalVertexView, - eval_vertex_state::EVState, task::{Job, Step, Task}, task_state::{Global, Local2, Shard}, POOL, }; +use crate::{ + core::state::{ + compute_state::ComputeState, + shuffle_state::{EvalLocalState, EvalShardState}, + }, + db::{ + api::view::GraphViewOps, + task::vertex::{eval_vertex::EvalVertexView, eval_vertex_state::EVState}, + }, +}; +use rayon::{prelude::*, ThreadPool}; +use std::{ + borrow::Cow, + rc::Rc, + sync::atomic::{AtomicBool, Ordering}, +}; pub struct TaskRunner { pub(crate) ctx: Context, @@ -190,19 +193,14 @@ impl TaskRunner { fn make_cur_and_prev_states(&self, init: S) -> (Vec, Vec) { let g = self.ctx.graph(); - let states: Vec = vec![init; g.num_vertices()]; + let states: Vec = vec![init; g.num_vertices()]; (states.clone(), states) } pub fn run< B: std::fmt::Debug, - F: FnOnce( - GlobalState, - EvalShardState, - EvalLocalState, - &Vec, - ) -> B + F: FnOnce(GlobalState, EvalShardState, EvalLocalState, &Vec) -> B + std::marker::Copy, S: Send + Sync + Clone + 'static + std::fmt::Debug, >( @@ -221,17 +219,19 @@ impl TaskRunner { .unwrap_or_else(|| POOL.clone()); let morcel_size = self.ctx.graph().num_vertices().min(16_000); - let num_chunks = self.ctx.graph().num_vertices() / morcel_size ; + let num_chunks = self.ctx.graph().num_vertices() / morcel_size; - let mut shard_state = shard_initial_state.unwrap_or_else(|| Shard::new(self.ctx.graph().num_vertices(), num_chunks, morcel_size)); + let mut shard_state = shard_initial_state.unwrap_or_else(|| { + Shard::new(self.ctx.graph().num_vertices(), num_chunks, morcel_size) + }); let mut global_state = global_initial_state.unwrap_or_else(|| Global::new()); let (mut cur_local_state, mut prev_local_state) = self.make_cur_and_prev_states::(init); - let mut done = false; + let mut _done = false; - (done, shard_state, global_state, cur_local_state) = self.run_task_list( + (_done, shard_state, global_state, cur_local_state) = self.run_task_list( &init_tasks, &pool, morcel_size, @@ -244,8 +244,8 @@ impl TaskRunner { // To allow the init step to cache stuff we will copy everything from cur_local_state to prev_local_state prev_local_state.clone_from_slice(&cur_local_state); - while !done && self.ctx.ss() < steps && tasks.len() > 0 { - (done, shard_state, global_state, cur_local_state) = self.run_task_list( + while !_done && self.ctx.ss() < steps && tasks.len() > 0 { + (_done, shard_state, global_state, cur_local_state) = self.run_task_list( &tasks, &pool, morcel_size, diff --git a/raphtory/src/db/task/task_state.rs b/raphtory/src/db/task/task_state.rs index fc64dbc0eb..106f8e2e71 100644 --- a/raphtory/src/db/task/task_state.rs +++ b/raphtory/src/db/task/task_state.rs @@ -1,6 +1,5 @@ -use std::{borrow::Cow, sync::Arc}; - use crate::core::state::{compute_state::ComputeState, shuffle_state::ShuffleComputeState}; +use std::{borrow::Cow, sync::Arc}; // this only contains the global state and it is synchronized after each task run #[derive(Clone, Debug)] @@ -29,7 +28,11 @@ impl<'a, S: 'static> Local2<'a, S> { impl Shard { pub(crate) fn new(total_len: usize, num_morcels: usize, morcel_size: usize) -> Self { - Self(Arc::new(ShuffleComputeState::new(total_len, num_morcels, morcel_size))) + Self(Arc::new(ShuffleComputeState::new( + total_len, + num_morcels, + morcel_size, + ))) } pub(crate) fn as_cow(&self) -> Cow<'_, ShuffleComputeState> { diff --git a/raphtory/src/db/task/eval_vertex.rs b/raphtory/src/db/task/vertex/eval_vertex.rs similarity index 95% rename from raphtory/src/db/task/eval_vertex.rs rename to raphtory/src/db/task/vertex/eval_vertex.rs index 09f81d9ed4..1944b949e3 100644 --- a/raphtory/src/db/task/eval_vertex.rs +++ b/raphtory/src/db/task/vertex/eval_vertex.rs @@ -1,31 +1,37 @@ -use crate::core::tgraph::VID; -use crate::core::time::IntoTime; -use crate::core::{Direction, Prop}; -use crate::db::edge::EdgeView; -use crate::db::path::{Operations, PathFromVertex}; -use crate::db::task::eval_edge::EvalEdgeView; -use crate::db::view_api::internal::GraphPropertiesOps; -use crate::db::view_api::{ - BoxedIter, EdgeListOps, EdgeViewOps, TimeOps, VertexListOps, VertexViewOps, -}; use crate::{ - core::state::{ - accumulator_id::AccId, agg::Accumulator, compute_state::ComputeState, StateType, + core::{ + entities::VID, + state::{accumulator_id::AccId, agg::Accumulator, compute_state::ComputeState, StateType}, + utils::time::IntoTime, + Direction, Prop, + }, + db::{ + api::view::{ + internal::GraphPropertiesOps, BoxedIter, EdgeListOps, EdgeViewOps, GraphViewOps, + TimeOps, VertexListOps, VertexViewOps, + }, + graph::{ + edge::EdgeView, + path::{Operations, PathFromVertex}, + }, + task::{ + edge::eval_edge::EvalEdgeView, + task_state::Local2, + vertex::{ + eval_vertex_state::EVState, + window_eval_vertex::{WindowEvalPathFromVertex, WindowEvalVertex}, + }, + }, }, - db::view_api::GraphViewOps, }; use itertools::Itertools; -use std::collections::HashMap; -use std::marker::PhantomData; use std::{ cell::{Ref, RefCell}, + collections::HashMap, + marker::PhantomData, rc::Rc, }; -use super::eval_vertex_state::EVState; -use super::task_state::Local2; -use super::window_eval_vertex::{WindowEvalPathFromVertex, WindowEvalVertex}; - pub struct EvalVertexView<'a, G: GraphViewOps, CS: ComputeState, S: 'static> { ss: usize, vertex: VID, @@ -157,13 +163,7 @@ impl<'a, G: GraphViewOps, CS: ComputeState, S> EvalVertexView<'a, G, CS, S> { A: StateType, OUT: std::fmt::Debug, { - Entry::new( - self.vertex_state.borrow(), - *agg_r, - &self.vertex, - self.id(), - self.ss, - ) + Entry::new(self.vertex_state.borrow(), *agg_r, &self.vertex, self.ss) } /// Read the prev value of the vertex state using the given accumulator. @@ -619,7 +619,6 @@ pub struct Entry<'a, 'b, A: StateType, IN, OUT, ACC: Accumulator, CS state: Ref<'a, EVState<'b, CS>>, acc_id: AccId, v_ref: &'a VID, - gid: u64, ss: usize, } @@ -639,14 +638,12 @@ impl<'a, 'b, A: StateType, IN, OUT, ACC: Accumulator, CS: ComputeSta state: Ref<'a, EVState<'b, CS>>, acc_id: AccId, v_ref: &'a VID, - gid: u64, ss: usize, ) -> Entry<'a, 'b, A, IN, OUT, ACC, CS> { Entry { state, acc_id, v_ref, - gid, ss, } } diff --git a/raphtory/src/db/task/eval_vertex_state.rs b/raphtory/src/db/task/vertex/eval_vertex_state.rs similarity index 99% rename from raphtory/src/db/task/eval_vertex_state.rs rename to raphtory/src/db/task/vertex/eval_vertex_state.rs index ae8f0669bb..c0d354c162 100644 --- a/raphtory/src/db/task/eval_vertex_state.rs +++ b/raphtory/src/db/task/vertex/eval_vertex_state.rs @@ -1,6 +1,5 @@ -use std::{borrow::Cow, cell::RefCell, rc::Rc}; - use crate::core::state::{compute_state::ComputeState, shuffle_state::ShuffleComputeState}; +use std::{borrow::Cow, cell::RefCell, rc::Rc}; #[derive(Debug)] pub(crate) struct EVState<'a, CS: ComputeState> { diff --git a/raphtory/src/db/task/vertex/mod.rs b/raphtory/src/db/task/vertex/mod.rs new file mode 100644 index 0000000000..ca5802a826 --- /dev/null +++ b/raphtory/src/db/task/vertex/mod.rs @@ -0,0 +1,3 @@ +pub mod eval_vertex; +pub mod eval_vertex_state; +pub mod window_eval_vertex; diff --git a/raphtory/src/db/task/window_eval_vertex.rs b/raphtory/src/db/task/vertex/window_eval_vertex.rs similarity index 97% rename from raphtory/src/db/task/window_eval_vertex.rs rename to raphtory/src/db/task/vertex/window_eval_vertex.rs index a3333ca975..ca308d9164 100644 --- a/raphtory/src/db/task/window_eval_vertex.rs +++ b/raphtory/src/db/task/vertex/window_eval_vertex.rs @@ -1,21 +1,23 @@ -use std::{cell::RefCell, collections::HashMap, marker::PhantomData, rc::Rc}; - -use crate::core::tgraph::VID; -use crate::db::view_api::internal::{GraphPropertiesOps, GraphWindowOps}; use crate::{ core::{ - state::agg::Accumulator, - state::{accumulator_id::AccId, compute_state::ComputeState, StateType}, - time::IntoTime, + entities::VID, + state::{accumulator_id::AccId, agg::Accumulator, compute_state::ComputeState, StateType}, + utils::time::IntoTime, Direction, Prop, }, db::{ - path::{Operations, PathFromVertex}, - view_api::{GraphViewOps, TimeOps, VertexListOps, VertexViewOps}, + api::view::{ + internal::{GraphPropertiesOps, GraphWindowOps}, + GraphViewOps, TimeOps, VertexListOps, VertexViewOps, + }, + graph::path::{Operations, PathFromVertex}, + task::{ + edge::window_eval_edge::WindowEvalEdgeView, task_state::Local2, + vertex::eval_vertex_state::EVState, + }, }, }; - -use super::{eval_vertex_state::EVState, task_state::Local2, window_eval_edge::WindowEvalEdgeView}; +use std::{cell::RefCell, collections::HashMap, marker::PhantomData, rc::Rc}; pub struct WindowEvalVertex<'a, G: GraphViewOps, CS: ComputeState, S: 'static> { ss: usize, diff --git a/raphtory/src/db/doc_strings.rs b/raphtory/src/db/utils/doc_strings.rs similarity index 100% rename from raphtory/src/db/doc_strings.rs rename to raphtory/src/db/utils/doc_strings.rs diff --git a/raphtory/src/db/utils/mod.rs b/raphtory/src/db/utils/mod.rs new file mode 100644 index 0000000000..aefeca739a --- /dev/null +++ b/raphtory/src/db/utils/mod.rs @@ -0,0 +1 @@ +pub mod doc_strings; diff --git a/raphtory/src/db/view_api/internal/into_dynamic.rs b/raphtory/src/db/view_api/internal/into_dynamic.rs deleted file mode 100644 index af4500eba5..0000000000 --- a/raphtory/src/db/view_api/internal/into_dynamic.rs +++ /dev/null @@ -1,59 +0,0 @@ -use crate::db::graph_layer::LayeredGraph; -use crate::db::graph_window::WindowedGraph; -use crate::db::subgraph_vertex::VertexSubgraph; -use crate::db::view_api::internal::DynamicGraph; -use crate::db::view_api::GraphViewOps; - -pub trait IntoDynamic { - fn into_dynamic(self) -> DynamicGraph; -} - -impl IntoDynamic for WindowedGraph { - fn into_dynamic(self) -> DynamicGraph { - DynamicGraph::new(self) - } -} - -impl IntoDynamic for LayeredGraph { - fn into_dynamic(self) -> DynamicGraph { - DynamicGraph::new(self) - } -} - -impl IntoDynamic for DynamicGraph { - fn into_dynamic(self) -> DynamicGraph { - self - } -} - -impl IntoDynamic for VertexSubgraph { - fn into_dynamic(self) -> DynamicGraph { - DynamicGraph::new(self) - } -} - -/// This macro defines a trait `GraphTag` and implements it for each graph view. -#[macro_export] -macro_rules! graph_tag { - () => { - pub trait GraphTag: - $crate::db::view_api::GraphViewOps + $crate::db::view_api::into_dynamic::IntoDynamic - { - } - - impl GraphTag for $crate::db::graph::Graph {} - impl GraphTag - for $crate::db::graph_layer::LayeredGraph - { - } - impl GraphTag - for $crate::db::graph_window::WindowedGraph - { - } - impl GraphTag - for $crate::db::subgraph_vertex::VertexSubgraph - { - } - impl GraphTag for $crate::db::view_api::internal::DynamicGraph {} - }; -} diff --git a/raphtory/src/graph_loader/example/company_house.rs b/raphtory/src/graph_loader/example/company_house.rs index 3302cc3192..ad1e91b2f3 100644 --- a/raphtory/src/graph_loader/example/company_house.rs +++ b/raphtory/src/graph_loader/example/company_house.rs @@ -1,12 +1,7 @@ -use crate::core::Prop; -use crate::db::graph::Graph; -use crate::db::mutation_api::{AdditionOps, PropertyAdditionOps}; -use crate::db::view_api::*; -use crate::graph_loader::source::csv_loader::CsvLoader; +use crate::{core::Prop, graph_loader::source::csv_loader::CsvLoader, prelude::*}; use chrono::NaiveDateTime; use serde::Deserialize; -use std::path::PathBuf; -use std::{fs, time::Instant}; +use std::{fs, path::PathBuf, time::Instant}; #[derive(Deserialize, std::fmt::Debug)] pub struct CompanyHouse { @@ -185,7 +180,7 @@ pub fn company_house_graph(path: Option) -> Graph { #[cfg(test)] mod company_house_graph_test { use super::*; - use crate::db::view_api::{TimeOps, VertexViewOps}; + use crate::db::api::view::{TimeOps, VertexViewOps}; #[test] #[ignore] diff --git a/raphtory/src/graph_loader/example/lotr_graph.rs b/raphtory/src/graph_loader/example/lotr_graph.rs index b7cd9cc0f8..fe401b26a6 100644 --- a/raphtory/src/graph_loader/example/lotr_graph.rs +++ b/raphtory/src/graph_loader/example/lotr_graph.rs @@ -14,20 +14,17 @@ //! Example: //! ```rust //! use raphtory::graph_loader::example::lotr_graph::lotr_graph; -//! use raphtory::db::graph::Graph; -//! use raphtory::db::view_api::*; +//! use raphtory::prelude::*; //! //! let graph = lotr_graph(); //! //! println!("The graph has {:?} vertices", graph.num_vertices()); //! println!("The graph has {:?} edges", graph.num_edges()); //! ``` -use crate::db::graph::Graph; - -use crate::graph_loader::fetch_file; - -use crate::db::mutation_api::AdditionOps; -use crate::graph_loader::source::csv_loader::CsvLoader; +use crate::{ + graph_loader::{fetch_file, source::csv_loader::CsvLoader}, + prelude::*, +}; use serde::Deserialize; use std::path::PathBuf; diff --git a/raphtory/src/graph_loader/example/neo4j_examples.rs b/raphtory/src/graph_loader/example/neo4j_examples.rs index e840bccb73..f6c0fffe75 100644 --- a/raphtory/src/graph_loader/example/neo4j_examples.rs +++ b/raphtory/src/graph_loader/example/neo4j_examples.rs @@ -1,7 +1,11 @@ -use crate::core::Prop; -use crate::db::graph as rap; -use crate::db::mutation_api::{AdditionOps, PropertyAdditionOps}; -use crate::graph_loader::source::neo4j_loader::Neo4JConnection; +use crate::{ + core::Prop, + db::{ + api::mutation::{AdditionOps, PropertyAdditionOps}, + graph::graph as rap, + }, + graph_loader::source::neo4j_loader::Neo4JConnection, +}; use neo4rs::*; fn load_movies(row: Row, graph: &rap::Graph) { diff --git a/raphtory/src/graph_loader/example/reddit_hyperlinks.rs b/raphtory/src/graph_loader/example/reddit_hyperlinks.rs index 36f6b9c1d9..42f96e9bae 100644 --- a/raphtory/src/graph_loader/example/reddit_hyperlinks.rs +++ b/raphtory/src/graph_loader/example/reddit_hyperlinks.rs @@ -30,8 +30,7 @@ //! Example: //! ```no_run //! use raphtory::graph_loader::example::reddit_hyperlinks::reddit_graph; -//! use raphtory::db::graph::Graph; -//! use raphtory::db::view_api::*; +//! use raphtory::prelude::*; //! //! let graph = reddit_graph(120, false); //! @@ -39,16 +38,14 @@ //! println!("The graph has {:?} edges", graph.num_edges()); //! ``` -use crate::core::Prop; -use crate::db::graph::Graph; -use crate::db::mutation_api::AdditionOps; -use crate::graph_loader::fetch_file; +use crate::{core::Prop, db::api::mutation::AdditionOps, graph_loader::fetch_file, prelude::*}; use chrono::*; use itertools::Itertools; -use std::fs::File; -use std::io::{self, BufRead}; -use std::path::Path; -use std::path::PathBuf; +use std::{ + fs::File, + io::{self, BufRead}, + path::{Path, PathBuf}, +}; /// Download the dataset and return the path to the file /// # Arguments @@ -158,8 +155,10 @@ pub fn reddit_graph(timeout: u64, test_file: bool) -> Graph { #[cfg(test)] mod reddit_test { - use crate::db::view_api::*; - use crate::graph_loader::example::reddit_hyperlinks::{reddit_file, reddit_graph}; + use crate::{ + db::api::view::*, + graph_loader::example::reddit_hyperlinks::{reddit_file, reddit_graph}, + }; #[test] fn check_data() { diff --git a/raphtory/src/graph_loader/example/stable_coins.rs b/raphtory/src/graph_loader/example/stable_coins.rs index ef336c5ad5..bb8085417c 100644 --- a/raphtory/src/graph_loader/example/stable_coins.rs +++ b/raphtory/src/graph_loader/example/stable_coins.rs @@ -1,15 +1,11 @@ -use crate::core::Prop; -use crate::db::graph::Graph; -use crate::db::mutation_api::AdditionOps; -use crate::db::view_api::GraphViewOps; -use crate::graph_loader::source::csv_loader::CsvLoader; -use crate::graph_loader::{fetch_file, unzip_file}; +use crate::{ + graph_loader::{fetch_file, source::csv_loader::CsvLoader, unzip_file}, + prelude::*, +}; use chrono::NaiveDateTime; use regex::Regex; use serde::Deserialize; -use std::collections::HashMap; -use std::path::PathBuf; -use std::{fs, time::Instant}; +use std::{collections::HashMap, fs, path::PathBuf, time::Instant}; #[allow(dead_code)] #[derive(Deserialize, std::fmt::Debug)] diff --git a/raphtory/src/graph_loader/example/sx_superuser_graph.rs b/raphtory/src/graph_loader/example/sx_superuser_graph.rs index 7c429242b1..d7d4f34573 100644 --- a/raphtory/src/graph_loader/example/sx_superuser_graph.rs +++ b/raphtory/src/graph_loader/example/sx_superuser_graph.rs @@ -37,8 +37,7 @@ //! Example: //! ```no_run //! use raphtory::graph_loader::example::sx_superuser_graph::sx_superuser_graph; -//! use raphtory::db::graph::Graph; -//! use raphtory::db::view_api::*; +//! use raphtory::prelude::*; //! //! let graph = sx_superuser_graph().unwrap(); //! @@ -46,10 +45,10 @@ //! println!("The graph has {:?} edges", graph.num_edges()); //! ``` -use crate::db::graph::Graph; - -use crate::db::mutation_api::AdditionOps; -use crate::graph_loader::{fetch_file, source::csv_loader::CsvLoader}; +use crate::{ + graph_loader::{fetch_file, source::csv_loader::CsvLoader}, + prelude::*, +}; use serde::Deserialize; use std::path::PathBuf; diff --git a/raphtory/src/graph_loader/mod.rs b/raphtory/src/graph_loader/mod.rs index 7db9be28ca..f6c21379c1 100644 --- a/raphtory/src/graph_loader/mod.rs +++ b/raphtory/src/graph_loader/mod.rs @@ -9,8 +9,7 @@ //! Load a pre-built graph //! ```rust //! use raphtory::algorithms::degree::average_degree; -//! use raphtory::db::graph::Graph; -//! use raphtory::db::view_api::*; +//! use raphtory::prelude::*; //! use raphtory::graph_loader::example::lotr_graph::lotr_graph; //! //! let graph = lotr_graph(); @@ -31,12 +30,10 @@ //! Load a graph from csv //! //! ```no_run -//! use raphtory::db::graph::Graph; -//! use raphtory::core::Prop; //! use std::time::Instant; //! use serde::Deserialize; -//! use raphtory::db::mutation_api::AdditionOps; //! use raphtory::graph_loader::source::csv_loader::CsvLoader; +//! use raphtory::prelude::*; //! //! let data_dir = "/tmp/lotr.csv"; //! @@ -97,12 +94,13 @@ //! assert!(path.is_ok()); //! ``` -use std::env; -use std::fs::File; -use std::fs::*; -use std::io::{copy, Cursor}; -use std::path::{Path, PathBuf}; -use std::time::Duration; +use std::{ + env, + fs::{File, *}, + io::{copy, Cursor}, + path::{Path, PathBuf}, + time::Duration, +}; use zip::read::ZipArchive; pub mod example; @@ -161,17 +159,10 @@ fn unzip_file(zip_file_path: &str, destination_path: &str) -> std::io::Result<() #[cfg(test)] mod graph_loader_test { - use crate::db::mutation_api::AdditionOps; - use crate::{ - core::{utils, Prop}, - db::{ - graph::Graph, - view_api::{GraphViewOps, TimeOps, VertexViewOps}, - }, - }; + use crate::{core::utils::hashing, prelude::*}; use csv::StringRecord; - use crate::graph_loader::fetch_file; + use crate::{graph_loader::fetch_file, prelude::*}; #[test] fn test_fetch_file() { @@ -224,8 +215,8 @@ mod graph_loader_test { if let Ok(mut reader) = csv::Reader::from_path(data_dir) { for rec in reader.records().flatten() { if let Some((src, dst, t)) = parse_record(&rec) { - let src_id = utils::calculate_hash(&src); - let dst_id = utils::calculate_hash(&dst); + let src_id = hashing::calculate_hash(&src); + let dst_id = hashing::calculate_hash(&dst); g.add_vertex( t, @@ -254,7 +245,7 @@ mod graph_loader_test { } } - let gandalf = utils::calculate_hash(&"Gandalf"); + let gandalf = hashing::calculate_hash(&"Gandalf"); assert!(g.has_vertex(gandalf)); assert!(g.has_vertex("Gandalf")) } diff --git a/raphtory/src/graph_loader/source/csv_loader.rs b/raphtory/src/graph_loader/source/csv_loader.rs index b74af70cd2..e13543d3f2 100644 --- a/raphtory/src/graph_loader/source/csv_loader.rs +++ b/raphtory/src/graph_loader/source/csv_loader.rs @@ -4,12 +4,10 @@ //! ```no_run //! use std::path::{Path, PathBuf}; //! use regex::Regex; -//! use raphtory::core::Prop; -//! use raphtory::core::utils::calculate_hash; +//! use raphtory::core::utils::hashing::calculate_hash; //! use raphtory::graph_loader::source::csv_loader::CsvLoader; -//! use raphtory::db::graph::Graph; -//! use raphtory::db::mutation_api::AdditionOps; //! use raphtory::graph_loader::example::lotr_graph::Lotr; +//! use raphtory::prelude::*; //! //! let g = Graph::new(); //! let csv_path: PathBuf = [env!("CARGO_MANIFEST_DIR"), "../../resource/"] @@ -67,13 +65,16 @@ use flate2::read::GzDecoder; use rayon::prelude::*; use regex::Regex; use serde::de::DeserializeOwned; -use std::collections::VecDeque; -use std::error::Error; -use std::fmt::{Debug, Display, Formatter}; -use std::fs::File; -use std::io::BufReader; -use std::path::{Path, PathBuf}; -use std::{fs, io}; +use std::{ + collections::VecDeque, + error::Error, + fmt::{Debug, Display, Formatter}, + fs, + fs::File, + io, + io::BufReader, + path::{Path, PathBuf}, +}; #[derive(Debug)] pub enum CsvErr { @@ -403,11 +404,10 @@ impl CsvLoader { #[cfg(test)] mod csv_loader_test { - use crate::core::utils::calculate_hash; - use crate::core::Prop; - use crate::db::graph::Graph; - use crate::db::mutation_api::AdditionOps; - use crate::graph_loader::source::csv_loader::CsvLoader; + use crate::{ + core::utils::hashing::calculate_hash, graph_loader::source::csv_loader::CsvLoader, + prelude::*, + }; use regex::Regex; use serde::Deserialize; use std::path::{Path, PathBuf}; diff --git a/raphtory/src/graph_loader/source/json_loader.rs b/raphtory/src/graph_loader/source/json_loader.rs index 9704fa3824..b654e1c695 100644 --- a/raphtory/src/graph_loader/source/json_loader.rs +++ b/raphtory/src/graph_loader/source/json_loader.rs @@ -1,3 +1,7 @@ +use crate::core::utils::errors::GraphError; +use rayon::prelude::*; +use regex::Regex; +use serde::de::DeserializeOwned; use std::{ collections::VecDeque, error::Error, @@ -6,11 +10,6 @@ use std::{ path::{Path, PathBuf}, }; -use crate::core::errors::GraphError; -use rayon::prelude::*; -use regex::Regex; -use serde::de::DeserializeOwned; - #[derive(Debug)] pub enum JsonErr { /// An IO error that occurred during file read. diff --git a/raphtory/src/graph_loader/source/neo4j_loader.rs b/raphtory/src/graph_loader/source/neo4j_loader.rs index e002da5d33..c539896811 100644 --- a/raphtory/src/graph_loader/source/neo4j_loader.rs +++ b/raphtory/src/graph_loader/source/neo4j_loader.rs @@ -1,4 +1,4 @@ -use crate::db::graph as rap; +use crate::db::graph::graph as rap; use neo4rs::*; /// A struct that defines the Neo4J loader with configurable options. pub struct Neo4JConnection { @@ -48,11 +48,17 @@ impl Neo4JConnection { #[cfg(test)] mod neo_loader_test { - use crate::core::Prop; - use crate::db::graph as rap; - use crate::db::mutation_api::{AdditionOps, PropertyAdditionOps}; - use crate::db::view_api::GraphViewOps; - use crate::graph_loader::source::neo4j_loader::Neo4JConnection; + use crate::{ + core::Prop, + db::{ + api::{ + mutation::{AdditionOps, PropertyAdditionOps}, + view::GraphViewOps, + }, + graph::graph as rap, + }, + graph_loader::source::neo4j_loader::Neo4JConnection, + }; use neo4rs::*; fn load_movies(row: Row, graph: &rap::Graph) { diff --git a/raphtory/src/graphgen/preferential_attachment.rs b/raphtory/src/graphgen/preferential_attachment.rs index 3acf7c6b73..d97f1f6a7c 100644 --- a/raphtory/src/graphgen/preferential_attachment.rs +++ b/raphtory/src/graphgen/preferential_attachment.rs @@ -5,16 +5,17 @@ //! # Examples //! //! ``` -//! use raphtory::db::graph::Graph; +//! use raphtory::prelude::*; //! use raphtory::graphgen::preferential_attachment::ba_preferential_attachment; //! //! let graph = Graph::new(); //! ba_preferential_attachment(&graph, 1000, 10); //! ``` -use crate::db::graph::Graph; -use crate::db::mutation_api::AdditionOps; -use crate::db::view_api::*; +use crate::db::{ + api::{mutation::AdditionOps, view::*}, + graph::graph::Graph, +}; use rand::prelude::*; use std::collections::HashSet; @@ -38,7 +39,7 @@ use std::collections::HashSet; /// # Examples /// /// ``` -/// use raphtory::db::graph::Graph; +/// use raphtory::prelude::*; /// use raphtory::graphgen::preferential_attachment::ba_preferential_attachment; /// /// let graph = Graph::new(); diff --git a/raphtory/src/graphgen/random_attachment.rs b/raphtory/src/graphgen/random_attachment.rs index 81ee96ffb7..18d3891190 100644 --- a/raphtory/src/graphgen/random_attachment.rs +++ b/raphtory/src/graphgen/random_attachment.rs @@ -7,15 +7,16 @@ //! # Examples //! //! ``` -//! use raphtory::db::graph::Graph; +//! use raphtory::prelude::*; //! use raphtory::graphgen::random_attachment::random_attachment; //! let graph = Graph::new(); //! random_attachment(&graph, 1000, 10); //! ``` -use crate::db::graph::Graph; -use crate::db::mutation_api::AdditionOps; -use crate::db::view_api::*; +use crate::db::{ + api::{mutation::AdditionOps, view::*}, + graph::graph::Graph, +}; use rand::seq::SliceRandom; /// Given a graph this function will add a user defined number of vertices, each with a @@ -35,7 +36,7 @@ use rand::seq::SliceRandom; /// # Examples /// /// ``` -/// use raphtory::db::graph::Graph; +/// use raphtory::prelude::*; /// use raphtory::graphgen::random_attachment::random_attachment; /// let graph = Graph::new(); /// random_attachment(&graph, 1000, 10); diff --git a/raphtory/src/lib.rs b/raphtory/src/lib.rs index cb17dae3eb..cbe7fa45e4 100644 --- a/raphtory/src/lib.rs +++ b/raphtory/src/lib.rs @@ -97,11 +97,16 @@ pub mod python; pub mod graph_loader; pub mod prelude { - pub use crate::core::{Prop, PropUnwrap}; - pub use crate::db::graph::Graph; - pub use crate::db::graph_deletions::GraphWithDeletions; - pub use crate::db::mutation_api::{AdditionOps, DeletionOps, PropertyAdditionOps}; - pub use crate::db::view_api::{ - EdgeListOps, EdgeViewOps, GraphViewOps, TimeOps, VertexListOps, VertexViewOps, + pub use crate::{ + core::{Prop, PropUnwrap}, + db::{ + api::{ + mutation::{AdditionOps, DeletionOps, PropertyAdditionOps}, + view::{ + EdgeListOps, EdgeViewOps, GraphViewOps, TimeOps, VertexListOps, VertexViewOps, + }, + }, + graph::graph::Graph, + }, }; } diff --git a/raphtory/src/python/edge.rs b/raphtory/src/python/graph/edge.rs similarity index 95% rename from raphtory/src/python/edge.rs rename to raphtory/src/python/graph/edge.rs index a8c3e645a8..f79499728e 100644 --- a/raphtory/src/python/edge.rs +++ b/raphtory/src/python/graph/edge.rs @@ -4,25 +4,36 @@ //! The PyEdge class also provides access to the perspective APIs, which allow the user to view the //! edge as it existed at a particular point in time, or as it existed over a particular time range. //! -use crate::core::time::error::ParseTimeError; -use crate::core::Prop; -use crate::db::edge::EdgeView; -use crate::db::graph_window::WindowedGraph; -use crate::db::view_api::internal::{DynamicGraph, IntoDynamic}; -use crate::db::view_api::*; -use crate::python; +use crate::{ + core::{utils::time::error::ParseTimeError, Prop}, + db::{ + api::view::{ + internal::{DynamicGraph, IntoDynamic}, + BoxedIter, WindowSet, + }, + graph::{edge::EdgeView, views::window_graph::WindowedGraph}, + }, + prelude::*, + python::{ + graph::vertex::{PyVertex, PyVertexIterable}, + types::{ + repr::{iterator_repr, Repr}, + wrappers::{ + iterators::{OptionI64Iterable, OptionPropIterable, PropsIterable}, + *, + }, + }, + utils::{PyGenericIterable, PyInterval, PyTime}, + }, +}; use chrono::NaiveDateTime; use itertools::Itertools; -use pyo3::prelude::*; -use pyo3::pyclass::CompareOp; -use python::types::repr::{iterator_repr, Repr}; -use python::utils::*; -use python::vertex::{PyVertex, PyVertexIterable}; -use python::wrappers::iterators::{OptionI64Iterable, OptionPropIterable, PropsIterable}; -use std::collections::hash_map::DefaultHasher; -use std::collections::HashMap; -use std::hash::{Hash, Hasher}; -use std::sync::Arc; +use pyo3::{prelude::*, pyclass::CompareOp}; +use std::{ + collections::{hash_map::DefaultHasher, HashMap}, + hash::{Hash, Hasher}, + sync::Arc, +}; /// PyEdge is a Python class that represents an edge in the graph. /// An edge is a directed connection between two vertices. diff --git a/raphtory/src/python/graph.rs b/raphtory/src/python/graph/graph.rs similarity index 94% rename from raphtory/src/python/graph.rs rename to raphtory/src/python/graph/graph.rs index 7cc7b70a70..b39d6894b1 100644 --- a/raphtory/src/python/graph.rs +++ b/raphtory/src/python/graph/graph.rs @@ -4,18 +4,20 @@ //! create windows, and query the graph with a variety of algorithms. //! It is a wrapper around a set of shards, which are the actual graph data structures. //! In Python, this class wraps around the rust graph. -use crate::core::errors::GraphError; -use crate::core::Prop; -use crate::db::graph::Graph; -use crate::db::mutation_api::{AdditionOps, PropertyAdditionOps}; -use crate::python; -use crate::python::utils::PyTime; +use crate::{ + core::utils::errors::GraphError, + prelude::*, + python::{ + graph::views::graph_view::PyGraphView, + utils::{PyInputVertex, PyTime}, + }, +}; use pyo3::prelude::*; -use python::graph_view::PyGraphView; -use python::utils::PyInputVertex; -use std::collections::HashMap; -use std::fmt::{Debug, Formatter}; -use std::path::{Path, PathBuf}; +use std::{ + collections::HashMap, + fmt::{Debug, Formatter}, + path::{Path, PathBuf}, +}; /// A temporal graph. #[derive(Clone)] diff --git a/raphtory/src/python/graph_with_deletions.rs b/raphtory/src/python/graph/graph_with_deletions.rs similarity index 94% rename from raphtory/src/python/graph_with_deletions.rs rename to raphtory/src/python/graph/graph_with_deletions.rs index 5375f7c57a..0843c05f3e 100644 --- a/raphtory/src/python/graph_with_deletions.rs +++ b/raphtory/src/python/graph/graph_with_deletions.rs @@ -5,18 +5,24 @@ //! create windows, and query the graph with a variety of algorithms. //! It is a wrapper around a set of shards, which are the actual graph data structures. //! In Python, this class wraps around the rust graph. -use crate::core::errors::GraphError; -use crate::core::Prop; -use crate::db::mutation_api::{AdditionOps, PropertyAdditionOps}; -use crate::prelude::{DeletionOps, GraphWithDeletions}; -use crate::python; -use crate::python::utils::PyTime; +use crate::{ + core::{utils::errors::GraphError, Prop}, + db::{ + api::mutation::{AdditionOps, PropertyAdditionOps}, + graph::views::deletion_graph::GraphWithDeletions, + }, + prelude::DeletionOps, + python::{ + graph::views::graph_view::PyGraphView, + utils::{PyInputVertex, PyTime}, + }, +}; use pyo3::prelude::*; -use python::graph_view::PyGraphView; -use python::utils::PyInputVertex; -use std::collections::HashMap; -use std::fmt::{Debug, Formatter}; -use std::path::{Path, PathBuf}; +use std::{ + collections::HashMap, + fmt::{Debug, Formatter}, + path::{Path, PathBuf}, +}; /// A temporal graph. #[derive(Clone)] diff --git a/raphtory/src/python/graph/mod.rs b/raphtory/src/python/graph/mod.rs new file mode 100644 index 0000000000..5f5854d88e --- /dev/null +++ b/raphtory/src/python/graph/mod.rs @@ -0,0 +1,5 @@ +pub mod edge; +pub mod graph; +pub mod graph_with_deletions; +pub mod vertex; +pub mod views; diff --git a/raphtory/src/python/vertex.rs b/raphtory/src/python/graph/vertex.rs similarity index 98% rename from raphtory/src/python/vertex.rs rename to raphtory/src/python/graph/vertex.rs index 6111617449..8568be1791 100644 --- a/raphtory/src/python/vertex.rs +++ b/raphtory/src/python/graph/vertex.rs @@ -1,27 +1,35 @@ //! Defines the `Vertex`, which represents a vertex in the graph. //! A vertex is a node in the graph, and can have properties and edges. //! It can also be used to navigate the graph. -use crate::core::time::error::ParseTimeError; -use crate::core::vertex_ref::VertexRef; -use crate::core::Prop; -use crate::db::graph_window::WindowedGraph; -use crate::db::path::{PathFromGraph, PathFromVertex}; -use crate::db::vertex::VertexView; -use crate::db::vertices::Vertices; -use crate::db::view_api::internal::{DynamicGraph, IntoDynamic}; -use crate::db::view_api::*; -use crate::python; -use crate::python::utils::{PyInterval, PyTime}; -use crate::*; + +use crate::{ + core::{entities::vertices::vertex_ref::VertexRef, utils::time::error::ParseTimeError, Prop}, + db::{ + api::view::{ + internal::{DynamicGraph, IntoDynamic}, + *, + }, + graph::{ + path::{PathFromGraph, PathFromVertex}, + vertex::VertexView, + vertices::Vertices, + views::window_graph::WindowedGraph, + }, + }, + python::{ + graph::edge::{PyEdges, PyNestedEdges}, + types::wrappers::iterators::*, + utils::{PyInterval, PyTime}, + }, + *, +}; use chrono::NaiveDateTime; use itertools::Itertools; -use pyo3::exceptions::PyIndexError; -use pyo3::prelude::*; -use pyo3::pyclass::CompareOp; -use pyo3::{pyclass, pymethods, PyAny, PyObject, PyRef, PyRefMut, PyResult, Python}; -use python::edge::{PyEdges, PyNestedEdges}; +use pyo3::{ + exceptions::PyIndexError, prelude::*, pyclass, pyclass::CompareOp, pymethods, PyAny, PyObject, + PyRef, PyRefMut, PyResult, Python, +}; use python::types::repr::{iterator_repr, Repr}; -use python::wrappers::iterators::*; use std::collections::HashMap; /// A vertex (or node) in the graph. diff --git a/raphtory/src/python/graph_view.rs b/raphtory/src/python/graph/views/graph_view.rs similarity index 94% rename from raphtory/src/python/graph_view.rs rename to raphtory/src/python/graph/views/graph_view.rs index 70d993c8a0..3f7e442da0 100644 --- a/raphtory/src/python/graph_view.rs +++ b/raphtory/src/python/graph/views/graph_view.rs @@ -1,23 +1,37 @@ //! The API for querying a view of the graph in a read-only state -use crate::core::errors::GraphError; -use crate::core::time::error::ParseTimeError; -use crate::core::vertex_ref::VertexRef; -use crate::core::Prop; -use crate::db::edge::EdgeView; -use crate::db::graph_layer::LayeredGraph; -use crate::db::graph_window::WindowedGraph; -use crate::db::subgraph_vertex::VertexSubgraph; -use crate::db::vertex::VertexView; -use crate::db::view_api::internal::{DynamicGraph, IntoDynamic, MaterializedGraph}; -use crate::db::view_api::*; -use crate::python; -use crate::python::utils::{PyInterval, PyTime}; -use crate::*; +use crate::{ + core::{ + entities::vertices::vertex_ref::VertexRef, + utils::{errors::GraphError, time::error::ParseTimeError}, + Prop, + }, + db::{ + api::view::{ + internal::{DynamicGraph, IntoDynamic, MaterializedGraph}, + LayerOps, WindowSet, + }, + graph::{ + edge::EdgeView, + vertex::VertexView, + views::{ + layer_graph::LayeredGraph, vertex_subgraph::VertexSubgraph, + window_graph::WindowedGraph, + }, + }, + }, + prelude::*, + python::{ + graph::{ + edge::PyEdges, + vertex::{PyVertex, PyVertices}, + }, + types::repr::Repr, + utils::{PyInterval, PyTime}, + }, + *, +}; use chrono::prelude::*; use pyo3::prelude::*; -use python::edge::PyEdges; -use python::types::repr::Repr; -use python::vertex::{PyVertex, PyVertices}; use std::collections::HashMap; impl IntoPy for MaterializedGraph { diff --git a/raphtory/src/python/graph/views/mod.rs b/raphtory/src/python/graph/views/mod.rs new file mode 100644 index 0000000000..c0068a9452 --- /dev/null +++ b/raphtory/src/python/graph/views/mod.rs @@ -0,0 +1 @@ +pub mod graph_view; diff --git a/raphtory/src/python/macros/mod.rs b/raphtory/src/python/macros/mod.rs deleted file mode 100644 index 7b041b8b41..0000000000 --- a/raphtory/src/python/macros/mod.rs +++ /dev/null @@ -1,6 +0,0 @@ -#[macro_use] -mod iter; -#[macro_use] -mod iterable; -#[macro_use] -mod nested_iterable; diff --git a/raphtory/src/python/mod.rs b/raphtory/src/python/mod.rs index cce7a6e707..f8ff9f5c5f 100644 --- a/raphtory/src/python/mod.rs +++ b/raphtory/src/python/mod.rs @@ -1,17 +1,7 @@ extern crate core; #[macro_use] -mod macros; - -pub mod algorithms; -pub mod edge; -pub mod errors; -pub mod graph; -pub mod graph_gen; -pub mod graph_loader; -pub mod graph_view; -pub mod graph_with_deletions; pub mod types; +pub mod graph; +pub mod packages; pub mod utils; -pub mod vertex; -pub mod wrappers; diff --git a/raphtory/src/python/algorithms.rs b/raphtory/src/python/packages/algorithms.rs similarity index 88% rename from raphtory/src/python/algorithms.rs rename to raphtory/src/python/packages/algorithms.rs index 00457af67d..e0556e8334 100644 --- a/raphtory/src/python/algorithms.rs +++ b/raphtory/src/python/packages/algorithms.rs @@ -2,27 +2,33 @@ /// /// To run an algorithm simply import the module and call the function with the graph as the argument /// -use crate::python::graph_view::PyGraphView; use std::collections::HashMap; -use crate::algorithms::connected_components; -use crate::algorithms::degree::{ - average_degree as average_degree_rs, max_in_degree as max_in_degree_rs, - max_out_degree as max_out_degree_rs, min_in_degree as min_in_degree_rs, - min_out_degree as min_out_degree_rs, +use crate::{ + algorithms::{ + connected_components, + degree::{ + average_degree as average_degree_rs, max_in_degree as max_in_degree_rs, + max_out_degree as max_out_degree_rs, min_in_degree as min_in_degree_rs, + min_out_degree as min_out_degree_rs, + }, + directed_graph_density::directed_graph_density as directed_graph_density_rs, + local_clustering_coefficient::local_clustering_coefficient as local_clustering_coefficient_rs, + local_triangle_count::local_triangle_count as local_triangle_count_rs, + motifs::three_node_local::{ + global_temporal_three_node_motifs as global_temporal_three_node_motif_rs, + local_temporal_three_node_motifs as local_three_node_rs, + }, + pagerank::unweighted_page_rank, + reciprocity::{ + all_local_reciprocity as all_local_reciprocity_rs, + global_reciprocity as global_reciprocity_rs, + }, + temporal_reachability::temporally_reachable_nodes as temporal_reachability_rs, + }, + core::entities::vertices::vertex_ref::VertexRef, + python::{graph::views::graph_view::PyGraphView, utils::PyInputVertex}, }; -use crate::algorithms::directed_graph_density::directed_graph_density as directed_graph_density_rs; -use crate::algorithms::local_clustering_coefficient::local_clustering_coefficient as local_clustering_coefficient_rs; -use crate::algorithms::local_triangle_count::local_triangle_count as local_triangle_count_rs; -use crate::algorithms::motifs::three_node_local::global_temporal_three_node_motifs as global_temporal_three_node_motif_rs; -use crate::algorithms::motifs::three_node_local::local_temporal_three_node_motifs as local_three_node_rs; -use crate::algorithms::pagerank::unweighted_page_rank; -use crate::algorithms::reciprocity::{ - all_local_reciprocity as all_local_reciprocity_rs, global_reciprocity as global_reciprocity_rs, -}; -use crate::algorithms::temporal_reachability::temporally_reachable_nodes as temporal_reachability_rs; -use crate::core::vertex_ref::VertexRef; -use crate::python::utils::PyInputVertex; use pyo3::prelude::*; /// Local triangle count - calculates the number of triangles (a cycle of length 3) a vertex participates in. diff --git a/raphtory/src/python/graph_gen.rs b/raphtory/src/python/packages/graph_gen.rs similarity index 91% rename from raphtory/src/python/graph_gen.rs rename to raphtory/src/python/packages/graph_gen.rs index 20b7b801a5..cb38b93ed6 100644 --- a/raphtory/src/python/graph_gen.rs +++ b/raphtory/src/python/packages/graph_gen.rs @@ -1,9 +1,13 @@ //! Provides functionality for generating graphs for testing and benchmarking. //! Allows us to generate graphs using the preferential attachment model and //! the random attachment model. -use crate::graphgen::preferential_attachment::ba_preferential_attachment as pa; -use crate::graphgen::random_attachment::random_attachment as ra; -use crate::python::graph::PyGraph; +use crate::{ + graphgen::{ + preferential_attachment::ba_preferential_attachment as pa, + random_attachment::random_attachment as ra, + }, + python::graph::graph::PyGraph, +}; use pyo3::prelude::*; /// Generates a graph using the random attachment model diff --git a/raphtory/src/python/graph_loader.rs b/raphtory/src/python/packages/graph_loader.rs similarity index 96% rename from raphtory/src/python/graph_loader.rs rename to raphtory/src/python/packages/graph_loader.rs index 844c568488..5132338341 100644 --- a/raphtory/src/python/graph_loader.rs +++ b/raphtory/src/python/packages/graph_loader.rs @@ -1,6 +1,6 @@ //! `GraphLoader` provides some default implementations for loading a pre-built graph. //! This base class is used to load in-built graphs such as the LOTR, reddit and StackOverflow. -use crate::python::graph::PyGraph; +use crate::python::graph::graph::PyGraph; use pyo3::prelude::*; use tokio::runtime::Runtime; @@ -73,10 +73,7 @@ pub fn reddit_hyperlink_graph(timeout_seconds: u64) -> PyResult> { #[pyfunction] #[pyo3(signature = (path=None,subset=None))] -pub fn stable_coin_graph( - path: Option, - subset: Option, -) -> PyResult> { +pub fn stable_coin_graph(path: Option, subset: Option) -> PyResult> { PyGraph::py_from_db_graph( crate::graph_loader::example::stable_coins::stable_coin_graph( path, diff --git a/raphtory/src/python/packages/mod.rs b/raphtory/src/python/packages/mod.rs new file mode 100644 index 0000000000..2dae20d460 --- /dev/null +++ b/raphtory/src/python/packages/mod.rs @@ -0,0 +1,3 @@ +pub mod algorithms; +pub mod graph_gen; +pub mod graph_loader; diff --git a/raphtory/src/python/perspective.rs b/raphtory/src/python/perspective.rs deleted file mode 100644 index 89da73496c..0000000000 --- a/raphtory/src/python/perspective.rs +++ /dev/null @@ -1,113 +0,0 @@ -//! This module defines the `PyPerspective` struct and the `PyPerspectiveSet` iterator. -//! -//! `PyPerspective` is a simple struct representing a time range from `start` to `end`. -//! The start time is inclusive and the end time is exclusive. -//! -//! `PyPerspectiveSet` is an iterator over a range of time periods (`Perspective`s). -//! It can be used to generate rolling or expanding perspectives based on a `step` size and an optional `window` size. -//! -//! These perpectives are used when querying the graph to determine the time bounds. -use pyo3::{pyclass, pymethods}; -use raphtory::db::perspective; -use raphtory::db::perspective::PerspectiveSet; -use std::i64; - -/// A struct representing a time range from `start` to `end`. -/// -/// The start time is inclusive and the end time is exclusive. -#[derive(Clone)] -#[pyclass(name = "Perspective")] -pub struct PyPerspective { - pub start: Option, - pub end: Option, -} - -/// Representing a time range from `start` to `end` for a graph -#[pymethods] -impl PyPerspective { - /// Creates a new `Perspective` with the given `start` and `end` times. - /// Arguments: - /// start (int): The start time of the perspective. If None, the perspective will start at the beginning of the graph. - /// end (int): The end time of the perspective. If None, the perspective will end at the end of the graph. - /// - /// Returns: - /// Perspective: A new perspective with the given start and end times. - #[new] - #[pyo3(signature = (start=None, end=None))] - fn new(start: Option, end: Option) -> Self { - PyPerspective { start, end } - } - - /// Creates an `PyPerspectiveSet` with the given `step` size and optional `start` and `end` times, - /// using an expanding window. - /// - /// An expanding window is a window that grows by `step` size at each iteration. - /// - /// Arguments: - /// step (int): The size of the step to take at each iteration. - /// start (int): The start time of the perspective. If None, the perspective will start at the beginning of the graph. (optional) - /// end (int): The end time of the perspective. If None, the perspective will end at the end of the graph. (optional) - /// - /// Returns: - /// PyPerspectiveSet: An iterator over a range of time periods (`Perspective`s). - #[staticmethod] - #[pyo3(signature = (step, start=None, end=None))] - fn expanding(step: u64, start: Option, end: Option) -> PyPerspectiveSet { - PyPerspectiveSet { - ps: perspective::Perspective::expanding(step, start, end), - } - } - - /// Creates an `PerspectiveSet` with the given `window` size and optional `step`, `start` and `end` times, - /// using a rolling window. - /// - /// A rolling window is a window that moves forward by `step` size at each iteration. - /// If `step` is not provided, it defaults to the `window` size. - /// - /// Arguments: - /// window (int): The size of the window to use at each iteration. - /// step (int): The size of the step to take at each iteration. (optional) - /// start (int): The start time of the perspective. If None, the perspective will start at the beginning of the graph. (optional) - /// end (int): The end time of the perspective. If None, the perspective will end at the end of the graph. (optional) - /// - /// Returns: - /// PyPerspectiveSet: An iterator over a range of time periods (`Perspective`s). - #[staticmethod] - #[pyo3(signature = (window, step=None, start=None, end=None))] - fn rolling( - window: u64, - step: Option, - start: Option, - end: Option, - ) -> PyPerspectiveSet { - PyPerspectiveSet { - ps: perspective::Perspective::rolling(window, step, start, end), - } - } -} - -impl From for PyPerspective { - fn from(value: perspective::Perspective) -> Self { - PyPerspective { - start: value.start, - end: value.end, - } - } -} - -impl From for perspective::Perspective { - fn from(value: PyPerspective) -> Self { - perspective::Perspective { - start: value.start, - end: value.end, - } - } -} - -/// A PerspectiveSet represents a set of windows on a timeline, -/// defined by a start, end, step, and window size. -#[pyclass(name = "PerspectiveSet")] -#[derive(Clone)] -pub struct PyPerspectiveSet { - pub(crate) ps: PerspectiveSet, -} diff --git a/raphtory/src/python/types/iterable.rs b/raphtory/src/python/types/iterable.rs index 465bbce7cb..5259d40344 100644 --- a/raphtory/src/python/types/iterable.rs +++ b/raphtory/src/python/types/iterable.rs @@ -1,8 +1,9 @@ -use crate::db::view_api::BoxedIter; -use crate::python::types::repr::{iterator_repr, Repr}; +use crate::{ + db::api::view::BoxedIter, + python::types::repr::{iterator_repr, Repr}, +}; use pyo3::{IntoPy, PyObject}; -use std::marker::PhantomData; -use std::sync::Arc; +use std::{marker::PhantomData, sync::Arc}; pub struct Iterable + From + Repr> { pub name: String, diff --git a/raphtory/src/python/macros/iter.rs b/raphtory/src/python/types/macros/iter.rs similarity index 100% rename from raphtory/src/python/macros/iter.rs rename to raphtory/src/python/types/macros/iter.rs diff --git a/raphtory/src/python/macros/iterable.rs b/raphtory/src/python/types/macros/iterable.rs similarity index 98% rename from raphtory/src/python/macros/iterable.rs rename to raphtory/src/python/types/macros/iterable.rs index 11e634ca07..521cb040cd 100644 --- a/raphtory/src/python/macros/iterable.rs +++ b/raphtory/src/python/types/macros/iterable.rs @@ -9,7 +9,7 @@ macro_rules! _py_numeric_methods { } pub fn mean(&self) -> f64 { - use $crate::python::wrappers::iterators::MeanExt; + use $crate::python::types::wrappers::iterators::MeanExt; self.iter().mean() } } diff --git a/raphtory/src/python/types/macros/mod.rs b/raphtory/src/python/types/macros/mod.rs new file mode 100644 index 0000000000..3576d70acc --- /dev/null +++ b/raphtory/src/python/types/macros/mod.rs @@ -0,0 +1,6 @@ +#[macro_use] +pub mod iter; +#[macro_use] +pub mod iterable; +#[macro_use] +pub mod nested_iterable; diff --git a/raphtory/src/python/macros/nested_iterable.rs b/raphtory/src/python/types/macros/nested_iterable.rs similarity index 100% rename from raphtory/src/python/macros/nested_iterable.rs rename to raphtory/src/python/types/macros/nested_iterable.rs diff --git a/raphtory/src/python/types/mod.rs b/raphtory/src/python/types/mod.rs index 21288e8fdc..713089c41a 100644 --- a/raphtory/src/python/types/mod.rs +++ b/raphtory/src/python/types/mod.rs @@ -1,2 +1,6 @@ +#[macro_use] +pub mod macros; + pub mod iterable; pub mod repr; +pub mod wrappers; diff --git a/raphtory/src/python/wrappers/iterators.rs b/raphtory/src/python/types/wrappers/iterators.rs similarity index 94% rename from raphtory/src/python/wrappers/iterators.rs rename to raphtory/src/python/types/wrappers/iterators.rs index 7129a03c93..2609346726 100644 --- a/raphtory/src/python/wrappers/iterators.rs +++ b/raphtory/src/python/types/wrappers/iterators.rs @@ -1,13 +1,14 @@ -use crate::core as db_c; -use crate::db::view_api::BoxedIter; -use crate::python::types::repr::Repr; -use crate::python::wrappers::prop::{PropHistories, PropHistory, PropValue, Props}; +use crate::{ + core as db_c, + db::api::view::BoxedIter, + python::types::{ + repr::Repr, + wrappers::prop::{PropHistories, PropHistory, PropValue, Props}, + }, +}; use num::cast::AsPrimitive; use pyo3::prelude::*; -use std::collections::HashMap; -use std::i64; -use std::iter::Sum; -use std::ops::Deref; +use std::{collections::HashMap, i64, iter::Sum, ops::Deref}; pub(crate) trait MeanExt: Iterator where diff --git a/raphtory/src/python/wrappers/mod.rs b/raphtory/src/python/types/wrappers/mod.rs similarity index 100% rename from raphtory/src/python/wrappers/mod.rs rename to raphtory/src/python/types/wrappers/mod.rs diff --git a/raphtory/src/python/wrappers/prop.rs b/raphtory/src/python/types/wrappers/prop.rs similarity index 90% rename from raphtory/src/python/wrappers/prop.rs rename to raphtory/src/python/types/wrappers/prop.rs index 59f3955189..51d681b1e3 100644 --- a/raphtory/src/python/wrappers/prop.rs +++ b/raphtory/src/python/types/wrappers/prop.rs @@ -1,8 +1,8 @@ -use crate::core::Prop; -use crate::python::graph_view::PyGraphView; -use crate::python::types::repr::Repr; -use pyo3::exceptions::PyTypeError; -use pyo3::{FromPyObject, IntoPy, PyAny, PyObject, PyResult, Python}; +use crate::{ + core::Prop, + python::{graph::views::graph_view::PyGraphView, types::repr::Repr}, +}; +use pyo3::{exceptions::PyTypeError, FromPyObject, IntoPy, PyAny, PyObject, PyResult, Python}; use std::collections::HashMap; impl IntoPy for Prop { diff --git a/raphtory/src/python/errors.rs b/raphtory/src/python/utils/errors.rs similarity index 75% rename from raphtory/src/python/errors.rs rename to raphtory/src/python/utils/errors.rs index 5895c21eca..7a67443639 100644 --- a/raphtory/src/python/errors.rs +++ b/raphtory/src/python/utils/errors.rs @@ -1,8 +1,8 @@ -use crate::core::errors::GraphError; -use crate::core::time::error::ParseTimeError; -use crate::graph_loader::source::csv_loader::CsvErr; -use pyo3::exceptions::PyException; -use pyo3::PyErr; +use crate::{ + core::utils::{errors::GraphError, time::error::ParseTimeError}, + graph_loader::source::csv_loader::CsvErr, +}; +use pyo3::{exceptions::PyException, PyErr}; use std::error::Error; impl From for PyErr { diff --git a/raphtory/src/python/utils.rs b/raphtory/src/python/utils/mod.rs similarity index 96% rename from raphtory/src/python/utils.rs rename to raphtory/src/python/utils/mod.rs index 678cc2f8f8..3f4a4a2c76 100644 --- a/raphtory/src/python/utils.rs +++ b/raphtory/src/python/utils/mod.rs @@ -2,15 +2,18 @@ //! //! This module contains helper functions for the Python bindings. //! These functions are not part of the public API and are not exported to the Python module. -use crate::core::time::error::ParseTimeError; -use crate::core::time::{Interval, IntoTime, TryIntoTime}; -use crate::core::vertex::InputVertex; -use crate::core::vertex_ref::VertexRef; -use crate::db::view_api::*; -use crate::python::vertex::PyVertex; +use crate::{ + core::{ + entities::vertices::{input_vertex::InputVertex, vertex_ref::VertexRef}, + utils::time::{error::ParseTimeError, Interval, IntoTime, TryIntoTime}, + }, + db::api::view::*, + python::graph::vertex::PyVertex, +}; use chrono::NaiveDateTime; -use pyo3::exceptions::PyTypeError; -use pyo3::prelude::*; +use pyo3::{exceptions::PyTypeError, prelude::*}; + +pub mod errors; /// Extract a `VertexRef` from a Python object. /// The object can be a `str`, `u64` or `PyVertex`.