Skip to content
Snippets Groups Projects
Commit 131c9f44 authored by dvermd's avatar dvermd
Browse files

[fix] wot:operations: #134 remove unwrap and deny its use

parent 93160d60
No related branches found
No related tags found
1 merge request!244Resolve "Reliability: remove all "unwrap()" and deny their use"
...@@ -27,6 +27,8 @@ ...@@ -27,6 +27,8 @@
//! [js-tests]: https://github.com/duniter/wot/blob/master/wotcpp/webOfTrust.cpp //! [js-tests]: https://github.com/duniter/wot/blob/master/wotcpp/webOfTrust.cpp
#![deny( #![deny(
clippy::option_unwrap_used,
clippy::result_unwrap_used,
missing_docs, missing_docs,
missing_debug_implementations, missing_debug_implementations,
missing_copy_implementations, missing_copy_implementations,
......
...@@ -50,8 +50,7 @@ impl<T: WebOfTrust> CentralitiesCalculator<T> for UlrikBrandesCentralityCalculat ...@@ -50,8 +50,7 @@ impl<T: WebOfTrust> CentralitiesCalculator<T> for UlrikBrandesCentralityCalculat
sigma[s.0] = 1.0; sigma[s.0] = 1.0;
d[s.0] = 0; d[s.0] = 0;
q.push_back(s); q.push_back(s);
while !q.is_empty() { while let Some(v) = q.pop_front() {
let v = q.pop_front().unwrap();
stack.push(v); stack.push(v);
for w in wot.get_links_source(v).expect("v don't have any source !") { for w in wot.get_links_source(v).expect("v don't have any source !") {
// w found for the first time ? // w found for the first time ?
...@@ -68,8 +67,7 @@ impl<T: WebOfTrust> CentralitiesCalculator<T> for UlrikBrandesCentralityCalculat ...@@ -68,8 +67,7 @@ impl<T: WebOfTrust> CentralitiesCalculator<T> for UlrikBrandesCentralityCalculat
} }
let mut delta = vec![0.0; wot_size]; let mut delta = vec![0.0; wot_size];
// stack returns vertices in order of non-increasing distance from s // stack returns vertices in order of non-increasing distance from s
while !stack.is_empty() { while let Some(w) = stack.pop() {
let w = stack.pop().unwrap();
if paths.contains_key(&w) { if paths.contains_key(&w) {
for v in paths.get(&w).expect("Not found w in p !") { for v in paths.get(&w).expect("Not found w in p !") {
if enabled_nodes.contains(&w) { if enabled_nodes.contains(&w) {
...@@ -103,8 +101,7 @@ impl<T: WebOfTrust> CentralitiesCalculator<T> for UlrikBrandesCentralityCalculat ...@@ -103,8 +101,7 @@ impl<T: WebOfTrust> CentralitiesCalculator<T> for UlrikBrandesCentralityCalculat
sigma[s.0] = 1.0; sigma[s.0] = 1.0;
d[s.0] = 0; d[s.0] = 0;
q.push_back(s); q.push_back(s);
while !q.is_empty() { while let Some(v) = q.pop_front() {
let v = q.pop_front().unwrap();
stack.push(v); stack.push(v);
for w in wot.get_links_source(v).expect("v don't have any source !") { for w in wot.get_links_source(v).expect("v don't have any source !") {
// w found for the first time ? // w found for the first time ?
...@@ -121,8 +118,7 @@ impl<T: WebOfTrust> CentralitiesCalculator<T> for UlrikBrandesCentralityCalculat ...@@ -121,8 +118,7 @@ impl<T: WebOfTrust> CentralitiesCalculator<T> for UlrikBrandesCentralityCalculat
} }
let mut delta = vec![0.0; wot_size]; let mut delta = vec![0.0; wot_size];
// stack returns vertices in order of non-increasing distance from s // stack returns vertices in order of non-increasing distance from s
while !stack.is_empty() { while let Some(w) = stack.pop() {
let w = stack.pop().unwrap();
if paths.contains_key(&w) { if paths.contains_key(&w) {
for v in paths.get(&w).expect("Not found w in p !") { for v in paths.get(&w).expect("Not found w in p !") {
if enabled_nodes.contains(&w) { if enabled_nodes.contains(&w) {
...@@ -156,8 +152,7 @@ impl<T: WebOfTrust> CentralitiesCalculator<T> for UlrikBrandesCentralityCalculat ...@@ -156,8 +152,7 @@ impl<T: WebOfTrust> CentralitiesCalculator<T> for UlrikBrandesCentralityCalculat
sigma[s.0] = 1.0; sigma[s.0] = 1.0;
d[s.0] = 0; d[s.0] = 0;
q.push_back(s); q.push_back(s);
while !q.is_empty() { while let Some(v) = q.pop_front() {
let v = q.pop_front().unwrap();
stack.push(v); stack.push(v);
if d[v.0] < step_max as isize { if d[v.0] < step_max as isize {
for w in wot.get_links_source(v).expect("v don't have any source !") { for w in wot.get_links_source(v).expect("v don't have any source !") {
...@@ -176,8 +171,7 @@ impl<T: WebOfTrust> CentralitiesCalculator<T> for UlrikBrandesCentralityCalculat ...@@ -176,8 +171,7 @@ impl<T: WebOfTrust> CentralitiesCalculator<T> for UlrikBrandesCentralityCalculat
} }
let mut delta = vec![0.0; wot_size]; let mut delta = vec![0.0; wot_size];
// stack returns vertices in order of non-increasing distance from s // stack returns vertices in order of non-increasing distance from s
while !stack.is_empty() { while let Some(w) = stack.pop() {
let w = stack.pop().unwrap();
if paths.contains_key(&w) { if paths.contains_key(&w) {
for v in paths.get(&w).expect("Not found w in p !") { for v in paths.get(&w).expect("Not found w in p !") {
if enabled_nodes.contains(&w) { if enabled_nodes.contains(&w) {
......
...@@ -97,7 +97,7 @@ impl<T: WebOfTrust + Sync> DistanceCalculator<T> for RustyDistanceCalculator { ...@@ -97,7 +97,7 @@ impl<T: WebOfTrust + Sync> DistanceCalculator<T> for RustyDistanceCalculator {
.par_iter() .par_iter()
.map(|&id| { .map(|&id| {
wot.get_links_source(id) wot.get_links_source(id)
.unwrap() .expect("get_links_source must return a value")
.iter() .iter()
.filter(|source| !area.contains(source)) .filter(|source| !area.contains(source))
.cloned() .cloned()
...@@ -116,7 +116,10 @@ impl<T: WebOfTrust + Sync> DistanceCalculator<T> for RustyDistanceCalculator { ...@@ -116,7 +116,10 @@ impl<T: WebOfTrust + Sync> DistanceCalculator<T> for RustyDistanceCalculator {
let mut success = area.iter().filter(|n| sentries.contains(n)).count() as u32; let mut success = area.iter().filter(|n| sentries.contains(n)).count() as u32;
let success_at_border = border.iter().filter(|n| sentries.contains(n)).count() as u32; let success_at_border = border.iter().filter(|n| sentries.contains(n)).count() as u32;
let mut sentries = sentries.len() as u32; let mut sentries = sentries.len() as u32;
if wot.is_sentry(node, sentry_requirement as usize).unwrap() { if wot
.is_sentry(node, sentry_requirement as usize)
.expect("is_sentry must return a value")
{
sentries -= 1; sentries -= 1;
success -= 1; success -= 1;
} }
......
...@@ -52,7 +52,10 @@ impl<T: WebOfTrust> PathFinder<T> for RustyPathFinder { ...@@ -52,7 +52,10 @@ impl<T: WebOfTrust> PathFinder<T> for RustyPathFinder {
let mut next_border = HashSet::new(); let mut next_border = HashSet::new();
for node in border { for node in border {
for source in &wot.get_links_source(node).unwrap() { for source in &wot
.get_links_source(node)
.expect("links source must not be None")
{
match graph[source.0].0 { match graph[source.0].0 {
path_distance if path_distance > distance => { path_distance if path_distance > distance => {
// shorter path, we replace // shorter path, we replace
...@@ -80,7 +83,7 @@ impl<T: WebOfTrust> PathFinder<T> for RustyPathFinder { ...@@ -80,7 +83,7 @@ impl<T: WebOfTrust> PathFinder<T> for RustyPathFinder {
let mut new_paths = vec![]; let mut new_paths = vec![];
for path in &paths { for path in &paths {
let node = path.last().unwrap(); let node = path.last().expect("path should not be empty");
if node == &to { if node == &to {
// If path is complete, we keep it. // If path is complete, we keep it.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment