Skip to content

Commit

Permalink
Ahash bump - follow up of #46 (#47)
Browse files Browse the repository at this point in the history
* bump ahash crate to fix build

currently, cargo build generates the following error due to the removal
of stdsim: rust-lang/rust#117372

* fix clippy errors

* attempt to fix formatting

* attempt to not parallelize he intersection

* remove rayon prelude

* chore(cargo): update dependencies and modernize crate

* chore(cargo): update lock via cargo update

---------

Co-authored-by: Clément Michaud <clement.michaud34@gmail.com>
  • Loading branch information
yamafaktory and clems4ever authored Nov 19, 2024
1 parent e8be7ca commit be27586
Show file tree
Hide file tree
Showing 55 changed files with 599 additions and 395 deletions.
491 changes: 205 additions & 286 deletions Cargo.lock

Large diffs are not rendered by default.

19 changes: 15 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,26 @@ rust-version = "1.56"
version = "2.1.2"

[dependencies]
ahash = "0.8.3"
indexmap = { version = "2.0.0", features = ["rayon"] }
itertools = "0.11.0"
ahash = "0.8.11"
indexmap = { version = "2.6.0", features = ["rayon"] }
itertools = "0.13.0"
rayon = "1.7.0"
thiserror = "1.0.47"
thiserror = "2.0.3"

[dev-dependencies]
criterion = "0.5.1"

[[bench]]
name = "performance"
harness = false

[lints.rust]
missing_debug_implementations = "warn"
missing_docs = "warn"
nonstandard_style = { level = "deny", priority= -1 }
rust_2021_compatibility = { level = "forbid", priority= -1 }
unreachable_pub = "warn"
unsafe_code = "deny"

[lints.clippy]
all = "deny"
20 changes: 16 additions & 4 deletions benches/performance.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
#![deny(unsafe_code, nonstandard_style)]

use std::fmt::{Display, Formatter, Result};

use criterion::{criterion_group, criterion_main, Criterion};
use hypergraph::{HyperedgeIndex, Hypergraph, VertexIndex};
use std::fmt::{
Display,
Formatter,
Result,
};

use criterion::{
Criterion,
criterion_group,
criterion_main,
};
use hypergraph::{
HyperedgeIndex,
Hypergraph,
VertexIndex,
};
use itertools::Itertools;

static HYPEREDGES: usize = 10_000;
Expand Down
3 changes: 2 additions & 1 deletion rustfmt.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
edition = "2021"
group_imports = "StdExternalCrate"
imports_granularity = "Crate"
imports_layout="Vertical"
use_field_init_shorthand = true
version = "Two"
style_edition = "2024"
5 changes: 4 additions & 1 deletion src/core/bi_hash_map.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use std::{collections::HashMap, fmt::Debug};
use std::{
collections::HashMap,
fmt::Debug,
};

/// Bi-directional hashmap used to store the mapping between the internal
/// unstable indexes - generated by `IndexMap` and `IndexSet` - and the exposed
Expand Down
9 changes: 6 additions & 3 deletions src/core/errors.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use thiserror::Error;

use crate::{HyperedgeIndex, VertexIndex};
use crate::{
HyperedgeIndex,
VertexIndex,
};

