Skip to content

Commit f37b719

Browse files
committed
added map
1 parent 2fb0816 commit f37b719

1 file changed

Lines changed: 11 additions & 4 deletions

File tree

source/code2text/src/main.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
/*
22
3+
code2text - generate random words from text files or source code
4+
35
use:
46
57
-i filename.txt
@@ -139,17 +141,21 @@ fn gen_words(
139141
}
140142
}
141143
}
144+
let num_lines = lines.len();
142145
let v: Vec<String> = Vec::new();
146+
let map: HashMap<String, bool> = HashMap::new();
147+
143148
let data = Arc::new(Mutex::new(v));
149+
let map_data = Arc::new(Mutex::new(map));
144150

145151
lines.into_par_iter().for_each(|line| {
146152
let mut v = data.lock().unwrap();
153+
let mut map = map_data.lock().unwrap();
147154

148155
let mut scan: Scanner = Scanner::new(&line);
149156
let mut counter = 0;
150157

151-
let mut map: HashMap<String, bool> = HashMap::new();
152-
loop {
158+
loop {
153159
let token_result = scan.scan_token();
154160
match token_result {
155161
ScanResult::Error => {
@@ -213,8 +219,9 @@ fn gen_words(
213219
let mut v = data.lock().unwrap();
214220

215221
println!(
216-
"code2text: scanning finished gathered {} tokens for pool, generating words...",
217-
v.len()
222+
"code2text: scanning finished gathered {} tokens for pool out of {} lines, generating words...",
223+
v.len(),
224+
num_lines
218225
);
219226
if v.len() < num {
220227
panic!("Not enough words");

0 commit comments

Comments
 (0)