Skip to content
This repository has been archived by the owner on Mar 25, 2024. It is now read-only.

Commit

Permalink
immutable iteration for parallel access
Browse files Browse the repository at this point in the history
  • Loading branch information
dginev committed Apr 16, 2019
1 parent 83956c5 commit 9ddc453
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion examples/corpus_node_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ pub fn main() -> Result<(), Error> {
node_model_file,
)));

let mut corpus = Corpus::new(corpus_path);
let corpus = Corpus::new(corpus_path);
let total_counts = corpus.catalog_with_parallel_walk(|document| {
// Recursively descend the dom DFS and record to the token model
let mut total_counts = HashMap::new();
Expand Down
2 changes: 1 addition & 1 deletion examples/corpus_token_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ pub fn main() {
// Integers, floats, subfigure numbers
let is_numeric = Regex::new(r"^-?(?:\d+)(?:[a-k]|(?:\.\d+(?:[eE][+-]?\d+)?))?$").unwrap();

let mut corpus = Corpus::new(corpus_path);
let corpus = Corpus::new(corpus_path);
let corpus_counts = corpus.catalog_with_parallel_walk(|document| {
let (
mut sentence_count,
Expand Down
2 changes: 1 addition & 1 deletion examples/pre_ref_words.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pub fn main() -> Result<(), Error> {

let node_statistics_file = File::create(node_statistics_filepath)?;

let mut corpus = Corpus::new(corpus_path);
let corpus = Corpus::new(corpus_path);

let catalog = corpus.catalog_with_parallel_walk(|document| {
println!(
Expand Down
2 changes: 1 addition & 1 deletion src/parallel_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ impl Corpus {
}

/// Get a parallel iterator over the documents
pub fn catalog_with_parallel_walk<F>(&mut self, closure: F) -> HashMap<String, u64>
pub fn catalog_with_parallel_walk<F>(&self, closure: F) -> HashMap<String, u64>
where
F: Fn(Document) -> HashMap<String, u64> + Send + Sync,
{
Expand Down
4 changes: 2 additions & 2 deletions tests/parallel_test.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use llamapun::parallel_data::Corpus;
use std::collections::HashMap;
use llamapun::parallel_data::{Corpus};

#[test]
fn can_iterate_corpus() {
let mut corpus = Corpus::new("tests".to_string());
let corpus = Corpus::new("tests".to_string());
let catalog = corpus.catalog_with_parallel_walk(|document| {
let mut thread_count = HashMap::new();
thread_count.insert(String::from("doc_count"), 1);
Expand Down

0 comments on commit 9ddc453

Please sign in to comment.