Skip to content
Open
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
1 change: 1 addition & 0 deletions clam-core
Submodule clam-core added at 5e10a7
1 change: 1 addition & 0 deletions optd
Submodule optd added at 409900
1 change: 1 addition & 0 deletions python/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ raphtory = { workspace = true, features = [
raphtory-graphql = { workspace = true, features = [
"python",
] }
clam-core = { workspace = true, features = ["python"] }

[features]
extension-module = ["pyo3/extension-module"]
Expand Down
1 change: 1 addition & 0 deletions python/python/raphtory/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
_sys.modules["raphtory.graph_loader"] = graph_loader
_sys.modules["raphtory.vectors"] = vectors
_sys.modules["raphtory.graphql"] = graphql
_sys.modules["raphtory.gql"] = gql
_sys.modules["raphtory.filter"] = filter
_sys.modules["raphtory.iterables"] = iterables

Expand Down
3 changes: 3 additions & 0 deletions python/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ use raphtory::python::{
},
};
use raphtory_graphql::python::pymodule::base_graphql_module;
use clam_core::python::py_gql::base_gql_module;

/// Raphtory graph analytics library
#[pymodule]
fn _raphtory(py: Python<'_>, m: &Bound<PyModule>) -> PyResult<()> {
let _ = add_raphtory_classes(m);

let graphql_module = base_graphql_module(py)?;
let gql_module = base_gql_module(py)?;
let algorithm_module = base_algorithm_module(py)?;
let graph_loader_module = base_graph_loader_module(py)?;
let graph_gen_module = base_graph_gen_module(py)?;
Expand All @@ -23,6 +25,7 @@ fn _raphtory(py: Python<'_>, m: &Bound<PyModule>) -> PyResult<()> {
let filter_module = base_filter_module(py)?;
let iterables = base_iterables_module(py)?;
m.add_submodule(&graphql_module)?;
m.add_submodule(&gql_module)?;
m.add_submodule(&algorithm_module)?;
m.add_submodule(&graph_loader_module)?;
m.add_submodule(&graph_gen_module)?;
Expand Down
12 changes: 12 additions & 0 deletions raphtory-itertools/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[package]
name = "raphtory-itertools"
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
3 changes: 3 additions & 0 deletions raphtory-itertools/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
mod take;

pub use take::{ReTake, TakeExt};
136 changes: 136 additions & 0 deletions raphtory-itertools/src/take.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
use std::{cmp, iter::FusedIterator};

/// An iterator that only iterates over the first `n` iterations of `iter`.
#[derive(Clone, Debug)]
#[must_use = "iterators are lazy and do nothing unless consumed"]
pub struct ReTake<I> {
iter: I,
n: usize,
}

pub trait TakeExt: Sized {
fn take_updatable(self, n: usize) -> ReTake<Self>;
}

impl<I: Iterator> TakeExt for I {
fn take_updatable(self, n: usize) -> ReTake<Self> {
ReTake { iter: self, n }
}
}

impl<I: Iterator> ReTake<I> {
/// Take the first n elements of the iterator by updating the current take
pub fn take_inplace(&mut self, n: usize) {
self.n = self.n.min(n);
}

/// Advance the iterator by n elements
pub fn advance_by(&mut self, n: usize) {
if let Some(to_skip) = n.min(self.n).checked_sub(1) {
self.iter.nth(to_skip);
}
self.n = self.n.saturating_sub(n);
}
}

impl<I> Iterator for ReTake<I>
where
I: Iterator,
{
type Item = <I as Iterator>::Item;

#[inline]
fn next(&mut self) -> Option<<I as Iterator>::Item> {
if self.n != 0 {
self.n -= 1;
self.iter.next()
} else {
None
}
}

#[inline]
fn nth(&mut self, n: usize) -> Option<I::Item> {
if self.n > n {
self.n -= n + 1;
self.iter.nth(n)
} else {
if self.n > 0 {
self.iter.nth(self.n - 1);
self.n = 0;
}
None
}
}

#[inline]
fn size_hint(&self) -> (usize, Option<usize>) {
if self.n == 0 {
return (0, Some(0));
}

let (lower, upper) = self.iter.size_hint();

let lower = cmp::min(lower, self.n);

let upper = match upper {
Some(x) if x < self.n => Some(x),
_ => Some(self.n),
};

(lower, upper)
}
}

impl<I> DoubleEndedIterator for ReTake<I>
where
I: DoubleEndedIterator + ExactSizeIterator,
{
#[inline]
fn next_back(&mut self) -> Option<Self::Item> {
if self.n == 0 {
None
} else {
let n = self.n;
self.n -= 1;
self.iter.nth_back(self.iter.len().saturating_sub(n))
}
}

#[inline]
fn nth_back(&mut self, n: usize) -> Option<Self::Item> {
let len = self.iter.len();
if self.n > n {
let m = len.saturating_sub(self.n) + n;
self.n -= n + 1;
self.iter.nth_back(m)
} else {
if len > 0 {
self.iter.nth_back(len - 1);
}
None
}
}

#[inline]
fn rfold<Acc, Fold>(mut self, init: Acc, fold: Fold) -> Acc
where
Self: Sized,
Fold: FnMut(Acc, Self::Item) -> Acc,
{
if self.n == 0 {
init
} else {
let len = self.iter.len();
if len > self.n && self.iter.nth_back(len - self.n - 1).is_none() {
init
} else {
self.iter.rfold(init, fold)
}
}
}
}

impl<I> ExactSizeIterator for ReTake<I> where I: ExactSizeIterator {}

impl<I> FusedIterator for ReTake<I> where I: FusedIterator {}
2 changes: 1 addition & 1 deletion ui-tests
Submodule ui-tests updated 104 files
Loading