Skip to content

Commit

Permalink
Add Clone trait
Browse files Browse the repository at this point in the history
  • Loading branch information
automainint committed Jul 16, 2024
1 parent f1f2e38 commit 5a83c79
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/rank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ pub enum Neighbors {
Negative,
}

#[derive(Clone)]
pub struct MeritRank<NodeData: Copy + Default> {
pub graph: Graph<NodeData>,
walks: WalkStorage,
Expand Down
3 changes: 2 additions & 1 deletion src/walk_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ use rand::prelude::*;

use integer_hasher::IntMap;

use crate::constants::{OPTIMIZE_INVALIDATION};
use crate::constants::OPTIMIZE_INVALIDATION;
use crate::graph::{NodeId, EdgeId, Weight};
use crate::random_walk::RandomWalk;

pub type WalkId = usize;

/// Represents a storage container for walks in the MeritRank graph.
#[derive(Clone)]
pub struct WalkStorage {
visits: IntMap<NodeId, IntMap<WalkId, usize>>,
walks: Vec<RandomWalk>,
Expand Down
30 changes: 30 additions & 0 deletions tests/test_meritrank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,36 @@ mod tests {
}
}

#[test]
fn test_clone_basic_chain_graph() {
let mut rank_ref = MeritRank::new(Graph::<()>::new()).unwrap();
rank_ref.add_node(0, ());
let walk_count = 10000;

let mut rank = MeritRank::new(Graph::<()>::new()).unwrap();
rank.add_node(0, ());
rank.calculate(0, walk_count).unwrap();
for n in 1..8
{
rank_ref.add_node(n, ());
rank_ref.add_edge(n-1, n, 1.0);
rank.add_node(n, ());
rank.add_edge(n-1, n, 1.0);

}
rank_ref.add_edge(8,1, 1.0);
rank.add_edge(8,1, 1.0);
let cloned = rank.clone();
rank_ref.calculate(0, walk_count).unwrap();
println! ("{:?}", cloned.get_ranks(0, None));
for n in 1..8
{
let ref_score = rank_ref.get_node_score(0, n).unwrap() as f64;
let score = cloned.get_node_score(0, n).unwrap() as f64;
assert_approx_eq!(ref_score, score , 0.1);
}
}

#[test]
fn test_too_early_cut_position_bug() {

Expand Down

0 comments on commit 5a83c79

Please sign in to comment.