Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

move input node and hashing code to raphtory-api #1671

Merged
merged 2 commits into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions examples/rust/src/bin/btc/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#![allow(dead_code)]

use chrono::{DateTime, Utc};
use raphtory::{core::utils::hashing, graph_loader::source::csv_loader::CsvLoader, prelude::*};
use raphtory::{graph_loader::source::csv_loader::CsvLoader, prelude::*};
use regex::Regex;
use serde::Deserialize;
use std::{
Expand Down Expand Up @@ -54,7 +54,7 @@ fn main() {
panic!("Missing data dir = {}", data_dir.to_str().unwrap())
}

let test_v = hashing::calculate_hash(&"139eeGkMGR6F9EuJQ3qYoXebfkBbNAsLtV:btc");
let test_v = "139eeGkMGR6F9EuJQ3qYoXebfkBbNAsLtV:btc".id();

// 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
Expand Down Expand Up @@ -82,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 = hashing::calculate_hash(&sent.addr);
let dst = hashing::calculate_hash(&sent.txn);
let src = sent.addr.id();
let dst = sent.txn.id();
let time = sent.time.timestamp();

if src == test_v || dst == test_v {
Expand Down
4 changes: 2 additions & 2 deletions examples/rust/src/bin/lotr/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use raphtory::{
algorithms::pathing::temporal_reachability::temporally_reachable_nodes, core::utils::hashing,
algorithms::pathing::temporal_reachability::temporally_reachable_nodes,
graph_loader::source::csv_loader::CsvLoader, prelude::*,
};
use serde::Deserialize;
Expand Down Expand Up @@ -99,7 +99,7 @@ fn main() {
assert_eq!(graph.count_nodes(), 139);
assert_eq!(graph.count_edges(), 701);

let gandalf = hashing::calculate_hash(&"Gandalf");
let gandalf = "Gandalf".id();

assert_eq!(gandalf, 2760374808085341115);
assert!(graph.has_node(gandalf));
Expand Down
2 changes: 1 addition & 1 deletion pometry-storage-private
4 changes: 4 additions & 0 deletions raphtory-api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ rayon = { workspace = true }
rand = { workspace = true }
quickcheck = { workspace = true }
quickcheck_macros = { workspace = true }
twox-hash.workspace = true

[dev-dependencies]
proptest.workspace = true

[features]
default = []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
//! `u64`, `&str`, and `String`.

use crate::core::utils::hashing;

const MAX_U64_BYTES: [u8; 20] = [
49, 56, 52, 52, 54, 55, 52, 52, 48, 55, 51, 55, 48, 57, 53, 53, 49, 54, 49, 53,
];
Expand Down Expand Up @@ -85,7 +86,7 @@ impl InputNode for String {

#[cfg(test)]
mod test {
use crate::core::entities::nodes::input_node::{parse_u64_strict, InputNode};
use crate::core::input::input_node::{parse_u64_strict, InputNode};
use proptest::prelude::*;

#[test]
Expand All @@ -109,6 +110,8 @@ mod test {
let res = parse_u64_strict(&s);
if let Some(n) = res {
assert_eq!(n.to_string(), s)
} else {
assert_ne!(s.id().to_string(), s)
}
});
}
Expand Down
1 change: 1 addition & 0 deletions raphtory-api/src/core/input/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod input_node;
2 changes: 2 additions & 0 deletions raphtory-api/src/core/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
pub mod entities;
pub mod input;
pub mod storage;
pub mod utils;

/// Denotes the direction of an edge. Can be incoming, outgoing or both.
#[derive(
Expand Down
5 changes: 1 addition & 4 deletions raphtory-api/src/core/storage/dict_mapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,11 @@ impl DictMapper {

#[cfg(test)]
mod test {
use std::{collections::HashMap, sync::Arc, thread};

use crate::core::storage::dict_mapper::DictMapper;
use quickcheck_macros::quickcheck;
use rand::seq::SliceRandom;
use rayon::prelude::*;

use super::*;
use std::collections::HashMap;

#[test]
fn test_dict_mapper() {
Expand Down
10 changes: 10 additions & 0 deletions raphtory-api/src/core/utils/hashing.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//! Utility functions used throughout the modules.

use std::hash::{Hash, Hasher};
use twox_hash::XxHash64;

pub fn calculate_hash<T: Hash + ?Sized>(t: &T) -> u64 {
let mut s = XxHash64::default();
t.hash(&mut s);
s.finish()
}
1 change: 1 addition & 0 deletions raphtory-api/src/core/utils/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod hashing;
5 changes: 1 addition & 4 deletions raphtory-graphql/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,7 @@ mod graphql_test {
prelude::*,
};
use serde_json::json;
use std::{
collections::{HashMap, HashSet},
path::Path,
};
use std::collections::{HashMap, HashSet};
use tempfile::{tempdir, TempDir};

#[tokio::test]
Expand Down
10 changes: 4 additions & 6 deletions raphtory/src/algorithms/pathing/temporal_reachability.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
use crate::{
algorithms::algorithm_result::AlgorithmResult,
core::{
entities::nodes::input_node::InputNode,
state::{
accumulator_id::accumulators::{hash_set, min, or},
compute_state::ComputeStateVec,
},
core::state::{
accumulator_id::accumulators::{hash_set, min, or},
compute_state::ComputeStateVec,
},
db::{
api::view::StaticGraphViewOps,
Expand All @@ -20,6 +17,7 @@ use crate::{
};
use itertools::Itertools;
use num_traits::Zero;
use raphtory_api::core::input::input_node::InputNode;
use std::{collections::HashMap, ops::Add};

#[derive(Eq, Hash, PartialEq, Clone, Debug, Default)]
Expand Down
9 changes: 6 additions & 3 deletions raphtory/src/core/entities/graph/tgraph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::{
tgraph_storage::GraphStorage,
timer::{MaxCounter, MinCounter, TimeCounterTrait},
},
nodes::{input_node::InputNode, node_ref::NodeRef, node_store::NodeStore},
nodes::{node_ref::NodeRef, node_store::NodeStore},
properties::{graph_meta::GraphMeta, props::Meta, tprop::TProp},
LayerIds, EID, VID,
},
Expand All @@ -24,8 +24,11 @@ use crate::{
},
prelude::DeletionOps,
};
use dashmap::{DashMap, DashSet};
use raphtory_api::core::storage::{arc_str::ArcStr, locked_vec::ArcReadLockedVec, FxDashMap};
use dashmap::DashSet;
use raphtory_api::core::{
input::input_node::InputNode,
storage::{arc_str::ArcStr, locked_vec::ArcReadLockedVec, FxDashMap},
};
use rustc_hash::FxHasher;
use serde::{Deserialize, Serialize};
use std::{
Expand Down
1 change: 0 additions & 1 deletion raphtory/src/core/entities/nodes/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
pub mod input_node;
pub mod node_ref;
pub mod node_store;
pub mod structure;
4 changes: 1 addition & 3 deletions raphtory/src/core/entities/properties/props.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,12 @@ use crate::{
},
db::api::storage::tprop_storage_ops::TPropOps,
};
use lock_api;
use parking_lot::RwLock;
use raphtory_api::core::storage::{
arc_str::ArcStr, dict_mapper::DictMapper, locked_vec::ArcReadLockedVec,
};
use serde::{Deserialize, Serialize};
use std::{borrow::Borrow, fmt::Debug, hash::Hash, ops::Deref, sync::Arc};
use std::{fmt::Debug, hash::Hash, ops::Deref, sync::Arc};

#[derive(Serialize, Deserialize, Default, Debug, PartialEq)]
pub struct Props {
Expand Down Expand Up @@ -319,7 +318,6 @@ impl PropMapper {
#[cfg(test)]
mod test {
use super::*;
use rayon::prelude::*;
use std::{sync::Arc, thread};

#[test]
Expand Down
6 changes: 1 addition & 5 deletions raphtory/src/core/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,15 @@ use crate::{
prelude::GraphViewOps,
};
use chrono::{DateTime, NaiveDateTime, Utc};
use raphtory_api::core::storage::arc_str::ArcStr;
use serde::{Deserialize, Serialize};
use serde_json::Value;
use std::{
borrow::Borrow,
cmp::Ordering,
collections::HashMap,
fmt,
fmt::{Display, Formatter},
hash::{Hash, Hasher},
ops::Deref,
sync::Arc,
};

Expand All @@ -53,9 +52,6 @@ pub mod state;
pub mod storage;
pub mod utils;

// this is here because Arc<str> annoyingly doesn't implement all the expected comparisons

use raphtory_api::core::storage::arc_str::ArcStr;
pub use raphtory_api::core::*;

#[derive(Clone, Copy, Debug, Serialize, Deserialize, PartialEq, Hash)]
Expand Down
32 changes: 0 additions & 32 deletions raphtory/src/core/utils/hashing.rs

This file was deleted.

1 change: 0 additions & 1 deletion raphtory/src/core/utils/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
pub mod errors;
pub mod hashing;
pub mod time;
3 changes: 2 additions & 1 deletion raphtory/src/db/api/mutation/addition_ops.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{
core::{
entities::{edges::edge_ref::EdgeRef, nodes::input_node::InputNode},
entities::edges::edge_ref::EdgeRef,
utils::{errors::GraphError, time::IntoTimeWithFormat},
Prop,
},
Expand All @@ -12,6 +12,7 @@ use crate::{
graph::{edge::EdgeView, node::NodeView},
},
};
use raphtory_api::core::input::input_node::InputNode;

use super::time_from_input;

Expand Down
6 changes: 2 additions & 4 deletions raphtory/src/db/api/mutation/deletion_ops.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
use crate::{
core::{
entities::nodes::input_node::InputNode,
utils::{errors::GraphError, time::IntoTimeWithFormat},
},
core::utils::{errors::GraphError, time::IntoTimeWithFormat},
db::api::mutation::{
internal::{InternalAdditionOps, InternalDeletionOps},
TryIntoInputTime,
},
};
use raphtory_api::core::input::input_node::InputNode;

use super::time_from_input;

Expand Down
29 changes: 12 additions & 17 deletions raphtory/src/db/api/storage/edges/edges.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
use super::edge_entry::EdgeStorageEntry;
use crate::{
core::{
entities::{edges::edge_store::EdgeStore, LayerIds, EID},
storage::ReadLockedStorage,
},
db::api::storage::nodes::unlocked::UnlockedEdges,
db::api::storage::{
edges::edge_storage_ops::EdgeStorageOps, nodes::unlocked::UnlockedEdges,
variants::storage_variants3::StorageVariants,
},
};

#[cfg(feature = "storage")]
use crate::disk_graph::storage_interface::edges_ref::DiskEdgesRef;

use super::edge_entry::EdgeStorageEntry;
use crate::db::api::storage::edges::edge_storage_ops::EdgeStorageOps;
#[cfg(feature = "storage")]
use crate::disk_graph::storage_interface::edges::DiskEdges;
use either::Either;
use rayon::iter::ParallelIterator;
use std::sync::Arc;

#[cfg(feature = "storage")]
use crate::disk_graph::storage_interface::{edges::DiskEdges, edges_ref::DiskEdgesRef};

pub enum EdgesStorage {
Mem(Arc<ReadLockedStorage<EdgeStore, EID>>),
#[cfg(feature = "storage")]
Expand All @@ -42,9 +40,6 @@ pub enum EdgesStorageRef<'a> {
Disk(DiskEdgesRef<'a>),
}

#[cfg(feature = "storage")]
use crate::db::api::storage::variants::storage_variants3::StorageVariants;

impl<'a> EdgesStorageRef<'a> {
#[cfg(feature = "storage")]
pub fn iter(self, layers: LayerIds) -> impl Iterator<Item = EdgeStorageEntry<'a>> {
Expand All @@ -70,13 +65,13 @@ impl<'a> EdgesStorageRef<'a> {
#[cfg(not(feature = "storage"))]
pub fn iter(self, layers: LayerIds) -> impl Iterator<Item = EdgeStorageEntry<'a>> {
match self {
EdgesStorageRef::Mem(storage) => Either::Left(
EdgesStorageRef::Mem(storage) => StorageVariants::Mem(
storage
.iter()
.filter(move |e| e.has_layer(&layers))
.map(EdgeStorageEntry::Mem),
),
EdgesStorageRef::Unlocked(edges) => Either::Right(
EdgesStorageRef::Unlocked(edges) => StorageVariants::Unlocked(
edges
.iter()
.filter(move |e| e.has_layer(&layers))
Expand Down Expand Up @@ -109,13 +104,13 @@ impl<'a> EdgesStorageRef<'a> {
#[cfg(not(feature = "storage"))]
pub fn par_iter(self, layers: LayerIds) -> impl ParallelIterator<Item = EdgeStorageEntry<'a>> {
match self {
EdgesStorageRef::Mem(storage) => Either::Left(
EdgesStorageRef::Mem(storage) => StorageVariants::Mem(
storage
.par_iter()
.filter(move |e| e.has_layer(&layers))
.map(EdgeStorageEntry::Mem),
),
EdgesStorageRef::Unlocked(edges) => Either::Right(
EdgesStorageRef::Unlocked(edges) => StorageVariants::Unlocked(
edges
.par_iter()
.filter(move |e| e.has_layer(&layers))
Expand Down
Loading
Loading