1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
use Hash;
use HashMap;
use crateCoding;
// Returns `conf` if it is greater than `0`, or `max(1, available parallelism + conf)` otherwise.
/*pub fn threads_count(conf: isize) -> NonZeroUsize {
if conf > 0 {
unsafe { NonZeroUsize::new_unchecked(conf as usize) }
} else {
unsafe { available_parallelism().map_or(NonZeroUsize::new_unchecked(1), |v| {
NonZeroUsize::new_unchecked(v.get().saturating_sub((-conf) as usize).max(1))
}) }
}
}*/
// Calls `f` in `threads_count` threads and returns vector of `threads_count` results returned by the callings.
/*pub fn threads_run<F, T>(threads_count: NonZeroUsize, mut f: F) -> std::thread::Result<Vec<T>>
where F: FnMut() -> T + Send + Clone, T: Send {
thread::scope(|scope| {
let mut extra_results = Vec::<ScopedJoinHandle::<T>>::with_capacity(threads_count.get()-1);
for _ in 0..threads_count.get() - 1 {
let mut f_clone = f.clone();
extra_results.push(scope.spawn(move |_| { f_clone() }));
}
let mut results = Vec::with_capacity(threads_count.get());
results.push(f());
for e in extra_results {
results.push(e.join().unwrap());
}
results
})
}*/
/// Encodes all `values` using `value_coding`.
/// Returns pair that consists of: values fragments and their sizes.