/// Enumeration of all the possible errors.
#[derive(Clone, Debug, Eq, Error, PartialEq)]
Expand All @@ -9,7 +12,7 @@ where
V: Copy + Eq,
HE: Copy + Eq,
{
/// Error when a HyperedgeIndex was not found.
/// Error when a `HyperedgeIndex` was not found.
#[error("HyperedgeIndex {0} was not found")]
HyperedgeIndexNotFound(HyperedgeIndex),

Expand Down Expand Up @@ -66,7 +69,7 @@ where
#[error("At least two hyperedges must be provided to be joined")]
HyperedgesInvalidJoin,

/// Error when a VertexIndex was not found.
/// Error when a `VertexIndex` was not found.
#[error("VertexIndex {0} was not found")]
VertexIndexNotFound(VertexIndex),

Expand Down
7 changes: 6 additions & 1 deletion src/core/hyperedges/add_hyperedge.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
use crate::{
errors::HypergraphError, HyperedgeIndex, HyperedgeKey, HyperedgeTrait, Hypergraph, VertexIndex,
HyperedgeIndex,
HyperedgeKey,
HyperedgeTrait,
Hypergraph,
VertexIndex,
VertexTrait,
errors::HypergraphError,
};

impl<V, HE> Hypergraph<V, HE>
Expand Down
7 changes: 6 additions & 1 deletion src/core/hyperedges/add_hyperedge_index.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
use crate::{HyperedgeIndex, HyperedgeTrait, Hypergraph, VertexTrait};
use crate::{
HyperedgeIndex,
HyperedgeTrait,
Hypergraph,
VertexTrait,
};

impl<V, HE> Hypergraph<V, HE>
where
Expand Down
6 changes: 5 additions & 1 deletion src/core/hyperedges/clear_hyperedges.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
use rayon::prelude::*;

use crate::{
bi_hash_map::BiHashMap, errors::HypergraphError, HyperedgeTrait, Hypergraph, VertexTrait,
HyperedgeTrait,
Hypergraph,
VertexTrait,
bi_hash_map::BiHashMap,
errors::HypergraphError,
};

impl<V, HE> Hypergraph<V, HE>
Expand Down
9 changes: 7 additions & 2 deletions src/core/hyperedges/contract_hyperedge_vertices.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@ use itertools::Itertools;
use rayon::prelude::*;

use crate::{
core::utils::are_slices_equal, errors::HypergraphError, HyperedgeIndex, HyperedgeTrait,
Hypergraph, VertexIndex, VertexTrait,
HyperedgeIndex,
HyperedgeTrait,
Hypergraph,
VertexIndex,
VertexTrait,
core::utils::are_slices_equal,
errors::HypergraphError,
};

impl<V, HE> Hypergraph<V, HE>
Expand Down
6 changes: 5 additions & 1 deletion src/core/hyperedges/count_hyperedges.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
use crate::{HyperedgeTrait, Hypergraph, VertexTrait};
use crate::{
HyperedgeTrait,
Hypergraph,
VertexTrait,
};

impl<V, HE> Hypergraph<V, HE>
where
Expand Down
8 changes: 7 additions & 1 deletion src/core/hyperedges/get_hyperedge.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
use crate::{errors::HypergraphError, HyperedgeIndex, HyperedgeTrait, Hypergraph, VertexTrait};
use crate::{
HyperedgeIndex,
HyperedgeTrait,
Hypergraph,
VertexTrait,
errors::HypergraphError,
};

impl<V, HE> Hypergraph<V, HE>
where
Expand Down
7 changes: 6 additions & 1 deletion src/core/hyperedges/get_hyperedge_vertices.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
use crate::{
errors::HypergraphError, HyperedgeIndex, HyperedgeKey, HyperedgeTrait, Hypergraph, VertexIndex,
HyperedgeIndex,
HyperedgeKey,
HyperedgeTrait,
Hypergraph,
VertexIndex,
VertexTrait,
errors::HypergraphError,
};

impl<V, HE> Hypergraph<V, HE>
Expand Down
8 changes: 7 additions & 1 deletion src/core/hyperedges/get_hyperedge_weight.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
use crate::{errors::HypergraphError, HyperedgeIndex, HyperedgeTrait, Hypergraph, VertexTrait};
use crate::{
HyperedgeIndex,
HyperedgeTrait,
Hypergraph,
VertexTrait,
errors::HypergraphError,
};

impl<V, HE> Hypergraph<V, HE>
where
Expand Down
8 changes: 7 additions & 1 deletion src/core/hyperedges/get_hyperedges.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
use rayon::prelude::*;

use crate::{errors::HypergraphError, HyperedgeIndex, HyperedgeTrait, Hypergraph, VertexTrait};
use crate::{
HyperedgeIndex,
HyperedgeTrait,
Hypergraph,
VertexTrait,
errors::HypergraphError,
};

impl<V, HE> Hypergraph<V, HE>
where
Expand Down
9 changes: 7 additions & 2 deletions src/core/hyperedges/get_hyperedges_connecting.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
use rayon::prelude::*;

use crate::{
core::shared::Connection, errors::HypergraphError, HyperedgeIndex, HyperedgeTrait, Hypergraph,
VertexIndex, VertexTrait,
HyperedgeIndex,
HyperedgeTrait,
Hypergraph,
VertexIndex,
VertexTrait,
core::shared::Connection,
errors::HypergraphError,
};

impl<V, HE> Hypergraph<V, HE>
Expand Down
10 changes: 7 additions & 3 deletions src/core/hyperedges/get_hyperedges_intersections.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
use itertools::Itertools;
use rayon::prelude::*;

use crate::{
errors::HypergraphError, HyperedgeIndex, HyperedgeKey, HyperedgeTrait, Hypergraph, VertexIndex,
HyperedgeIndex,
HyperedgeKey,
HyperedgeTrait,
Hypergraph,
VertexIndex,
VertexTrait,
errors::HypergraphError,
};

impl<V, HE> Hypergraph<V, HE>
Expand All @@ -26,7 +30,7 @@ where

// Get the internal vertices of the hyperedges and keep the eventual error.
let vertices = hyperedges
.into_par_iter()
.into_iter()
.map(|hyperedge_index| {
self.get_internal_hyperedge(hyperedge_index)
.and_then(|internal_index| {
Expand Down
8 changes: 7 additions & 1 deletion src/core/hyperedges/get_internal_hyperedge.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
use crate::{errors::HypergraphError, HyperedgeIndex, HyperedgeTrait, Hypergraph, VertexTrait};
use crate::{
HyperedgeIndex,
HyperedgeTrait,
Hypergraph,
VertexTrait,
errors::HypergraphError,
};

impl<V, HE> Hypergraph<V, HE>
where
Expand Down
8 changes: 7 additions & 1 deletion src/core/hyperedges/get_internal_hyperedges.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
use crate::{errors::HypergraphError, HyperedgeIndex, HyperedgeTrait, Hypergraph, VertexTrait};
use crate::{
HyperedgeIndex,
HyperedgeTrait,
Hypergraph,
VertexTrait,
errors::HypergraphError,
};

impl<V, HE> Hypergraph<V, HE>
where
Expand Down
7 changes: 6 additions & 1 deletion src/core/hyperedges/join_hyperedges.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
use rayon::prelude::*;

use crate::{
errors::HypergraphError, HyperedgeIndex, HyperedgeTrait, Hypergraph, VertexIndex, VertexTrait,
HyperedgeIndex,
HyperedgeTrait,
Hypergraph,
VertexIndex,
VertexTrait,
errors::HypergraphError,
};

impl<V, HE> Hypergraph<V, HE>
Expand Down
11 changes: 8 additions & 3 deletions src/core/hyperedges/remove_hyperedge.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
use crate::{
errors::HypergraphError, HyperedgeIndex, HyperedgeKey, HyperedgeTrait, Hypergraph, VertexTrait,
HyperedgeIndex,
HyperedgeKey,
HyperedgeTrait,
Hypergraph,
VertexTrait,
errors::HypergraphError,
};

impl<V, HE> Hypergraph<V, HE>
Expand Down Expand Up @@ -33,7 +38,7 @@ where
for vertex in vertices {
match self.vertices.get_index_mut(vertex) {
Some((_, index_set)) => {
index_set.remove(&internal_index);
index_set.swap_remove(&internal_index);
}
None => return Err(HypergraphError::InternalVertexIndexNotFound(vertex)),
}
Expand Down Expand Up @@ -113,7 +118,7 @@ where
// Perform an insertion of the current hyperedge and a
// removal of the swapped one.
index_set.insert(internal_index);
index_set.remove(&last_index);
index_set.swap_remove(&last_index);
}
None => return Err(HypergraphError::InternalVertexIndexNotFound(vertex)),
}
Expand Down
8 changes: 7 additions & 1 deletion src/core/hyperedges/reverse_hyperedge.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
use rayon::prelude::*;

use crate::{errors::HypergraphError, HyperedgeIndex, HyperedgeTrait, Hypergraph, VertexTrait};
use crate::{
HyperedgeIndex,
HyperedgeTrait,
Hypergraph,
VertexTrait,
errors::HypergraphError,
};

impl<V, HE> Hypergraph<V, HE>
where
Expand Down
10 changes: 8 additions & 2 deletions src/core/hyperedges/update_hyperedge_vertices.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
use rayon::prelude::*;

use crate::{
core::utils::are_slices_equal, errors::HypergraphError, HyperedgeIndex, HyperedgeKey,
HyperedgeTrait, Hypergraph, VertexIndex, VertexTrait,
HyperedgeIndex,
HyperedgeKey,
HyperedgeTrait,
Hypergraph,
VertexIndex,
VertexTrait,
core::utils::are_slices_equal,
errors::HypergraphError,
};

impl<V, HE> Hypergraph<V, HE>
Expand Down
7 changes: 6 additions & 1 deletion src/core/hyperedges/update_hyperedge_weight.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
use crate::{
errors::HypergraphError, HyperedgeIndex, HyperedgeKey, HyperedgeTrait, Hypergraph, VertexTrait,
HyperedgeIndex,
HyperedgeKey,
HyperedgeTrait,
Hypergraph,
VertexTrait,
errors::HypergraphError,
};

impl<V, HE> Hypergraph<V, HE>
Expand Down
6 changes: 5 additions & 1 deletion src/core/indexes.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
use std::fmt::{Display, Formatter, Result};
use std::fmt::{
Display,
Formatter,
Result,
};

/// Vertex stable index representation as usize.
/// Uses the newtype index pattern.
Expand Down
8 changes: 7 additions & 1 deletion src/core/iterator.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
use rayon::prelude::*;

use crate::{errors::HypergraphError, HyperedgeKey, HyperedgeTrait, Hypergraph, VertexTrait};
use crate::{
HyperedgeKey,
HyperedgeTrait,
Hypergraph,
VertexTrait,
errors::HypergraphError,
};

impl<V, HE> IntoIterator for Hypergraph<V, HE>
where
Expand Down
Loading

0 comments on commit be27586

Please sign in to comment.