Skip to content

Commit

Permalink
move minimal structs into raphtory-api
Browse files Browse the repository at this point in the history
  • Loading branch information
fabianmurariu committed May 24, 2024
1 parent 0fc1fe2 commit 85f3869
Show file tree
Hide file tree
Showing 33 changed files with 861 additions and 309 deletions.
57 changes: 57 additions & 0 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ members = [
"examples/netflow",
"python",
"js-raphtory",
"raphtory-graphql",
"raphtory-graphql", "raphtory-api",
]
default-members = ["raphtory"]
resolver = "2"
Expand Down
18 changes: 18 additions & 0 deletions raphtory-api/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[package]
name = "raphtory-api"
version.workspace = true
documentation.workspace = true
repository.workspace = true
license.workspace = true
readme.workspace = true
homepage.workspace = true
keywords.workspace = true
authors.workspace = true
rust-version.workspace = true
edition.workspace = true

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
serde = { workspace = true, features = ["derive"] }
chrono.workspace = true
1 change: 1 addition & 0 deletions raphtory-api/src/core/entities/edges/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod edge_ref;
87 changes: 87 additions & 0 deletions raphtory-api/src/core/entities/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
use serde::{Deserialize, Serialize};

use self::edges::edge_ref::EdgeRef;

pub mod edges;

// the only reason this is public is because the physical ids of the nodes don't move
#[repr(transparent)]
#[derive(
Copy, Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, Deserialize, Serialize, Default,
)]
pub struct VID(pub usize);

impl VID {
pub fn index(&self) -> usize {
self.0
}

pub fn as_u64(&self) -> u64 {
self.0 as u64
}
}

impl From<usize> for VID {
fn from(id: usize) -> Self {
VID(id)
}
}

impl From<VID> for usize {
fn from(id: VID) -> Self {
id.0
}
}

#[repr(transparent)]
#[derive(
Copy, Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, Deserialize, Serialize, Default,
)]
pub struct EID(pub usize);

impl From<EID> for usize {
fn from(id: EID) -> Self {
id.0
}
}

impl From<usize> for EID {
fn from(id: usize) -> Self {
EID(id)
}
}

#[derive(
Copy, Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, Deserialize, Serialize, Default,
)]
pub struct ELID {
edge: EID,
layer: Option<usize>,
}

impl ELID {
pub fn new(edge: EID, layer: Option<usize>) -> Self {
Self { edge, layer }
}
pub fn pid(&self) -> EID {
self.edge
}

pub fn layer(&self) -> Option<usize> {
self.layer
}
}

impl From<EdgeRef> for ELID {
fn from(value: EdgeRef) -> Self {
ELID {
edge: value.pid(),
layer: value.layer().copied(),
}
}
}
impl EID {
pub fn from_u64(id: u64) -> Self {
EID(id as usize)
}
}
22 changes: 22 additions & 0 deletions raphtory-api/src/core/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
pub mod entities;
pub mod storage;

/// Denotes the direction of an edge. Can be incoming, outgoing or both.
#[derive(
Clone,
Copy,
Hash,
Eq,
PartialEq,
PartialOrd,
Debug,
Default,
serde::Serialize,
serde::Deserialize,
)]
pub enum Direction {
OUT,
IN,
#[default]
BOTH,
}
1 change: 1 addition & 0 deletions raphtory-api/src/core/storage/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod timeindex;
78 changes: 78 additions & 0 deletions raphtory-api/src/core/storage/timeindex.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
use std::{fmt, ops::Range};

use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};

#[derive(Debug, Copy, Clone, Serialize, Deserialize, PartialEq, Ord, PartialOrd, Eq)]
pub struct TimeIndexEntry(pub i64, pub usize);

pub trait AsTime: fmt::Debug + Copy + Ord + Eq + Send + Sync + 'static {
fn t(&self) -> i64;

fn dt(&self) -> Option<DateTime<Utc>> {
let t = self.t();
DateTime::from_timestamp_millis(t)
}

fn range(w: Range<i64>) -> Range<Self>;

fn i(&self) -> usize {
0
}

fn new(t: i64, s: usize) -> Self;
}

impl From<i64> for TimeIndexEntry {
fn from(value: i64) -> Self {
Self::start(value)
}
}

impl TimeIndexEntry {
pub const MIN: TimeIndexEntry = TimeIndexEntry(i64::MIN, 0);

pub const MAX: TimeIndexEntry = TimeIndexEntry(i64::MAX, usize::MAX);
pub fn new(t: i64, s: usize) -> Self {
Self(t, s)
}

pub fn start(t: i64) -> Self {
Self(t, 0)
}

pub fn end(t: i64) -> Self {
Self(t.saturating_add(1), 0)
}
}

impl AsTime for i64 {
fn t(&self) -> i64 {
*self
}

fn range(w: Range<i64>) -> Range<Self> {
w
}

fn new(t: i64, _s: usize) -> Self {
t
}
}

impl AsTime for TimeIndexEntry {
fn t(&self) -> i64 {
self.0
}
fn range(w: Range<i64>) -> Range<Self> {
Self::start(w.start)..Self::start(w.end)
}

fn i(&self) -> usize {
self.1
}

fn new(t: i64, s: usize) -> Self {
Self(t, s)
}
}
1 change: 1 addition & 0 deletions raphtory-api/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod core;
42 changes: 42 additions & 0 deletions raphtory-arrow/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,46 @@
[package]
name = "raphtory-arrow"
version = "0.8.1"
documentation = "https://raphtory.readthedocs.io/en/latest/"
repository = "https://github.com/Raphtory/raphtory-arrow/"
license = "GPL-3.0"
readme = "README.md"
homepage = "https://github.com/Raphtory/raphtory-arrow/"
keywords = ["graph", "temporal-graph", "temporal"]
authors = ["Pometry"]
rust-version = "1.77"
edition = "2021"

[profile.release-with-debug]
inherits = "release"
debug = true


# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
raphtory-api = { path = "../raphtory-api", version = "0.8.1" }
ahash = { version = "0.8", features = ["serde"] }
bincode = "1.3.3"
bytemuck = "1.16.0"
itertools = "0.12.1"
memmap2 = "0.9.4"
num-traits = "0.2.19"
once_cell = "1.19.0"
parking_lot = "0.12.2"
polars-arrow = "0.39.2"
polars-parquet = { version = "0.39.2", features = ["compression"] }
polars-utils = "0.39.2"
rayon = "1.10.0"
serde = "1.0.201"
serde_json = "1.0.117"
strum = { version = "0.26.2", features = ["derive"] }
tempfile = "3.10.1"
thiserror = "1.0.60"
tracing = "0.1.40"
tracing-subscriber = "0.3.18"
twox-hash = "1.6.3"

[dev-dependencies]
proptest = "1.4.0"
tracing-test = "0.2.4"
Loading

0 comments on commit 85f3869

Please sign in to comment.